ogre 2.1 terrain question

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
User avatar
nevarim
Gnoll
Posts: 675
Joined: Mon Jul 05, 2010 6:16 pm
Location: Pavia Italy
x 4
Contact:

ogre 2.1 terrain question

Post by nevarim »

hi all
i saw that in sample2 there is no samples about terrain usage

there is somthing new about this part of ogre? (ogreterrain)

thanks
Neva
i'm a noob until proven otherwise :D
used in my project ;) and thanks to everyone :D
Ogre 3d
Mygui
Skyx
Hydrax
MOC
CCS
User avatar
Thyrion
Goblin
Posts: 224
Joined: Wed Jul 31, 2013 1:58 pm
Location: germany
x 8

Re: ogre 2.1 terrain question

Post by Thyrion »

http://www.ogre3d.org/forums/viewtopic.php?f=25&t=88798
The Terra system is WIP and still not merged into 2.1 "main"
Arkiruthis
Gremlin
Posts: 178
Joined: Fri Dec 24, 2010 7:55 pm
x 10

Re: ogre 2.1 terrain question

Post by Arkiruthis »

On my setup the terrain sample is purple and shiny. Is that just a WIP thing?

dark_sylinc posted a screenshot in the thread Thyrion linked and it looked similar there too. But the other screenshots in that thread look correct with, well... green?

http://i.imgur.com/swSzem7.jpg

Quite keen to play around with it but just wondered if that was an issue with my graphics card not supporting something? I'm not even sure if I'm using Forward3D or not, I haven't changed anything in the sample code.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: ogre 2.1 terrain question

Post by dark_sylinc »

Arkiruthis wrote:On my setup the terrain sample is purple and shiny.
That's because of extremely poor choice of material parameters (metalness, roughness & the textures). The purplenish was a test texture to check the diffuse was working and it was just never replaced (replacing textures is tricky because it has to look good and have a small impact on the repository size)
Is that just a WIP thing?
It's one of the most recent additions and thus the least tested ones. Particularly someone reported a few potential bugs with metalness and textures, but shouldn't be too hard to fix. I just haven't found the time yet.
Arkiruthis
Gremlin
Posts: 178
Joined: Fri Dec 24, 2010 7:55 pm
x 10

Re: ogre 2.1 terrain question

Post by Arkiruthis »

Ah okay, no worries! Thanks Matias. :D
User avatar
nevarim
Gnoll
Posts: 675
Joined: Mon Jul 05, 2010 6:16 pm
Location: Pavia Italy
x 4
Contact:

Re: ogre 2.1 terrain question

Post by nevarim »

in 2.1 there isn't this terrain sample right?
i'm a noob until proven otherwise :D
used in my project ;) and thanks to everyone :D
Ogre 3d
Mygui
Skyx
Hydrax
MOC
CCS
Arkiruthis
Gremlin
Posts: 178
Joined: Fri Dec 24, 2010 7:55 pm
x 10

Re: ogre 2.1 terrain question

Post by Arkiruthis »

nevarim wrote:in 2.1 there isn't this terrain sample right?
What platform are you compiling on?

On Windows, inside the Visual Studio solution (OGRE.SLN) there should be a sub-project called "Sample_Tutorial_Terrain".

Did you select "CMAKE_BUILD_SAMPLES2" in the CMake setup? (it's off by default)
User avatar
Thyrion
Goblin
Posts: 224
Joined: Wed Jul 31, 2013 1:58 pm
Location: germany
x 8

Re: ogre 2.1 terrain question

Post by Thyrion »

nevarim wrote:in 2.1 there isn't this terrain sample right?
You know what a branch is?
Branches:
- v2-1 -> ogre 2.1 main branch -> no terrain sample
- v2-1-pso -> ogre 2.1 development branch -> has the terrain sample
- v2-1-metal -> another development branch

"v2-1-pso" and "v2-1-metal" will be merged into v2-1 if finished/stable.

You can test the others if you don't want to wait.
Arkiruthis
Gremlin
Posts: 178
Joined: Fri Dec 24, 2010 7:55 pm
x 10

Re: ogre 2.1 terrain question

Post by Arkiruthis »

Ah yep, I'm on the v2-1-PSO branch, I should've mentioned that.
User avatar
nevarim
Gnoll
Posts: 675
Joined: Mon Jul 05, 2010 6:16 pm
Location: Pavia Italy
x 4
Contact:

Re: ogre 2.1 terrain question

Post by nevarim »

great this is working, but there isn't more the sample for to modify terrain?
i'm a noob until proven otherwise :D
used in my project ;) and thanks to everyone :D
Ogre 3d
Mygui
Skyx
Hydrax
MOC
CCS
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: ogre 2.1 terrain question

