Operating System: Windows10
Render System: OpenGL
Hello.
I'm not an English speaker. I may make some mistakes on expressing. Forgive me.


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();
}
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();
}
Thanks!