Problems about baking composite maps Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
SanSeiU
Gnoblar
Posts: 3
Joined: Thu Mar 11, 2021 6:39 am

Problems about baking composite maps

Post by SanSeiU »

Ogre Version: 1.12.11
Operating System: Windows10
Render System: OpenGL

Hello.
I'm not an English speaker. I may make some mistakes on expressing. Forgive me.

Image
Image

I'm a beginner in Ogre. I followed Tutorial 3 on Official Website and encountered some problems. When I tried to generate a simple terrain, I set lighting information for generating composite maps, according to the tutorial. I expected the renderer using the pre-baked composite map rather than calculating lights when the distance between the terrain and my camera reaches a specific value. And it actually worked, with the terrain far away a complete black. I'm confused with it. Core codes of my program are as follows.

Code: Select all

void BasicTutorial1::setup()
{
    // do not forget to call the base first
    ApplicationContext::setup();
    addInputListener(this);

    // get a pointer to the already created root
    Root* root = getRoot();
    mScnMgr = root->createSceneManager();

    // register our scene with the RTSS
    RTShader::ShaderGenerator* shadergen = RTShader::ShaderGenerator::getSingletonPtr();
    shadergen->addSceneManager(mScnMgr);

    mScnMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 8000, false);
    mScnMgr -> setAmbientLight(ColourValue(0.05, 0, 0.1));

    mCamera = mScnMgr-> createCamera("camera");
    mCamera -> setNearClipDistance(40);
    mCamera -> setFarClipDistance(0);
    mCamera -> setAutoAspectRatio(true);

    SceneNode * camNode = mScnMgr-> createSceneNode();
    camNode -> setPosition(mTerrainPos + Vector3(1683, 50, 2116));
    camNode -> lookAt(Vector3(1963, 50, 1660), Node::TS_PARENT);
    camNode -> attachObject(mCamera);

    Viewport* vp = getRenderWindow()->addViewport(mCamera);
    vp -> setBackgroundColour(ColourValue::White);
    
    Light * light = mScnMgr-> createLight();
    light -> setType(Light::LT_DIRECTIONAL);
    light -> setDiffuseColour(ColourValue::White);
    light -> setSpecularColour(0.4f, 0.4f, 0.4f);

    SceneNode * lightNode = mScnMgr-> getRootSceneNode() -> createChildSceneNode();
    lightNode -> setDirection(Vector3(0.55, -0.6, 0.2).normalisedCopy());
    lightNode -> attachObject(light);

    mTerrainGlobals = new TerrainGlobalOptions();

    mTerrainGroup = new TerrainGroup(mScnMgr, Terrain::ALIGN_X_Z, terrainSize, terrainWorldSize);
    mTerrainGroup->setFilenameConvention(TERRAIN_FILE_PREFIX, TERRAIN_FILE_SUFFIX);
    mTerrainGroup->setOrigin(mTerrainPos);

    configureTerrainDefaults(light);

    for (long x = TERRAIN_PAGE_MIN_X; x <= TERRAIN_PAGE_MAX_X; ++x)
        for (long y = TERRAIN_PAGE_MIN_Y; y <= TERRAIN_PAGE_MAX_Y; ++y)
            defineTerrain(x, y);
    // sync load since we want everything in place when we start
    mTerrainGroup->loadAllTerrains(true);
   

   //blend map
    if (mTerrainsImported)
    {
        TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
        while (ti.hasMoreElements())
        {
            Terrain* t = ti.getNext()->instance;
            initBlendMaps(t);
        }
    }

    mTerrainGroup->freeTemporaryResources();
}
Below is where I set light information

Code: Select all

void BasicTutorial1::configureTerrainDefaults(Light* light)
{
    mTerrainGlobals->setMaxPixelError(8); 
    mTerrainGlobals->setCompositeMapDistance(5000);

    mTerrainGlobals->setLightMapDirection(light->getDerivedDirection());
    mTerrainGlobals->setCompositeMapAmbient(mScnMgr->getAmbientLight());
    mTerrainGlobals->setCompositeMapDiffuse(light->getDiffuseColour());

    Ogre::Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings();
    defaultimp.inputScale = 600;
    defaultimp.minBatchSize = 33;
    defaultimp.maxBatchSize = 65;

    Image combined;
    combined.loadTwoImagesAsRGBA("Ground23_col.jpg", "Ground23_spec.png", "General");
    TextureManager::getSingleton().loadImage("Ground23_diffspec", "General", combined);

    defaultimp.layerList.resize(3);
    defaultimp.layerList[0].worldSize = 200;
    defaultimp.layerList[0].textureNames.push_back("Ground37_diffspec.dds");
    defaultimp.layerList[0].textureNames.push_back("Ground37_normheight.dds");
    defaultimp.layerList[1].worldSize = 200;
    defaultimp.layerList[1].textureNames.push_back("Ground23_diffspec");
    defaultimp.layerList[1].textureNames.push_back("Ground23_normheight.dds");
    defaultimp.layerList[2].worldSize = 400;
    defaultimp.layerList[2].textureNames.push_back("Rock20_diffspec.dds");
    defaultimp.layerList[2].textureNames.push_back("Rock20_normheight.dds");
}

Code: Select all

void BasicTutorial1::defineTerrain(long x, long y)
{
    String filename = mTerrainGroup->generateFilename(x, y);
    if (ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename))
    {
        mTerrainGroup->defineTerrain(x, y);
    }
    else
    {
        Image img;
        getTerrainImage(x % 2 != 0, y % 2 != 0, img);
        mTerrainGroup->defineTerrain(x, y, &img);
        mTerrainsImported = true;
    }
}

void BasicTutorial1::getTerrainImage(bool flipX, bool flipY, Image & img)
{
    img.load("terrain.png", mTerrainGroup->getResourceGroup());
    if (flipX)
        img.flipAroundY();
    if (flipY)
        img.flipAroundX();
}
I should have set everything correctly by the tutorial, but there must be something I ignored. Disabling composite mapping is workable. But I want to figure out my problem.
Thanks!
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Problems about baking composite maps

Post by paroj »

does it work in the SampleBrowser (Terrain Sample) or with a different RenderSystem?
SanSeiU
Gnoblar
Posts: 3
Joined: Thu Mar 11, 2021 6:39 am

Re: Problems about baking composite maps

Post by SanSeiU »

paroj wrote: Thu Mar 11, 2021 1:27 pm does it work in the SampleBrowser (Terrain Sample) or with a different RenderSystem?
Thanks for your advice..
I tried various Render Systems both in the SampleBrowser and my program. And I got basically same results in my program, some black composite maps, except with DX11. My computer may not support DX11 well. When I use DX11, the picture looks quite dark both in the SampleBrowser and my program. And it performs best in the SampleBrower with DX9, no problems found. When I use different versions of OpenGL in SampleBrowser, the composite maps look brighter or a black, as the images show below.
Image
Image
Actually, I'm using a integrated graphics card on my surface pro. It may not support methods provided by Ogre well.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Problems about baking composite maps

Post by paroj »

in the samplebrowser, you have to wait until the "Building Terrain.." message disappears. It means that the Composite map is being updated.
SanSeiU
Gnoblar
Posts: 3
Joined: Thu Mar 11, 2021 6:39 am

Re: Problems about baking composite maps

Post by SanSeiU »

paroj wrote: Fri Mar 12, 2021 3:07 pm in the samplebrowser, you have to wait until the "Building Terrain.." message disappears. It means that the Composite map is being updated.
OK. Exactly! I waited for quite a while and my program worked properly as well. I ignored that the composite map was rendered asynchronously. Thanks for your reply!
Post Reply