Post by xrgo »

Hello! I am trying to integrate Terra in my engine, but I am getting a crash in update... this is what I am doing:

Code: Select all

void yTerraManager::init(){

    Ogre::Root* root = Ogre::Root::getSingletonPtr();
    Ogre::HlmsManager *hlmsManager = root->getHlmsManager();    
    Ogre::SceneManager* sceneManager = yGraphicsServices::getGraphicsSceneNodeManager().getMainSceneManager();
    Ogre::Camera* camera = yGraphicsServices::getGraphicsCameraManager().getMainCamera();
    Ogre::RenderWindow *renderWindow = yGraphicsServices::getGraphicsRender().getRenderWindow();
    Ogre::CompositorManager2 *compositorManager = root->getCompositorManager2();

    Ogre::ArchiveVec library;
    std::string renderSystemAppend = "GLSL";

    Ogre::String buffer;
    if( yUtils::getConfigFileSetting("RenderSystem", buffer) && buffer == "D3D" ) {
        renderSystemAppend = "HLSL";
    }
    Ogre::Archive *archiveTerra = Ogre::ArchiveManager::getSingletonPtr()->load( "../../yoyEngine/media/Hlms/Terra/"+renderSystemAppend, "FileSystem", true );

    Ogre::Archive *archiveLibraryCommon = Ogre::ArchiveManager::getSingletonPtr()->load("../../yoyEngine/media/Hlms/Common/"+renderSystemAppend, "FileSystem", true );
    Ogre::Archive *archiveLibraryCommonAny = Ogre::ArchiveManager::getSingletonPtr()->load("../../yoyEngine/media/Hlms/Common/Any", "FileSystem", true );
    Ogre::Archive *archivePbsLibrary = Ogre::ArchiveManager::getSingletonPtr()->load("../../yoyEngine/media/Hlms/Pbs/"+renderSystemAppend, "FileSystem", true );
    Ogre::Archive *archivePbsLibraryAny = Ogre::ArchiveManager::getSingletonPtr()->load("../../yoyEngine/media/Hlms/Pbs/Any", "FileSystem", true );
    library.push_back( archiveLibraryCommon );
    library.push_back( archiveLibraryCommonAny );
    library.push_back( archivePbsLibrary );
    library.push_back( archivePbsLibraryAny );


    Ogre::HlmsTerra *hlmsTerra = OGRE_NEW Ogre::HlmsTerra( archiveTerra, &library );
    hlmsManager->registerHlms( hlmsTerra );

#ifdef DEVELOPER
    QDir().mkdir("./hlmsShaders/terra/");
    hlmsTerra->setDebugOutputPath(true,"./hlmsShaders/terra/");
#else
    hlmsTerra->setDebugOutputPath(false);
#endif


    mTerra = new Ogre::Terra( Ogre::Id::generateNewId<Ogre::MovableObject>(),
                              &sceneManager->_getEntityMemoryManager( Ogre::SCENE_STATIC ),
                              sceneManager, 0, root->getCompositorManager2(),
                              camera );
    mTerra->setCastShadows( false );

    //mTerra->load( "Heightmap.png", Ogre::Vector3::ZERO, Ogre::Vector3( 256.0f, 1.0f, 256.0f ) );
    mTerra->load( "Heightmap.png", Ogre::Vector3( 64.0f, 4096.0f * 0.5f, 64.0f ), Ogre::Vector3( 4096.0f, 4096.0f, 4096.0f ) );

    Ogre::SceneNode *rootNode = sceneManager->getRootSceneNode( Ogre::SCENE_STATIC );
    Ogre::SceneNode *sceneNode = rootNode->createChildSceneNode( Ogre::SCENE_STATIC );
    sceneNode->attachObject( mTerra );


    Ogre::HlmsDatablock *datablock = hlmsTerra->getDatablock( "TerraExampleMaterial" );
    //Ogre::HlmsDatablock* datablock = hlmsTerra->createDatablock("test","test",Ogre::HlmsMacroblock(),Ogre::HlmsBlendblock(),Ogre::HlmsParamVec());

    mTerra->setDatablock( datablock );


    //dont care about shadow right now

//    //enable the shader pieces for pbs
//    Ogre::Hlms *hlmsPbs = hlmsManager->getHlms( Ogre::HLMS_PBS );
//    Ogre::Archive *archivePbs = hlmsPbs->getDataFolder();
//    Ogre::ArchiveVec libraryPbs = hlmsPbs->getPiecesLibraryAsArchiveVec();
//    libraryPbs.push_back( Ogre::ArchiveManager::getSingletonPtr()->load(
//                              "../../yoyEngine/media/Hlms/Terra/" + renderSystemAppend + "/PbsTerraShadows",
//                              "FileSystem", true ) );
//    hlmsPbs->reloadFrom( archivePbs, &libraryPbs );
//    {
//        Ogre::HlmsPbsTerraShadows* mHlmsPbsTerraShadows = new Ogre::HlmsPbsTerraShadows();
//        mHlmsPbsTerraShadows->setTerra( mTerra );
//        //Set the PBS listener so regular objects also receive terrain shadows
//        Ogre::Hlms *hlmsPbs = root->getHlmsManager()->getHlms( Ogre::HLMS_PBS );
//        hlmsPbs->setListener( mHlmsPbsTerraShadows );
//    }


    Ogre::CompositorWorkspace *oldWorkspace = yGraphicsServices::getGraphicsWorkspaceManager().getMainWorkspace();
    if( oldWorkspace )
    {
        Ogre::TexturePtr terraShadowTex = oldWorkspace->getExternalRenderTargets()[1].textures.back();
        if( terraShadowTex->getFormat() == Ogre::PF_NULL )
        {
            Ogre::ResourcePtr resourcePtr( terraShadowTex );
            Ogre::TextureManager::getSingleton().remove( resourcePtr );
        }
        compositorManager->removeWorkspace( oldWorkspace );
    }

    Ogre::CompositorChannelVec externalChannels( 2 );
    //Render window
    externalChannels[0].target = renderWindow;

    //Terra's Shadow texture
    Ogre::ResourceLayoutMap initialLayouts;
    Ogre::ResourceAccessMap initialUavAccess;

    const Ogre::ShadowMapper *shadowMapper = mTerra->getShadowMapper();
    shadowMapper->fillUavDataForCompositorChannel( externalChannels[1], initialLayouts,
                                                   initialUavAccess );

    compositorManager->addWorkspace( sceneManager, externalChannels, camera,
                                        "Tutorial_TerrainWorkspace", true, -1,
                                        (Ogre::UavBufferPackedVec*)0, &initialLayouts,
                                        &initialUavAccess );

    root->addFrameListener(this);

}

