在渲染一個具體的物體之前,Ogre會查找與該物體相關的光源,根據光源的范圍,內角和外角(如果是聚光燈)等引數進行計算,如果物體受到光源的影響,則將此光源的引數傳入著色器進行光照計算,如果沒有找到一個光源,那么傳入一個空白的光源引數給著色器,
查找物體相關的光源代碼如下:
bool Light::isInLightRange(const Ogre::Sphere& container) const
{
bool isIntersect = true;
//directional light always intersects (check only spotlight and point)
if (mLightType != LT_DIRECTIONAL)
{
//Check that the sphere is within the sphere of the light
isIntersect = container.intersects(Sphere(mDerivedPosition, mRange));
//If this is a spotlight, check that the sphere is within the cone of the spot light
if ((isIntersect) && (mLightType == LT_SPOTLIGHT))
{
//check first check of the sphere surrounds the position of the light
//(this covers the case where the center of the sphere is behind the position of the light
// something which is not covered in the next test).
isIntersect = container.intersects(mDerivedPosition);
//if not test cones
if (!isIntersect)
{
//Calculate the cone that exists between the sphere and the center position of the light
Ogre::Vector3 lightSphereConeDirection = container.getCenter() - mDerivedPosition;
Ogre::Radian halfLightSphereConeAngle = Math::ASin(container.getRadius() / lightSphereConeDirection.length());
//Check that the light cone and the light-position-to-sphere cone intersect)
Radian angleBetweenConeDirections = lightSphereConeDirection.angleBetween(mDerivedDirection);
isIntersect = angleBetweenConeDirections <= halfLightSphereConeAngle + mSpotOuter * 0.5;
}
}
}
return isIntersect;
}
空白光源的定義如下:
Light mBlankLight;
Light::Light()
: mLightType(LT_POINT),
mPosition(Vector3::ZERO),
mDiffuse(ColourValue::White),
mSpecular(ColourValue::Black),
mDirection(Vector3::UNIT_Z),
mSpotOuter(Degree(40.0f)),
mSpotInner(Degree(30.0f)),
mSpotFalloff(1.0f),
mSpotNearClip(0.0f),
mRange(100000),
mAttenuationConst(1.0f),
mAttenuationLinear(0.0f),
mAttenuationQuad(0.0f),
mPowerScale(1.0f),
mIndexInFrame(0),
mOwnShadowFarDist(false),
mShadowFarDist(0),
mShadowFarDistSquared(0),
mShadowNearClipDist(-1),
mShadowFarClipDist(-1),
mDerivedPosition(Vector3::ZERO),
mDerivedDirection(Vector3::UNIT_Z),
mDerivedCamRelativePosition(Vector3::ZERO),
mDerivedCamRelativeDirty(false),
mCameraToBeRelativeTo(0),
mDerivedTransformDirty(false),
mCustomShadowCameraSetup()
{
//mMinPixelSize should always be zero for lights otherwise lights will disapear
mMinPixelSize = 0;
}
mBlankLight.setDiffuseColour(ColourValue::Black);
mBlankLight.setSpecularColour(ColourValue::Black);
mBlankLight.setAttenuation(0,1,0,0);
以下因為光源引數設定不當,導致使用了空板光源引數,而產生錯誤的渲染效果

注意:其他引數不正確是因為hsls中沒有使用這些變數,所以ogre沒有傳入這些引數的值,導致這些對應的變數沒有得到初始化!
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/336597.html
標籤:其他
上一篇:物件拷貝、屬性復制(型別轉換)
