//----------------------------------------------------------------------- void InstanceBatch::_notifyCurrentCamera( Camera* cam ) { mCurrentCamera = cam; //See DistanceLodStrategy::getValueImpl() //We use our own because our SceneNode is just filled with zeroes, and updating it //with real values is expensive, plus we would need to make sure it doesn't get to //the shader Real depth = Math::Sqrt( getSquaredViewDepth(cam) ) - mMeshReference->getBoundingSphereRadius(); depth = std::max( depth, Real(0) ); Real lodValue = depth * cam->_getLodBiasInverse(); //Now calculate Material LOD /*const LodStrategy *materialStrategy = m_material->getLodStrategy(); //Calculate LOD value for given strategy Real lodValue = materialStrategy->getValue( this, cam );*/ //Get the index at this depth unsigned short idx = mMaterial->getLodIndex( lodValue ); //TODO: Replace subEntity for MovableObject // Construct event object /*EntityMaterialLodChangedEvent subEntEvt; subEntEvt.subEntity = this; subEntEvt.camera = cam; subEntEvt.lodValue = lodValue; subEntEvt.previousLodIndex = m_materialLodIndex; subEntEvt.newLodIndex = idx; //Notify LOD event listeners cam->getSceneManager()->_notifyEntityMaterialLodChanged(subEntEvt);*/ //Change LOD index mMaterialLodIndex = idx; MovableObject::_notifyCurrentCamera( cam ); }
//----------------------------------------------------------------------- void InstanceBatch::_notifyCurrentCamera( Camera* cam ) { mCurrentCamera = cam; //See DistanceLodStrategy::getValueImpl() //We use our own because our SceneNode is just filled with zeroes, and updating it //with real values is expensive, plus we would need to make sure it doesn't get to //the shader Real depth = Math::Sqrt(getSquaredViewDepth(cam)) - getBoundingRadius(); depth = std::max( depth, Real(0) ); Real lodValue = depth * cam->_getLodBiasInverse(); //Now calculate Material LOD /*const LodStrategy *materialStrategy = m_material->getLodStrategy(); //Calculate LOD value for given strategy Real lodValue = materialStrategy->getValue( this, cam );*/ //Get the index at this depth unsigned short idx = mMaterial->getLodIndex( lodValue ); //TODO: Replace subEntity for MovableObject // Construct event object /*EntityMaterialLodChangedEvent subEntEvt; subEntEvt.subEntity = this; subEntEvt.camera = cam; subEntEvt.lodValue = lodValue; subEntEvt.previousLodIndex = m_materialLodIndex; subEntEvt.newLodIndex = idx; //Notify LOD event listeners cam->getSceneManager()->_notifyEntityMaterialLodChanged(subEntEvt);*/ // Change LOD index mMaterialLodIndex = idx; mBeyondFarDistance = false; if (cam->getUseRenderingDistance() && mUpperDistance > 0) { if (depth > mUpperDistance) mBeyondFarDistance = true; } if (!mBeyondFarDistance && cam->getUseMinPixelSize() && mMinPixelSize > 0) { Real pixelRatio = cam->getPixelDisplayRatio(); Ogre::Vector3 objBound = getBoundingBox().getSize() * getParentNode()->_getDerivedScale(); objBound.x = Math::Sqr(objBound.x); objBound.y = Math::Sqr(objBound.y); objBound.z = Math::Sqr(objBound.z); float sqrObjMedianSize = std::max( std::max(std::min(objBound.x, objBound.y), std::min(objBound.x, objBound.z)), std::min(objBound.y, objBound.z)); // If we have a perspective camera calculations are done relative to distance Real sqrDistance = 1; if (cam->getProjectionType() == PT_PERSPECTIVE) sqrDistance = getSquaredViewDepth(cam->getLodCamera()); // it's ok mBeyondFarDistance = sqrObjMedianSize < sqrDistance * Math::Sqr(pixelRatio * mMinPixelSize); } if (mParentNode) { MovableObjectLodChangedEvent evt; evt.movableObject = this; evt.camera = cam; cam->getSceneManager()->_notifyMovableObjectLodChanged(evt); } mRenderingDisabled = mListener && !mListener->objectRendering(this, cam); // MovableObject::_notifyCurrentCamera( cam ); // it does not suit }