terrain fog lod

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
zhuyeaini
Gnoblar
Posts: 4
Joined: Wed Dec 19, 2012 11:52 am

terrain fog lod

Post by zhuyeaini »

hi:
in ogre 1.8.1 terrain component,i found a problem,if i use fog in terrain,of course,it's ok ,the terrain behind the fog far distance is become the fog
colour,but the problem appear,
the terrain behind the fog's far distance should not be render,it become the fog colour,so i check the terrain source code and find there has no method
to let terrain become invisible if it behind the fog's far distance.(Or i haven't found?)
so i changed the terrain source code with:
bool TerrainQuadTreeNode::calculateCurrentLod(const Camera* cam, Real cFactor)
{
mSelfOrChildRendered = false;

// early-out
/* disable this, could cause 'jumps' in LOD as children go out of frustum
if (!cam->isVisible(mMovable->getWorldBoundingBox(true)))
{
mCurrentLod = -1;
return mSelfOrChildRendered;
}
*/

// Check children first
int childRenderedCount = 0;
if (!isLeaf())
{
for (int i = 0; i < 4; ++i)
{
if (mChildren->calculateCurrentLod(cam, cFactor))
++childRenderedCount;
}

}

if (childRenderedCount == 0)
{

// no children were within their LOD ranges, so we should consider our own
Vector3 localPos = cam->getDerivedPosition() - mLocalCentre - mTerrain->getPosition();
Real dist;
if (TerrainGlobalOptions::getSingleton().getUseRayBoxDistanceCalculation())
{
// Get distance to this terrain node (to closest point of the box)
// head towards centre of the box (note, box may not cover mLocalCentre because of height)
Vector3 dir(mAABB.getCenter() - localPos);
dir.normalise();
Ray ray(localPos, dir);
std::pair<bool, Real> intersectRes = Math::intersects(ray, mAABB);

// ray will always intersect, we just want the distance
dist = intersectRes.second;
}
else
{
// distance to tile centre
dist = localPos.length();
// deduct half the radius of the box, assume that on average the
// worst case is best approximated by this
dist -= (mBoundingRadius * 0.5f);
}

//some thing like these,we can use fog far distance and add flag in terrain group to check if we should
if(mTerrain->mInvisibleBeyondDis && dist>mTerrain->mBeyondDis)
{
mCurrentLod = -1;
return mSelfOrChildRendered;
}


// Do material LOD
MaterialPtr material = getMaterial();
const LodStrategy *materialStrategy = material->getLodStrategy();
Real lodValue = materialStrategy->getValue(mMovable, cam);
// Get the index at this biased depth
mMaterialLodIndex = material->getLodIndex(lodValue);
..............................
..............................
..............................
}

please give some advance,thanks
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: terrain fog lod

Post by bstone »

That's unnecessary. Set the camera far plane distance to the proper value related to your fog distance and the terrain chunks will get culled out by the camera's frustrum.
zhuyeaini
Gnoblar
Posts: 4
Joined: Wed Dec 19, 2012 11:52 am

Re: terrain fog lod

Post by zhuyeaini »

bstone wrote:That's unnecessary. Set the camera far plane distance to the proper value related to your fog distance and the terrain chunks will get culled out by the camera's frustrum.
yes,that's also ok,but i set camera far distance infinite .....