Ogre 的基于Texture的阴影有时会不正常的原因

138 篇文章 0 订阅

Ogre 的基于Texture的阴影有时会不正常(相对不正常,只是因为使用不得当)

因为默认情况下mShadowCasterRenderBackFaces为true,即渲染背面,从官方解释可看出,这么做是为了优化在渲染阴影时的效率,它是可选的。当使用基于Texture的阴影且mShadowCasterRenderBackFaces为true时就会利用背面去渲染阴影深度图。(这样做的目的应该是模型在制作时有一个背面的较为简单的网格,它专门为阴影渲染优化而做的,从而达到优化的目的)

 

官方解释:

virtual void Ogre::SceneManager::setShadowCasterRenderBackFaces ( bool  bf ) [virtual]

Sets whether or not shadow casters should be rendered into shadow textures using their back faces rather than their front faces.

Remarks:
Rendering back faces rather than front faces into a shadow texture can help minimise depth comparison issues, if you're using depth shadowmapping. You will probably still need some biasing but you won't need as much. For solid objects the result is the same anyway, if you have objects with holes you may want to turn this option off. The default is to enable this option.

Definition at line 2929 of file OgreSceneManager.h.


 

默认情况下mShadowCasterRenderBackFaces为true


SceneManager::SceneManager(const String& name) :
mName(name),
mRenderQueue(0),
mLastRenderQueueInvocationCustom(false),
mCurrentViewport(0),
mSceneRoot(0),
mSkyPlaneEntity(0),
mSkyBoxObj(0),
mSkyPlaneNode(0),
mSkyDomeNode(0),
mSkyBoxNode(0),
mSkyPlaneEnabled(false),
mSkyBoxEnabled(false),
mSkyDomeEnabled(false),
mFogMode(FOG_NONE),
mFogColour(),
mFogStart(0),
mFogEnd(0),
mFogDensity(0),
mSpecialCaseQueueMode(SCRQM_EXCLUDE),
mWorldGeometryRenderQueue(RENDER_QUEUE_WORLD_GEOMETRY_1),
mLastFrameNumber(0),
mResetIdentityView(false),
mResetIdentityProj(false),
mNormaliseNormalsOnScale(true),
mFlipCullingOnNegativeScale(true),
mLightsDirtyCounter(0),
mMovableNameGenerator("Ogre/MO"),
mShadowCasterPlainBlackPass(0),
mShadowReceiverPass(0),
mDisplayNodes(false),
mShowBoundingBoxes(false),
mActiveCompositorChain(0),
mLateMaterialResolving(false),
mShadowTechnique(SHADOWTYPE_NONE),
mDebugShadows(false),
mShadowColour(ColourValue(0.25, 0.25, 0.25)),
mShadowDebugPass(0),
mShadowStencilPass(0),
mShadowModulativePass(0),
mShadowMaterialInitDone(false),
mShadowIndexBufferSize(51200),
mFullScreenQuad(0),
mShadowDirLightExtrudeDist(10000),
mIlluminationStage(IRS_NONE),
mShadowTextureConfigDirty(true),
mShadowUseInfiniteFarPlane(true),
mShadowCasterRenderBackFaces(true),
mShadowAdditiveLightClip(false),
mLightClippingInfoMapFrameNumber(999),
mShadowCasterSphereQuery(0),
mShadowCasterAABBQuery(0),
mDefaultShadowFarDist(0),
mDefaultShadowFarDistSquared(0),
mShadowTextureOffset(0.6), 
mShadowTextureFadeStart(0.7), 
mShadowTextureFadeEnd(0.9),
mShadowTextureSelfShadow(false),
mShadowTextureCustomCasterPass(0),
mShadowTextureCustomReceiverPass(0),
mVisibilityMask(0xFFFFFFFF),
mFindVisibleObjects(true),
mSuppressRenderStateChanges(false),
mSuppressShadows(false),
mCameraRelativeRendering(false),
mLastLightHash(0),
mLastLightLimit(0),
mLastLightHashGpuProgram(0),
mGpuParamsDirty((uint16)GPV_ALL)
{

    // init sky
    for (size_t i = 0; i < 5; ++i)
    {
        mSkyDomeEntity[i] = 0;
    }

	mShadowCasterQueryListener = OGRE_NEW ShadowCasterSceneQueryListener(this);

    Root *root = Root::getSingletonPtr();
    if (root)
        _setDestinationRenderSystem(root->getRenderSystem());

	// Setup default queued renderable visitor
	mActiveQueuedRenderableVisitor = &mDefaultQueuedRenderableVisitor;

	// set up default shadow camera setup
	mDefaultShadowCameraSetup.bind(OGRE_NEW DefaultShadowCameraSetup());

	// init shadow texture config
	setShadowTextureCount(1);

	// init shadow texture count per type.
	mShadowTextureCountPerType[Light::LT_POINT] = 1;
	mShadowTextureCountPerType[Light::LT_DIRECTIONAL] = 1;
	mShadowTextureCountPerType[Light::LT_SPOTLIGHT] = 1;

	// create the auto param data source instance
	mAutoParamDataSource = createAutoParamDataSource();

}


 

当使用基于Texture的阴影且mShadowCasterRenderBackFaces为true时就会利用背面去渲染阴影深度图。


const Pass* SceneManager::_setPass(const Pass* pass, bool evenIfSuppressed, 
								   bool shadowDerivation)
{
...................

		// Culling mode
		if (isShadowTechniqueTextureBased() 
			&& mIlluminationStage == IRS_RENDER_TO_TEXTURE
			&& mShadowCasterRenderBackFaces
			&& pass->getCullingMode() == CULL_CLOCKWISE)
		{
			// render back faces into shadow caster, can help with depth comparison
			mPassCullingMode = CULL_ANTICLOCKWISE;
		}
		else
		{
			mPassCullingMode = pass->getCullingMode();
		}
		mDestRenderSystem->_setCullingMode(mPassCullingMode);
..........................
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值