bool yTerraManager::frameRenderingQueued(const Ogre::FrameEvent &evt){ //I tried frameStarted too, and in an update() just before renderOneFrame()

    const float lightEpsilon = 0.0f;
    mTerra->update( Ogre::Vector3::NEGATIVE_UNIT_Y, lightEpsilon );

    return true;
}

this is the callstack (for some reason I can't examine the actual line inside addRenderable... although ogre is in Debug mode):
1 Ogre::RenderQueue::addRenderable BaseProjectDevSim 0x7ff6ef43e2d5
2 Ogre::RenderQueue::addRenderableV2 BaseProjectDevSim 0x7ff6ef433e81
3 Ogre::SceneManager::cullFrustum BaseProjectDevSim 0x7ff6ef05b7a5
4 Ogre::SceneManager::_updateWorkerThread BaseProjectDevSim 0x7ff6ef06f414
5 Ogre::updateWorkerThread BaseProjectDevSim 0x7ff6ef06f90c
6 Ogre::updateWorkerThread_internal BaseProjectDevSim 0x7ff6ef06f963
7 BaseThreadInitThunk KERNEL32 0x7ff9e4a02774
8 RtlUserThreadStart ntdll 0x7ff9e52c0d51
if I comment out this in Terra::optimizeCellsAndAdd:

Code: Select all

        while( itor != end )
            mRenderables.push_back( *itor++ );
it doesn't crash but obviously i don't see the terrain

if I set rootNode->setVisible(false); it also don't crash but again... no visible :P

if I create an empty datablock:
//Ogre::HlmsDatablock *datablock = hlmsTerra->getDatablock( "TerraExampleMaterial" );
Ogre::HlmsDatablock* datablock = hlmsTerra->createDatablock("test","test",Ogre::HlmsMacroblock(),Ogre::HlmsBlendblock(),Ogre::HlmsParamVec());
I get a different crash:
"Parameter called texShadowMap0 does not exist. Known names are: f3dGrid f3dGrid[0] f3dLightList f3dLightList[0] terrainNormals terrainNormals[0] terrainShadows terrainShadows[0] texCloudsShadows texCloudsShadows[0] " @0x61bc6fd418
which makes me think that some media/hlms paths are wrong but I double check them and I think I haven't missed anything.. the other resources needed (materials, textures, etc. are added when I init Ogre)

please help!
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: ogre 2.1 terrain question

Post by xrgo »

xrgo wrote:Hello! I am trying to integrate Terra in my engine, but I am getting a crash in update...
FIXED!! the problem was that it was conflicting with my custom pieces for pbs lol.. and it needed a directional light beforehand
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: ogre 2.1 terrain question

Post by xrgo »

I have another problem:

when I use a dimension different than Ogre::Vector3( 4096.0f, 4096.0f, 4096.0f ) I get weird normals, I (kind of) solved this by looking at the value that this working dimension uses for the vScale parameter.. and it gave me Vector3(0.000244141, 1, 0.000244141)... so if I force that value always for vScale it works fine with every dimension (that I tested). my guess is that this value is a normalized one with a 1 in Y, maybe can be hardcoded and that can optimize a bit the shaders? EDIT: well if I set a dimension Y of 0, it should be just a plane, but it also shows normals so obviously forcing the value is not correct, I don't know the solution of this yet

also terrain shadows are not working but I just started looking at this one =) EDIT: working now, i was just setting light direction wrong lol

