📄 ogrepaginglandscaperenderable.cpp
字号:
Real a1;
if (RGBA_precalc.a < 1.0f)
{
a1 = RGBA_precalc.g / ( 1 - RGBA_precalc.a );
}
else
a1 = 0.0f;
Real a2 = 1.0f - a1;
RGBA_precalc.r = a1;
RGBA_precalc.g = a1;
RGBA_precalc.b = a1;
RGBA_precalc.a = a2;
}
else if (b_base)
{
RGBA_precalc = PagingLandScapeData2DManager::getSingleton().getBaseAt( mInfo->pageX, mInfo->pageZ, i, k );
RGBA_precalc.a = 1.0f;
}
else if (b_instant_colored)
{
const ColourValue Sand (1.0f, 1.0f, 0.0f);
const ColourValue Grass (0.13f,0.545f,0.13f);
//const ColourValue Rock (0.7450f, 0.745f, 0.745f);
const ColourValue Rock (0.411764f, 0.411764f, 0.411764f);
const ColourValue Snow (1.0f, 0.98f, 0.98f);
if ( height < matHeight[0] )
{
// sand - grass interpolation
Real interpol = height / matHeight[0];
RGBA_precalc = Sand * (1.0f - interpol) + Grass * interpol;
}
else if ( height < matHeight[1] )// && Height >=matHeight[0]
{
// grass - rock interpolation
Real interpol = (height - matHeight[0])/ (matHeight[1] - matHeight[0]);
RGBA_precalc = Grass * (1.0f - interpol) + Rock * interpol;
}
else //Height >=matHeight[1]
{
// rock - snow interpolation
Real interpol = (height - matHeight[1])/ (absmaxHeight - matHeight[1]);
RGBA_precalc = Rock * (1.0f - interpol) + Snow * interpol;
}
if (!b_lit)
norm = PagingLandScapeData2DManager::getSingleton().getNormalAt( mInfo->pageX,
mInfo->pageZ, i, k );
Real Slope = std::max (Math::Abs (norm.x),
Math::Abs (norm.z)) / 2.0f;
// color - rock interpolation
RGBA_precalc = RGBA_precalc * (1.0f - Slope) + Rock * Slope;
if (b_shadowed)
{
const ColourValue lightDiffuse (1.0f, 1.0f, 0.0f);
Real fIntensity = 1.0f; // full light
if(fLightAngle < pfHorizon[i + K_heightDataPos])
{
// if Vertex has some shadows
fIntensity = 1.0f - (-5.0f * (fLightAngle - pfHorizon[i + K_heightDataPos]));
}
if (fIntensity >= 0.0f)
{
// if Vertex is at least partially lighted
fIntensity = LightDir.dotProduct (norm);
}
else
{
// if Vertex is fully shadowed
fIntensity = 0.0f;
}
RGBA_precalc += fIntensity * lightDiffuse;
}
RGBA_precalc.a = 1.0f;
}
RGBA *pColor;
colorelem->baseVertexPointerToElement(pSecond, &pColor);
Root::getSingleton().convertColourValue (RGBA_precalc,
pColor);
}
pMain += vVertices->getVertexSize();
pSecond += vColors->getVertexSize();
K_Tex1DataPos += Aux1;
}
K_Tex2DataPos += Aux1;
K_heightDataPos += pageSize;
}
// Unlock the buffers
vVertices->unlock();
vColors->unlock();
// Calculate the bounding box for this renderable
mBox.setExtents( (Real) ( offSetX * scale_x ),
min,
(Real) ( offSetZ * scale_z ),
(Real) ( endx * scale_x ),
max,
(Real) ( endx * scale_z ));
mWorldBoundingSphere.setCenter( mBox.getCenter() );
mWorldBoundingSphere.setRadius( mBox.getMaximum().length() );
mIsLoaded = true;
mNeedReload = false;
}
//-----------------------------------------------------------------------
void PagingLandScapeRenderable::release()
{
if (mInUse && mIsLoaded)
{
if (mNeighbors[SOUTH])
mNeighbors[SOUTH]->_setNeighbor (NORTH, 0);
if (mNeighbors[NORTH])
mNeighbors[NORTH]->_setNeighbor (SOUTH, 0);
if (mNeighbors[EAST])
mNeighbors[EAST]->_setNeighbor (WEST, 0);
if (mNeighbors[WEST])
mNeighbors[WEST]->_setNeighbor (EAST, 0);
for (uint i = 0; i < 4; i++ )
{
mNeighbors[i] = 0;
}
PagingLandScapeRenderableManager::getSingleton().freeRenderable( this );
mInUse = false;
mIsLoaded = false;
mInfo = 0;
}
}
//-----------------------------------------------------------------------
void PagingLandScapeRenderable::_notifyCurrentCamera( Camera* cam )
{
if ( mInUse == false || mIsLoaded == false)
return;
if (static_cast<PagingLandscapeCamera*> (cam)->getVisibility (static_cast<SceneNode*> (mParentNode)->_getWorldAABB ()))
{
mInFrustum = true;
setVisible (true);
}
else
{
mInFrustum = false;
setVisible (false);
return;
}
/* set*/
#if defined(_VisibilityCheck)
//Check if the renderable need to be rendered based on the Cone normal approach
//TODO: use the cone aperture not a fixed value
if ( PagingLandScapeOptions::getSingleton().lit == true )
{
mMustRender = (bool)( cam->getDirection().dotProduct( mConeNormal ) < PagingLandScapeOptions::getSingleton().visibilityAngle );
}
#endif
Real d = (mParentNode->_getDerivedPosition() - cam->getDerivedPosition()).squaredLength();
// Now adjust it by the camera bias
d = d * cam->getLodBias ();
// Material LOD
if ( m_pMaterial->getNumLodLevels() > 1 )
mMaterialLODIndex = m_pMaterial->getLodIndexSquaredDepth(d);
// Check if we need to decrease the LOD
Real factor = PagingLandScapeOptions::getSingleton().LOD_factor;
Real curr_lod = factor * (1 + mRenderLevel);
bool changeLOD = false;
if (d < curr_lod)
{
if (mRenderLevel)
{
mRenderLevel--;
curr_lod -= factor;
changeLOD = true;
}
}
else if (mRenderLevel < PagingLandScapeOptions::getSingleton().maxRenderLevel &&
d >= (curr_lod * 2))
{
curr_lod += factor;
mRenderLevel++;
changeLOD = true;
}
if (changeLOD || mRenderOp.indexData == 0)
{
update ();
for (uint i = 0; i < 4; i++)
{
if (mNeighbors[i] && mNeighbors[i]->isLoaded ())
mNeighbors[i] -> update ();
}
}
if (mNeedReload)
load ();
}
//-----------------------------------------------------------------------
void PagingLandScapeRenderable::update()
{
mRenderOp.indexData = getIndexData();
}
//-----------------------------------------------------------------------
IndexData* PagingLandScapeRenderable::getIndexData(void)
{
uint stitchFlags = 0;
if ( mNeighbors[ EAST ] && mNeighbors[ EAST ]->isLoaded () &&
mNeighbors[ EAST ] -> mRenderLevel > mRenderLevel)
{
stitchFlags |= STITCH_EAST;
stitchFlags |=
(mNeighbors[ EAST ] -> mRenderLevel - mRenderLevel) << STITCH_EAST_SHIFT;
}
if ( mNeighbors[ WEST ] && mNeighbors[ WEST ]->isLoaded () &&
mNeighbors[ WEST ] -> mRenderLevel > mRenderLevel)
{
stitchFlags |= STITCH_WEST;
stitchFlags |=
(mNeighbors[ WEST ] -> mRenderLevel - mRenderLevel) << STITCH_WEST_SHIFT;
}
if ( mNeighbors[ NORTH ] && mNeighbors[ NORTH ]->isLoaded () &&
mNeighbors[ NORTH ] -> mRenderLevel > mRenderLevel )
{
stitchFlags |= STITCH_NORTH;
stitchFlags |=
(mNeighbors[ NORTH ] -> mRenderLevel - mRenderLevel) << STITCH_NORTH_SHIFT;
}
if ( mNeighbors[ SOUTH ] && mNeighbors[ SOUTH ]->isLoaded () &&
mNeighbors[ SOUTH ] -> mRenderLevel > mRenderLevel )
{
stitchFlags |= STITCH_SOUTH;
stitchFlags |=
(mNeighbors[ SOUTH ] -> mRenderLevel - mRenderLevel) << STITCH_SOUTH_SHIFT;
}
return PagingLandScapeIndexBuffer::getSingleton().getIndexData( stitchFlags,
mRenderLevel ,
mNeighbors);
}
//-----------------------------------------------------------------------
void PagingLandScapeRenderable::_updateRenderQueue( RenderQueue* queue )
{
#if defined(_VisibilityCheck)
if ( mMustRender == false )
{
return;
}
#endif
if ( mInUse && mIsLoaded && mInFrustum)
{
PagingLandScapeRenderableManager::getSingleton().addVisible ();
queue -> addRenderable( this );
}
}
//-----------------------------------------------------------------------
Technique* PagingLandScapeRenderable::getTechnique(void) const
{
return m_pMaterial->getBestTechnique(mMaterialLODIndex);
}
//-----------------------------------------------------------------------
Real PagingLandScapeRenderable::getSquaredViewDepth(const Camera* cam) const
{
// Use squared length to avoid square root
return (mParentNode->_getDerivedPosition() - cam->getDerivedPosition()).squaredLength();
}
//-----------------------------------------------------------------------
Real PagingLandScapeRenderable::getBoundingRadius(void) const
{
return mWorldBoundingSphere.getRadius();
}
} //namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -