public async System.Threading.Tasks.Task <bool> Init(CRenderContext RHICtx) { await Thread.AsyncDummyClass.DummyFunc(); if (mSE_CSMMobile == null) { mSE_CSMMobile = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxSE_SSM>(); } if (mSE_CSMMobile == null) { return(false); } mWholeReslutionX = mResolutionX * mCsmNum; mWholeReslutionY = mResolutionY; CGfxSceneViewInfo ShadowMapViewInfo = new CGfxSceneViewInfo(); ShadowMapViewInfo.mUseDSV = true; ShadowMapViewInfo.Width = mWholeReslutionX; ShadowMapViewInfo.Height = mWholeReslutionY; ShadowMapViewInfo.mDSVDesc.Init(); ShadowMapViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D16_UNORM; ShadowMapViewInfo.mDSVDesc.Width = mWholeReslutionX; ShadowMapViewInfo.mDSVDesc.Height = mWholeReslutionY; mShadowMapView = new CGfxSceneView(); if (false == mShadowMapView.Init(RHICtx, null, ShadowMapViewInfo)) { return(false); } mRenderPassDesc_CSM = new CRenderPassDesc[4]; FrameBufferClearColor TempClearColor = new FrameBufferClearColor(); TempClearColor.r = 1.0f; TempClearColor.g = 1.0f; TempClearColor.b = 1.0f; TempClearColor.a = 1.0f; mRenderPassDesc_CSM[0].mFBLoadAction_Color = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_CSM[0].mFBStoreAction_Color = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_CSM[0].mFBClearColorRT0 = TempClearColor; mRenderPassDesc_CSM[0].mFBLoadAction_Depth = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_CSM[0].mFBStoreAction_Depth = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_CSM[0].mDepthClearValue = 1.0f; mRenderPassDesc_CSM[0].mFBLoadAction_Stencil = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_CSM[0].mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_CSM[0].mStencilClearValue = 0u; for (UInt32 RPDIdx = 1; RPDIdx < 4; RPDIdx++) { mRenderPassDesc_CSM[RPDIdx].mFBLoadAction_Color = FrameBufferLoadAction.LoadActionLoad; mRenderPassDesc_CSM[RPDIdx].mFBStoreAction_Color = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_CSM[RPDIdx].mFBClearColorRT0 = TempClearColor; mRenderPassDesc_CSM[RPDIdx].mFBLoadAction_Depth = FrameBufferLoadAction.LoadActionLoad; mRenderPassDesc_CSM[RPDIdx].mFBStoreAction_Depth = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_CSM[RPDIdx].mDepthClearValue = 1.0f; mRenderPassDesc_CSM[RPDIdx].mFBLoadAction_Stencil = FrameBufferLoadAction.LoadActionLoad; mRenderPassDesc_CSM[RPDIdx].mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_CSM[RPDIdx].mStencilClearValue = 0u; } mShadowCameraArray = new CGfxCamera[4]; for (UInt32 CamIdx = 0; CamIdx < 4; CamIdx++) { mShadowCameraArray[CamIdx] = new CGfxCamera(); if (mShadowCameraArray[CamIdx].Init(RHICtx, false) == false) { return(false); } } mShadowMapView.ResizeViewport(mBorderSize, mBorderSize, mInnerResolutionY, mInnerResolutionY); mShadowMapSizeAndRcp.X = mWholeReslutionX; mShadowMapSizeAndRcp.Y = mWholeReslutionY; mShadowMapSizeAndRcp.Z = 1.0f / mWholeReslutionX; mShadowMapSizeAndRcp.W = 1.0f / mWholeReslutionY; if (CEngine.Instance.RenderSystem.RHIType == ERHIType.RHT_OGL) { //gles; mOrtho2UVMtx.M11 = 0.5f; mOrtho2UVMtx.M22 = 0.5f; mOrtho2UVMtx.M33 = 0.5f; mOrtho2UVMtx.M44 = 1.0f; mOrtho2UVMtx.M41 = 0.5f; mOrtho2UVMtx.M42 = 0.5f; mOrtho2UVMtx.M43 = 0.5f; } else { // D3D mOrtho2UVMtx.M11 = 0.5f; mOrtho2UVMtx.M22 = -0.5f; mOrtho2UVMtx.M33 = 1.0f; mOrtho2UVMtx.M44 = 1.0f; mOrtho2UVMtx.M41 = 0.5f; mOrtho2UVMtx.M42 = 0.5f; } for (UInt32 UVAdjustIdx = 0; UVAdjustIdx < mCsmNum; UVAdjustIdx++) { mUVAdjustedMtxArray[UVAdjustIdx].M11 = (float)mInnerResolutionX / (float)mWholeReslutionX; mUVAdjustedMtxArray[UVAdjustIdx].M22 = (float)mInnerResolutionY / (float)mWholeReslutionY; mUVAdjustedMtxArray[UVAdjustIdx].M33 = 1.0f; mUVAdjustedMtxArray[UVAdjustIdx].M44 = 1.0f; mUVAdjustedMtxArray[UVAdjustIdx].M41 = (float)(mResolutionX * UVAdjustIdx + mBorderSize) / (float)mWholeReslutionX; mUVAdjustedMtxArray[UVAdjustIdx].M42 = (float)mBorderSize / (float)mWholeReslutionY; } mCsmDistanceArray[0] = mShadowDistance * 0.08f; mCsmDistanceArray[1] = mShadowDistance * 0.15f; mCsmDistanceArray[2] = mShadowDistance * 0.30f; mCsmDistanceArray[3] = mShadowDistance * 0.47f; mSumDistanceFarArray[0] = mCsmDistanceArray[0]; mSumDistanceFarArray[1] = mCsmDistanceArray[0] + mCsmDistanceArray[1]; mSumDistanceFarArray[2] = mCsmDistanceArray[0] + mCsmDistanceArray[1] + mCsmDistanceArray[2]; mSumDistanceFarArray[3] = mCsmDistanceArray[0] + mCsmDistanceArray[1] + mCsmDistanceArray[2] + mCsmDistanceArray[3]; mSumDistanceFarVec.X = mSumDistanceFarArray[0]; mSumDistanceFarVec.Y = mSumDistanceFarArray[1]; mSumDistanceFarVec.Z = mSumDistanceFarArray[2]; mSumDistanceFarVec.W = mSumDistanceFarArray[3]; return(true); }
public async System.Threading.Tasks.Task <bool> Init(CRenderContext RHICtx) { await Thread.AsyncDummyClass.DummyFunc(); if (mSE_SSM == null) { mSE_SSM = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxSE_SSM>(); } if (mSE_SSM == null) { return(false); } CGfxSceneViewInfo ShadowMapViewInfo = new CGfxSceneViewInfo(); ShadowMapViewInfo.mUseDSV = true; ShadowMapViewInfo.Width = mResolutionX; ShadowMapViewInfo.Height = mResolutionY; // TODO��OpenGL ES���ʹ�� D24S8��ʽ�� ����depth texture�Ľ����Զ��0�� D16��D32��ʽ����ȷ�ġ� ShadowMapViewInfo.mDSVDesc.Init(); ShadowMapViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D16_UNORM; //ShadowMapViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D32_FLOAT; //ShadowMapViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D24_UNORM_S8_UINT; ShadowMapViewInfo.mDSVDesc.Width = mResolutionX; ShadowMapViewInfo.mDSVDesc.Height = mResolutionY; //CRenderTargetViewDesc rtDesc0 = new CRenderTargetViewDesc(); //rtDesc0.Init(); //rtDesc0.Format = EPixelFormat.PXF_R8G8B8A8_UNORM; //rtDesc0.Width = mResolutionX; //rtDesc0.Height = mResolutionY; //ShadowMapViewInfo.mRTVDescArray.Add(rtDesc0); mShadowMapView = new CGfxSceneView(); if (false == mShadowMapView.Init(RHICtx, null, ShadowMapViewInfo)) { return(false); } mRenderPassDesc_SSM = new CRenderPassDesc(); FrameBufferClearColor TempClearColor = new FrameBufferClearColor(); TempClearColor.r = 1.0f; TempClearColor.g = 1.0f; TempClearColor.b = 1.0f; TempClearColor.a = 1.0f; mRenderPassDesc_SSM.mFBLoadAction_Color = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_SSM.mFBStoreAction_Color = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_SSM.mFBClearColorRT0 = TempClearColor; mRenderPassDesc_SSM.mFBLoadAction_Depth = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_SSM.mFBStoreAction_Depth = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_SSM.mDepthClearValue = 1.0f; mRenderPassDesc_SSM.mFBLoadAction_Stencil = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_SSM.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_SSM.mStencilClearValue = 0u; mShadowCamera = new CGfxCamera(); if (mShadowCamera.Init(RHICtx, false) == false) { return(false); } //mShadowCamera.SetSceneView(RHICtx, mShadowMapView); mShadowMapView.ResizeViewport(mBorderSize, mBorderSize, mInnerResolutionY, mInnerResolutionY); mShadowMapSizeAndRcp.X = mResolutionX; mShadowMapSizeAndRcp.Y = mResolutionY; mShadowMapSizeAndRcp.Z = 1.0f / mResolutionX; mShadowMapSizeAndRcp.W = 1.0f / mResolutionY; //// OpenGL //mOrtho2UVMtx.M11 = 0.5f; //mOrtho2UVMtx.M22 = 0.5f; //mOrtho2UVMtx.M33 = 0.5f; //mOrtho2UVMtx.M41 = 0.5f; //mOrtho2UVMtx.M42 = 0.5f; //mOrtho2UVMtx.M43 = 0.5f; //mOrtho2UVMtx.M44 = 1.0f; if (CEngine.Instance.RenderSystem.RHIType == ERHIType.RHT_OGL) { //gles; mOrtho2UVMtx.M11 = 0.5f; mOrtho2UVMtx.M22 = 0.5f; mOrtho2UVMtx.M33 = 0.5f; mOrtho2UVMtx.M44 = 1.0f; mOrtho2UVMtx.M41 = 0.5f; mOrtho2UVMtx.M42 = 0.5f; mOrtho2UVMtx.M43 = 0.5f; } else { // D3D mOrtho2UVMtx.M11 = 0.5f; mOrtho2UVMtx.M22 = -0.5f; mOrtho2UVMtx.M33 = 1.0f; mOrtho2UVMtx.M44 = 1.0f; mOrtho2UVMtx.M41 = 0.5f; mOrtho2UVMtx.M42 = 0.5f; } return(true); }