EDIT2: shadows looks reeeeeeeally pixelated in the standard pbs objects when dimension is not 4096 =(
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: ogre 2.1 terrain question

Post by dark_sylinc »

What dimensions are you using? I can't remember now if there were restrictions (e.g. multiple of 2, power of 2, etc)
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: ogre 2.1 terrain question

Post by xrgo »

I tried with many numbers, multiple of 2 and power of 2 also... its really easy to see the problem when using a reflection texture, or just by doing

Code: Select all

	outColour.xyz = texture( terrainNormals, inPs.uv0.xy ).xyz
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: ogre 2.1 terrain question

Post by dark_sylinc »

Please post some screenshots (restoring vScale to what the original code) and some code (all the parameters used).
Beware that when resolution changes, normals get less sharper.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: ogre 2.1 terrain question

Post by xrgo »

this is from the samples, I just changed this:

Code: Select all

        Ogre::HlmsManager *hlmsManager = root->getHlmsManager();
        //Ogre::HlmsDatablock *datablock = hlmsManager->getDatablock( "TerraExampleMaterial" );
        Ogre::HlmsDatablock *datablock = hlmsManager->getHlms( Ogre::HLMS_USER3 )->getDefaultDatablock();
//        Ogre::HlmsMacroblock macroblock;
//        macroblock.mPolygonMode = Ogre::PM_WIREFRAME;
        //datablock->setMacroblock( macroblock );


		Ogre::TexturePtr cubemap = Ogre::TextureManager::getSingletonPtr()->getByName("citadela_hor.dds");
		if (cubemap.isNull()) {
			cubemap = Ogre::TextureManager::getSingleton().load("citadela_hor.dds", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_CUBE_MAP, Ogre::MIP_DEFAULT, 1, false, Ogre::PF_UNKNOWN, true);
		}
		static_cast<Ogre::HlmsTerraDatablock*>(datablock)->setTexture(Ogre::TERRA_REFLECTION, 0, cubemap);
basically just using the default datablock and added a reflection cubemap

using 4096:

Code: Select all

        mTerra->load( "Heightmap.png", Ogre::Vector3( 64.0f, 4096.0f * 0.5f, 64.0f ), Ogre::Vector3(4096.0f, 4096.0f, 4096.0f) );
Image

using 128:

Code: Select all

        mTerra->load( "Heightmap.png", Ogre::Vector3( 64.0f, 128.0f * 0.5f, 64.0f ), Ogre::Vector3(128.0f, 128.0f, 128.0f) );
Image

looks like it just has more roughness, but if I look up it looks like this:
Image
so you can see its still very glossy =)

now with

Code: Select all

outColour.xyz = texture( terrainNormals, inPs.uv0.xy ).xyz
using 4096:
Image
using 128:
Image

the effect is proportionally affected with the dimension, in other word for values farther away from 4096 the normals are worst
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: ogre 2.1 terrain question

Post by dark_sylinc »

I totally misunderstood what you were doing (there is no restriction on dimensions being power of 2 or multiple of 2; I thought you were talking about the heightmap's resolution).

This is clearly a very stupid bug. m_xzRelativeSize is set right after calling createHeightmap, instead of being set before.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: ogre 2.1 terrain question

Post by dark_sylinc »

Pushed a fix.

Let me know if this fixes your issues!
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: ogre 2.1 terrain question

Post by xrgo »

yes at first glance its working! thank you so much!!
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: ogre 2.1 terrain question

Post by xrgo »

me haz another question..
My engine has the ability to take 8k screenshots, and I would like to disable LOD for the terrain at that moment because it looks very bad.
Also I can capture 360 video but the terrain is only displayed in one view of the cubemap... fo the rest is invisible :P

The question is... Since I don't care much for performance while doing those things... How can I disable all those optimizations? LOD and cell hiding

EDIT: increasing basePixelDimension and vertPixelDimension in update seems to solve the LOD problem, I can make a setter that does it temporarily =)
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: ogre 2.1 terrain question

Post by 123iamking »

I want to add physic to terrain, but I don't know how.
Here is my attempt: I checked out the array m_terrainCells, I think it may hold the information that form the terrain, but when I take a look at each terrain cell, I don't know how to form the triangle to fit a terrain cell (I think use btBvhTriangleMeshShape may be appropriated for terrain). I also took a look at btOgre2.1, but can't find a way to use it to add physic to terrain.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: ogre 2.1 terrain question

Post by xrgo »

Hello, A few thoughts on Terra:
in the pixel shader shouldn't be the default value when no detail rough or metal be 1 instead of 0...

Code: Select all

	@property( roughness_map@n )
		float roughness@n = texture( textureMaps[@value( roughness_map@n_idx )],
									vec3( inPs.uv0.xy * material.detailOffsetScale[@value(currOffsetDetail)].zw +
											material.detailOffsetScale[@value(currOffsetDetail)].xy,
											@value( roughness_map@n_idx_slice ) ) ).x;
	@end @property( !roughness_map@n )
		float roughness@n = 0; //<<<<<<<<<<should be 1
	@end
so later when multiplied by the material value...

Code: Select all

	ROUGHNESS =			(roughness0 * detailWeights.x * material.roughness.x +
						 roughness1 * detailWeights.y * material.roughness.y) +
						(roughness2 * detailWeights.z * material.roughness.z +
						 roughness3 * detailWeights.w * material.roughness.w);
its not always 0.

aaaand, the mixing of the details I think it should be something like this:

Code: Select all

			diffuseCol.xyz = mix( detailCol0,  detailCol1, sqrt(detailWeights.x) );
			diffuseCol.xyz = mix( diffuseCol.xyz,  detailCol2, sqrt(detailWeights.y) );
			diffuseCol.xyz = mix( diffuseCol.xyz,  detailCol3, sqrt(detailWeights.z) );
(the sqrt is just because of the gamma)
this makes more sense, so in the detailWeights texture when I see Red I can actually see the first detail, and when Blue I can see the second... and so on

Saludos!
Post Reply