Esempio n. 1
0
        public override async System.Threading.Tasks.Task <bool> Init(CRenderContext RHICtx, UInt32 width, UInt32 height, CGfxCamera camera, IntPtr WinHandle)
        {
            CGfxSceneViewInfo SnapshotViewInfo = new CGfxSceneViewInfo();

            SnapshotViewInfo.mUseDSV = true;
            SnapshotViewInfo.Width   = width;
            SnapshotViewInfo.Height  = height;
            SnapshotViewInfo.mDSVDesc.Init();
            SnapshotViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D24_UNORM_S8_UINT;
            SnapshotViewInfo.mDSVDesc.Width  = width;
            SnapshotViewInfo.mDSVDesc.Height = height;

            CRenderTargetViewDesc rtDesc0 = new CRenderTargetViewDesc();

            rtDesc0.Init();
            rtDesc0.Format = EPixelFormat.PXF_R8G8B8A8_UNORM;
            rtDesc0.Width  = width;
            rtDesc0.Height = height;
            SnapshotViewInfo.mRTVDescArray.Add(rtDesc0);

            BaseSceneView = new CGfxSceneView();
            if (false == BaseSceneView.Init(RHICtx, null, SnapshotViewInfo))
            {
                return(false);
            }

            Camera = camera;
            //mCamera.SetSceneView(RHICtx, mBaseSceneView);

            mRenderPassDesc_Snapshot = new CRenderPassDesc();
            FrameBufferClearColor TempClearColor = new FrameBufferClearColor();

            TempClearColor.r = 0.0f;
            TempClearColor.g = 0.0f;
            TempClearColor.b = 0.0f;
            TempClearColor.a = 0.0f;
            mRenderPassDesc_Snapshot.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Snapshot.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Snapshot.mFBClearColorRT0       = TempClearColor;
            mRenderPassDesc_Snapshot.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Snapshot.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Snapshot.mDepthClearValue       = 1.0f;
            mRenderPassDesc_Snapshot.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Snapshot.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Snapshot.mStencilClearValue     = 0u;

            mRenderPassDesc_Final = new CRenderPassDesc();
            TempClearColor.r      = 0.0f;
            TempClearColor.g      = 1.0f;
            TempClearColor.b      = 0.0f;
            TempClearColor.a      = 0.0f;
            mRenderPassDesc_Final.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Final.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Final.mFBClearColorRT0       = TempClearColor;
            mRenderPassDesc_Final.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Final.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Final.mDepthClearValue       = 1.0f;
            mRenderPassDesc_Final.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Final.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Final.mStencilClearValue     = 0u;

            if (mSnapshotSE == null)
            {
                mSnapshotSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxSnapshotSE>();
            }
            if (mCopySE == null)
            {
                mCopySE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileCopySE>();
            }

            var ufoViewInfo = new CGfxScreenViewDesc();

            ufoViewInfo.IsSwapChainBuffer   = false;
            ufoViewInfo.UseDepthStencilView = false;
            ufoViewInfo.Width  = width;
            ufoViewInfo.Height = height;

            var rtDesc1 = new CRenderTargetViewDesc();

            rtDesc1.Init();
            rtDesc1.mCanBeSampled = vBOOL.FromBoolean(true);
            rtDesc1.Format        = EPixelFormat.PXF_R8G8B8A8_UNORM;
            rtDesc1.Width         = width;
            rtDesc1.Height        = height;
            ufoViewInfo.mRTVDescArray.Add(rtDesc1);

            var screenAlignedTriangle = CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(RHICtx, CEngineDesc.ScreenAlignedTriangleName, true);

            mScreenAlignedTriangle = CEngine.Instance.MeshManager.CreateMesh(RHICtx, screenAlignedTriangle);
            var mtl = await CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(RHICtx, RName.GetRName("Material/defaultmaterial.instmtl"));

            mScreenAlignedTriangle.SetMaterialInstance(RHICtx, 0, mtl, CEngine.Instance.PrebuildPassData.DefaultShadingEnvs);
            //await mScreenAlignedTriangle.AwaitEffects();
            mFinalView = new CGfxScreenView();
            await mFinalView.Init(RHICtx, null, ufoViewInfo, mCopySE, mtl, mScreenAlignedTriangle);

            var viewportSizeAndRcp = new Vector4(width, height, 1.0f / width, 1.0f / height);

            mFinalView.ViewportSizeAndRcp = viewportSizeAndRcp;

            return(true);
        }
Esempio n. 2
0
        public bool Init(UInt32 width, UInt32 height, CGfxCamera camera)
        {
            var RHICtx = EngineNS.CEngine.Instance.RenderContext;

            mViewportSizeX = width;
            mViewportSizeY = height;

            //hit proxy view;
            CGfxSceneViewInfo HitProxyViewInfo = new CGfxSceneViewInfo();

            HitProxyViewInfo.mUseDSV = true;
            HitProxyViewInfo.Width   = width;
            HitProxyViewInfo.Height  = height;
            HitProxyViewInfo.mDSVDesc.Init();
            HitProxyViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D24_UNORM_S8_UINT;
            HitProxyViewInfo.mDSVDesc.Width  = width;
            HitProxyViewInfo.mDSVDesc.Height = height;

            CRenderTargetViewDesc rtDesc0 = new CRenderTargetViewDesc();

            rtDesc0.Init();
            rtDesc0.Format = EPixelFormat.PXF_R8G8B8A8_UNORM;
            rtDesc0.Width  = width;
            rtDesc0.Height = height;
            HitProxyViewInfo.mRTVDescArray.Add(rtDesc0);

            mHitProxyView = new CGfxSceneView();
            if (false == mHitProxyView.Init(RHICtx, null, HitProxyViewInfo))
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"HitProxyError!!!", "");
                return(false);
            }

            mCamera = camera;

            mRenderPassDesc_HitProxy = new CRenderPassDesc();
            FrameBufferClearColor TempClearColor = new FrameBufferClearColor();

            TempClearColor.r = 0.0f;
            TempClearColor.g = 0.0f;
            TempClearColor.b = 0.0f;
            TempClearColor.a = 0.0f;
            mRenderPassDesc_HitProxy.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_HitProxy.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_HitProxy.mFBClearColorRT0       = TempClearColor;
            mRenderPassDesc_HitProxy.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_HitProxy.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_HitProxy.mDepthClearValue       = 1.0f;
            mRenderPassDesc_HitProxy.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_HitProxy.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_HitProxy.mStencilClearValue     = 0u;

            if (mHitProxySE == null)
            {
                mHitProxySE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxHitProxySE>();
            }
            if (mHitProxySE == null)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"HitProxyError!!!", "");
                return(false);
            }

            if (mHitProxyAxisSE == null)
            {
                mHitProxyAxisSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxHitProxyAxisSE>();
            }
            if (mHitProxyAxisSE == null)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"HitProxyError!!!", "");
                return(false);
            }

            mHitProxyCPUTexture = new CBlobObject();
            return(true);
        }
Esempio n. 3
0
        public override async System.Threading.Tasks.Task <bool> Init(CRenderContext RHICtx, UInt32 width, UInt32 height, CGfxCamera camera, IntPtr WinHandle)
        {
            if (mOpaqueSE == null)
            {
                mOpaqueSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileOpaqueSE>();
            }

            if (mCustomTranslucentSE == null)
            {
                mCustomTranslucentSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileCustomTranslucentSE>();
            }

            if (mTranslucentSE == null)
            {
                mTranslucentSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileTranslucentSE>();
            }

            if (mCopySE == null)
            {
                mCopySE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileCopySE>();
            }

            if (mGizmosSE == null)
            {
                mGizmosSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxGizmosSE>();
            }

            if (mSE_MobileSky == null)
            {
                mSE_MobileSky = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxSE_MobileSky>();
            }

            if (mOpaqueSE == null || mCustomTranslucentSE == null || mTranslucentSE == null || mCopySE == null || mGizmosSE == null || mSE_MobileSky == null)
            {
                return(false);
            }

            {
                //base scene view;
                CGfxSceneViewInfo BaseViewInfo = new CGfxSceneViewInfo();
                BaseViewInfo.mUseDSV = true;
                BaseViewInfo.Width   = width;
                BaseViewInfo.Height  = height;
                BaseViewInfo.mDSVDesc.Init();
                BaseViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D24_UNORM_S8_UINT;
                BaseViewInfo.mDSVDesc.Width  = width;
                BaseViewInfo.mDSVDesc.Height = height;

                CRenderTargetViewDesc rtDesc0 = new CRenderTargetViewDesc();
                rtDesc0.Init();
                //rtDesc0.Format = EPixelFormat.PXF_R8G8B8A8_UNORM;
                rtDesc0.Format = EPixelFormat.PXF_R16G16B16A16_FLOAT;
                rtDesc0.Width  = width;
                rtDesc0.Height = height;
                BaseViewInfo.mRTVDescArray.Add(rtDesc0);

                BaseSceneView = new CGfxSceneView();
                if (false == BaseSceneView.Init(RHICtx, null, BaseViewInfo))
                {
                    return(false);
                }
                BaseSceneView.UIHost = new UISystem.UIHost();
                await BaseSceneView.UIHost.Initialize(RHICtx, new UISystem.UIHostInitializer());

                BaseSceneView.UIHost.WindowSize = new SizeF(width, height);

                mForwardBasePass = new CGfxFramePass(RHICtx, "OffSrcFWBasePass");
                mForwardBasePass.mBaseSceneView = BaseSceneView;

                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Opaque, PrebuildPassIndex.PPI_OpaquePbr, mOpaqueSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_CustomOpaque, PrebuildPassIndex.PPI_OpaquePbr, mOpaqueSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Sky, PrebuildPassIndex.PPI_Sky, mSE_MobileSky);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_CustomTranslucent, PrebuildPassIndex.PPI_CustomTranslucentPbr, mCustomTranslucentSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Translucent, PrebuildPassIndex.PPI_Gizmos, mTranslucentSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Gizmos, PrebuildPassIndex.PPI_TransparentPbr, mGizmosSE);

                FrameBufferClearColor TempClearColor = new FrameBufferClearColor();
                TempClearColor.r = 0.0f;
                TempClearColor.g = 0.0f;
                TempClearColor.b = 0.0f;
                TempClearColor.a = 0.0f;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mFBClearColorRT0       = TempClearColor;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mDepthClearValue       = 1.0f;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mStencilClearValue     = 0u;
            }

            {
                //ufo scene view;
                CGfxScreenViewDesc UFOViewInfo = new CGfxScreenViewDesc();
                UFOViewInfo.IsSwapChainBuffer   = false;
                UFOViewInfo.UseDepthStencilView = false;
                UFOViewInfo.Width  = width;
                UFOViewInfo.Height = height;

                var rtDesc1 = new CRenderTargetViewDesc();
                rtDesc1.Init();
                rtDesc1.mCanBeSampled = vBOOL.FromBoolean(true);
                rtDesc1.Format        = EPixelFormat.PXF_R8G8B8A8_UNORM;
                rtDesc1.Width         = width;
                rtDesc1.Height        = height;
                UFOViewInfo.mRTVDescArray.Add(rtDesc1);

                mCopyPostprocessPass = new CGfxPostprocessPass();
                await mCopyPostprocessPass.Init(RHICtx, SwapChain, UFOViewInfo, mCopySE, RName.GetRName("Material/defaultmaterial.instmtl"), "OffSrcCopyPost");

                FrameBufferClearColor TempClearColor = new FrameBufferClearColor();
                TempClearColor.r = 0.0f;
                TempClearColor.g = 0.0f;
                TempClearColor.b = 0.0f;
                TempClearColor.a = 0.0f;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mFBClearColorRT0       = TempClearColor;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mDepthClearValue       = 1.0f;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mStencilClearValue     = 0u;
            }

            Camera = camera;
            Camera.SetSceneView(RHICtx, BaseSceneView);

            bool IsReady = await mSSM.Init(RHICtx);

            if (IsReady == false)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"SSM Error", "");
                return(false);
            }

            IsReady = await mBloomMobile.Init(RHICtx, width, height, BaseSceneView);

            if (IsReady == false)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"BloomError", "");
                return(false);
            }

            //sun shaft;
            IsReady = await mSunShaftMobile.Init(RHICtx, width, height);

            if (IsReady == false)
            {
                System.Diagnostics.Debug.Assert(false);
                return(false);
            }

            //mobile ao;
            IsReady = await mMobileAO.Init(RHICtx, width, height, BaseSceneView);

            if (IsReady == false)
            {
                System.Diagnostics.Debug.Assert(false);
                return(false);
            }

            //
            mOpaqueSE.mTex_ShadowMap = mSSM.mShadowMapView.FrameBuffer.GetSRV_DepthStencil();
            mOpaqueSE.EnvMapName     = CEngine.Instance.Desc.DefaultEnvMap;
            mOpaqueSE.EyeEnvMapName  = CEngine.Instance.Desc.DefaultEyeEnvMap;

            mCustomTranslucentSE.EnvMapName     = CEngine.Instance.Desc.DefaultEnvMap;
            mCustomTranslucentSE.mTex_ShadowMap = mSSM.mShadowMapView.FrameBuffer.GetSRV_DepthStencil();

            mTranslucentSE.EnvMapName = CEngine.Instance.Desc.DefaultEnvMap;

            mCopySE.mBaseSceneView = BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0);
            if (CEngine.EnableBloom == true)
            {
                mCopySE.mBloomTex = mBloomMobile.mUSView8.FrameBuffer.GetSRV_RenderTarget(0);
            }
            else
            {
                mCopySE.mBloomTex = BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0);
            }
            mCopySE.VignetteTex  = CEngine.Instance.Desc.DefaultVignette;
            mCopySE.mSunShaftTex = mSunShaftMobile.mView_Blur.FrameBuffer.GetSRV_RenderTarget(0);
            //mCopySE.mSRV_MobileAo = mMobileAO.mView_BlurV.FrameBuffer.GetSRV_RenderTarget(0);
            mCopySE.mSRV_MobileAo = mMobileAO.mView_AoMask.FrameBuffer.GetSRV_RenderTarget(0);

            {
                var Tex2DDesc = mOpaqueSE.EnvMap.TxPicDesc;
                BaseSceneView.mEnvMapMipMaxLevel = Tex2DDesc.MipLevel - 1;

                Tex2DDesc = mOpaqueSE.EyeEnvMap.TxPicDesc;
                BaseSceneView.mEyeEnvMapMaxMipLevel = Tex2DDesc.MipLevel - 1;

                var ViewportSizeAndRcp = new Vector4(width, height, 1.0f / width, 1.0f / height);
                mCopyPostprocessPass.mScreenView.ViewportSizeAndRcp = ViewportSizeAndRcp;
            }

            return(true);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public override async System.Threading.Tasks.Task <bool> Init(CRenderContext RHICtx, UInt32 width, UInt32 height, CGfxCamera camera, IntPtr WinHandle)
        {
            if (RHICtx == null)
            {
                RHICtx = CEngine.Instance.RenderContext;
            }

            if (mOpaqueSE == null)
            {
                mOpaqueSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileOpaqueSE>();
            }

            if (mCustomTranslucentSE == null)
            {
                mCustomTranslucentSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileCustomTranslucentSE>();
            }

            if (mTranslucentSE == null)
            {
                mTranslucentSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileTranslucentSE>();
            }

            if (mCopySE == null)
            {
                mCopySE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileCopySE>();
            }

            if (mSE_MobileSky == null)
            {
                mSE_MobileSky = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxSE_MobileSky>();
            }

            if (mOpaqueSE == null || mCustomTranslucentSE == null || mTranslucentSE == null || mCopySE == null || mSE_MobileSky == null)
            {
                return(false);
            }

            {
                //base scene view;
                CGfxSceneViewInfo BaseViewInfo = new CGfxSceneViewInfo();
                BaseViewInfo.mUseDSV = true;
                BaseViewInfo.Width   = width;
                BaseViewInfo.Height  = height;
                BaseViewInfo.mDSVDesc.Init();
                BaseViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D24_UNORM_S8_UINT;
                BaseViewInfo.mDSVDesc.Width  = width;
                BaseViewInfo.mDSVDesc.Height = height;

                CRenderTargetViewDesc rtDesc0 = new CRenderTargetViewDesc();
                rtDesc0.Init();
                if (RHICtx.ContextCaps.SupportHalfRT == 0)
                {
                    CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EnvShader.CGfxMobileOpaqueSE>().SetMacroDefineValue("ENV_DISABLE_AO", "1");
                    CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EnvShader.CGfxMobileCopySE>().SetMacroDefineValue("ENV_DISABLE_AO", "1");
                    CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Bricks.GpuDriven.GpuScene.CGfxMergeInstanceSE>().SetMacroDefineValue("ENV_DISABLE_AO", "1");
                    rtDesc0.Format = EPixelFormat.PXF_R8G8B8A8_UNORM;
                }
                else
                {
                    CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EnvShader.CGfxMobileOpaqueSE>().SetMacroDefineValue("ENV_DISABLE_AO", "0");
                    CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EnvShader.CGfxMobileCopySE>().SetMacroDefineValue("ENV_DISABLE_AO", "0");
                    CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <Bricks.GpuDriven.GpuScene.CGfxMergeInstanceSE>().SetMacroDefineValue("ENV_DISABLE_AO", "0");
                    rtDesc0.Format = EPixelFormat.PXF_R16G16B16A16_FLOAT;
                }
                Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"MobileGame render texture format: {rtDesc0.Format}");
                rtDesc0.Width  = width;
                rtDesc0.Height = height;
                BaseViewInfo.mRTVDescArray.Add(rtDesc0);

                BaseSceneView = new CGfxSceneView();
                if (false == BaseSceneView.Init(RHICtx, null, BaseViewInfo))
                {
                    return(false);
                }
                BaseSceneView.UIHost = await CEngine.Instance.UIManager.RegisterHost("Game");

                BaseSceneView.UIHost.IsInputActive = true;
                BaseSceneView.UIHost.WindowSize    = new SizeF(width, height);

                mForwardBasePass = new CGfxFramePass(RHICtx, "GameForwordBasePse");
                mForwardBasePass.mBaseSceneView = BaseSceneView;

                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Opaque, PrebuildPassIndex.PPI_OpaquePbr, mOpaqueSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_CustomOpaque, PrebuildPassIndex.PPI_OpaquePbr, mOpaqueSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Sky, PrebuildPassIndex.PPI_Sky, mSE_MobileSky);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_CustomTranslucent, PrebuildPassIndex.PPI_CustomTranslucentPbr, mCustomTranslucentSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Translucent, PrebuildPassIndex.PPI_TransparentPbr, mTranslucentSE);

                FrameBufferClearColor TempClearColor = new FrameBufferClearColor();
                TempClearColor.r = 0.0f;
                TempClearColor.g = 0.0f;
                TempClearColor.b = 0.0f;
                TempClearColor.a = 1.0f;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mFBClearColorRT0       = TempClearColor;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mDepthClearValue       = 1.0f;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mStencilClearValue     = 0u;
            }

            {
                EngineNS.CSwapChainDesc SwapChainDesc;
                SwapChainDesc.Format       = EngineNS.EPixelFormat.PXF_R8G8B8A8_UNORM;
                SwapChainDesc.Width        = width;
                SwapChainDesc.Height       = height;
                SwapChainDesc.WindowHandle = WinHandle;
                SwapChainDesc.ColorSpace   = EColorSpace.COLOR_SPACE_SRGB_NONLINEAR;
                SwapChain = RHICtx.CreateSwapChain(SwapChainDesc);
                //RHICtx.BindCurrentSwapChain(mSwapChain);

                //ufo scene view;
                CGfxScreenViewDesc UFOViewInfo = new CGfxScreenViewDesc();
                UFOViewInfo.IsSwapChainBuffer   = true;
                UFOViewInfo.UseDepthStencilView = false;
                UFOViewInfo.Width  = width;
                UFOViewInfo.Height = height;

                var rtDesc1 = new CRenderTargetViewDesc();
                rtDesc1.mCanBeSampled = vBOOL.FromBoolean(false);
                UFOViewInfo.mRTVDescArray.Add(rtDesc1);

                mCopyPostprocessPass = new CGfxPostprocessPass();
                await mCopyPostprocessPass.Init(RHICtx, SwapChain, UFOViewInfo, mCopySE, RName.GetRName("Material/defaultmaterial.instmtl"), "GameCopyPost");

                FrameBufferClearColor TempClearColor = new FrameBufferClearColor();
                TempClearColor.r = 0.0f;
                TempClearColor.g = 0.0f;
                TempClearColor.b = 0.0f;
                TempClearColor.a = 0.0f;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mFBClearColorRT0       = TempClearColor;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mDepthClearValue       = 1.0f;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mStencilClearValue     = 0u;
            }

            Camera = camera;
            Camera.SetSceneView(RHICtx, BaseSceneView);

            //shadow ssm;
            bool IsReady = await mSSM.Init(RHICtx);

            if (IsReady == false)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"SSM Error", "");
                return(false);
            }

            //post effect;
            IsReady = await mBloomMobile.Init(RHICtx, width, height, BaseSceneView);

            if (IsReady == false)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"BloomError", "");
                return(false);
            }

            //sun shaft;
            IsReady = await mSunShaftMobile.Init(RHICtx, width, height);

            if (IsReady == false)
            {
                System.Diagnostics.Debug.Assert(false);
                return(false);
            }

            //mobile ao;
            IsReady = await mMobileAO.Init(RHICtx, width, height, BaseSceneView);

            if (IsReady == false)
            {
                System.Diagnostics.Debug.Assert(false);
                return(false);
            }

            //
            mOpaqueSE.mTex_ShadowMap = mSSM.mShadowMapView.FrameBuffer.GetSRV_DepthStencil();
            mOpaqueSE.EnvMapName     = CEngine.Instance.Desc.DefaultEnvMap;
            mOpaqueSE.EyeEnvMapName  = CEngine.Instance.Desc.DefaultEyeEnvMap;

            mCustomTranslucentSE.EnvMapName     = CEngine.Instance.Desc.DefaultEnvMap;
            mCustomTranslucentSE.mTex_ShadowMap = mSSM.mShadowMapView.FrameBuffer.GetSRV_DepthStencil();

            mTranslucentSE.EnvMapName = CEngine.Instance.Desc.DefaultEnvMap;

            mCopySE.mBaseSceneView = BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0);
            if (CEngine.EnableBloom == true)
            {
                mCopySE.mBloomTex = mBloomMobile.mUSView8.FrameBuffer.GetSRV_RenderTarget(0);
            }
            else
            {
                mCopySE.mBloomTex = BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0);
            }
            mCopySE.VignetteTex  = CEngine.Instance.Desc.DefaultVignette;
            mCopySE.mSunShaftTex = mSunShaftMobile.mView_Blur.FrameBuffer.GetSRV_RenderTarget(0);
            //mCopySE.mSRV_MobileAo = mMobileAO.mView_BlurV.FrameBuffer.GetSRV_RenderTarget(0);
            mCopySE.mSRV_MobileAo = mMobileAO.mView_AoMask.FrameBuffer.GetSRV_RenderTarget(0);

            {
                var Tex2DDesc = mOpaqueSE.EnvMap.TxPicDesc;
                BaseSceneView.mEnvMapMipMaxLevel = Tex2DDesc.MipLevel - 1;

                Tex2DDesc = mOpaqueSE.EyeEnvMap.TxPicDesc;
                BaseSceneView.mEyeEnvMapMaxMipLevel = Tex2DDesc.MipLevel - 1;

                var ViewportSizeAndRcp = new Vector4(width, height, 1.0f / width, 1.0f / height);
                mCopyPostprocessPass.mScreenView.ViewportSizeAndRcp = ViewportSizeAndRcp;
            }

            return(true);
        }
        public override async System.Threading.Tasks.Task <bool> Init(CRenderContext rc, UInt32 width, UInt32 height, CGfxCamera camera, IntPtr WinHandle)
        {
            if (mOpaqueSE == null)
            {
                mOpaqueSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileOpaqueEditorSE>();
            }

            if (mCustomTranslucentSE == null)
            {
                mCustomTranslucentSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileCustomTranslucentEditorSE>();
            }

            if (mTranslucentSE == null)
            {
                mTranslucentSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileTranslucentSE>();
            }

            if (mGizmosSE == null)
            {
                mGizmosSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxGizmosSE>();
            }

            mCopyEditorSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMobileCopyEditorSE>();

            if (mSE_MobileSky == null)
            {
                mSE_MobileSky = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxSE_MobileSky>();
            }

            if (mOpaqueSE == null || mCustomTranslucentSE == null || mTranslucentSE == null || mGizmosSE == null || mCopyEditorSE == null || mSE_MobileSky == null)
            {
                return(false);
            }

            //shadow csm;
            bool IsReady = await mCSM.Init(rc);

            if (IsReady == false)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"SSM Error", "");
                return(false);
            }

            //hitproxy;
            IsReady = mHitProxy.Init(width, height, camera);
            if (IsReady == false)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"HitProxyError", "");
                return(false);
            }
            //mHitProxy.mEnabled = true;

            IsReady = await mPickedEffect.Init(width, height, camera);

            if (IsReady == false)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"PickedEffectError", "");
                return(false);
            }

            {
                //base scene view;
                CGfxSceneViewInfo BaseViewInfo = new CGfxSceneViewInfo();
                BaseViewInfo.mUseDSV = true;
                BaseViewInfo.Width   = width;
                BaseViewInfo.Height  = height;
                BaseViewInfo.mDSVDesc.Init();
                BaseViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D24_UNORM_S8_UINT;
                BaseViewInfo.mDSVDesc.Width  = width;
                BaseViewInfo.mDSVDesc.Height = height;

                CRenderTargetViewDesc rtDesc0 = new CRenderTargetViewDesc();
                rtDesc0.Init();
                //rtDesc0.Format = EPixelFormat.PXF_R8G8B8A8_UNORM;
                rtDesc0.Format = EPixelFormat.PXF_R16G16B16A16_FLOAT;
                rtDesc0.Width  = width;
                rtDesc0.Height = height;
                BaseViewInfo.mRTVDescArray.Add(rtDesc0);

                BaseSceneView = new CGfxSceneView();
                if (false == BaseSceneView.Init(rc, null, BaseViewInfo))
                {
                    return(false);
                }
                BaseSceneView.UIHost = await CEngine.Instance.UIManager.RegisterHost("Editor");

                //BaseSceneView.UIHost.IsInputActive = false;
                BaseSceneView.UIHost.WindowSize = new SizeF(width, height);

                mForwardBasePass = new CGfxFramePass(rc, "GameForwordBasePass");
                mForwardBasePass.mBaseSceneView = BaseSceneView;
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Opaque, PrebuildPassIndex.PPI_OpaquePbrEditor, mOpaqueSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_CustomOpaque, PrebuildPassIndex.PPI_OpaquePbrEditor, mOpaqueSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Sky, PrebuildPassIndex.PPI_Sky, mSE_MobileSky);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_CustomTranslucent, PrebuildPassIndex.PPI_CustomTranslucentPbrEditor, mCustomTranslucentSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Translucent, PrebuildPassIndex.PPI_TransparentPbr, mTranslucentSE);
                mForwardBasePass.SetRLayerParameter(ERenderLayer.RL_Gizmos, PrebuildPassIndex.PPI_Gizmos, mGizmosSE);

                FrameBufferClearColor TempClearColor = new FrameBufferClearColor();
                TempClearColor.r = 0.0f;
                TempClearColor.g = 0.0f;
                TempClearColor.b = 0.0f;
                TempClearColor.a = 1.0f;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mFBClearColorRT0       = TempClearColor;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mDepthClearValue       = 1.0f;
                mForwardBasePass.mRenderPassDesc.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
                mForwardBasePass.mRenderPassDesc.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
                mForwardBasePass.mRenderPassDesc.mStencilClearValue     = 0u;
            }

            {
                EngineNS.CSwapChainDesc SwapChainDesc;
                SwapChainDesc.Format       = EngineNS.EPixelFormat.PXF_R8G8B8A8_UNORM;
                SwapChainDesc.Width        = width;
                SwapChainDesc.Height       = height;
                SwapChainDesc.WindowHandle = WinHandle;
                SwapChainDesc.ColorSpace   = EColorSpace.COLOR_SPACE_SRGB_NONLINEAR;
                SwapChain = rc.CreateSwapChain(SwapChainDesc);
                //RHICtx.BindCurrentSwapChain(mSwapChain);

                //final scene view;
                CGfxScreenViewDesc FinalViewInfo = new CGfxScreenViewDesc();
                FinalViewInfo.IsSwapChainBuffer   = true;
                FinalViewInfo.UseDepthStencilView = false;
                FinalViewInfo.Width  = width;
                FinalViewInfo.Height = height;

                var rtvDesc1 = new CRenderTargetViewDesc();
                rtvDesc1.mCanBeSampled = vBOOL.FromBoolean(false);
                rtvDesc1.Format        = SwapChainDesc.Format;
                FinalViewInfo.mRTVDescArray.Add(rtvDesc1);

                mCopyPostprocessPass = new CGfxPostprocessPass();
                await mCopyPostprocessPass.Init(rc, SwapChain, FinalViewInfo, mCopyEditorSE, RName.GetRName("Material/defaultmaterial.instmtl"), "EditorCopyPost");

                FrameBufferClearColor TempClearColor = new FrameBufferClearColor();
                TempClearColor.r = 0.0f;
                TempClearColor.g = 0.0f;
                TempClearColor.b = 0.0f;
                TempClearColor.a = 0.0f;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mFBClearColorRT0       = TempClearColor;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mDepthClearValue       = 1.0f;
                mCopyPostprocessPass.mRenderPassDesc.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
                mCopyPostprocessPass.mRenderPassDesc.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
                mCopyPostprocessPass.mRenderPassDesc.mStencilClearValue     = 0u;
            }

            Camera = camera;
            Camera.SetSceneView(rc, BaseSceneView);

            //post effect;
            IsReady = await mBloomMobile.Init(rc, width, height, BaseSceneView);

            if (IsReady == false)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"BloomError", "");
                return(false);
            }

            //sun shaft;
            IsReady = await mSunShaftMobile.Init(rc, width, height);

            if (IsReady == false)
            {
                System.Diagnostics.Debug.Assert(false);
                return(false);
            }

            //mobile ao;
            IsReady = await mMobileAO.Init(rc, width, height, BaseSceneView);

            if (IsReady == false)
            {
                System.Diagnostics.Debug.Assert(false);
                return(false);
            }

            //
            mOpaqueSE.mTex_ShadowMap = mCSM.mShadowMapView.FrameBuffer.GetSRV_DepthStencil();
            mOpaqueSE.EnvMapName     = CEngine.Instance.Desc.DefaultEnvMap;
            mOpaqueSE.EyeEnvMapName  = CEngine.Instance.Desc.DefaultEnvMap;

            mCustomTranslucentSE.EnvMapName     = CEngine.Instance.Desc.DefaultEnvMap;
            mCustomTranslucentSE.mTex_ShadowMap = mCSM.mShadowMapView.FrameBuffer.GetSRV_DepthStencil();

            mTranslucentSE.EnvMapName = CEngine.Instance.Desc.DefaultEnvMap;

            mCopyEditorSE.mBaseSceneView = BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0);
            mCopyEditorSE.mBloomTex      = mBloomMobile.mUSView8.FrameBuffer.GetSRV_RenderTarget(0);
            mCopyEditorSE.mPickedTex     = mPickedEffect.mSV_PickedBlurH.FrameBuffer.GetSRV_RenderTarget(0);
            mCopyEditorSE.VignetteTex    = CEngine.Instance.Desc.DefaultVignette;
            mCopyEditorSE.mSunShaftTex   = mSunShaftMobile.mView_Blur.FrameBuffer.GetSRV_RenderTarget(0);
            //mCopyEditorSE.mSRV_MobileAo = mMobileAO.mView_BlurV.FrameBuffer.GetSRV_RenderTarget(0);
            mCopyEditorSE.mSRV_MobileAo = mMobileAO.mView_AoMask.FrameBuffer.GetSRV_RenderTarget(0);

            {
                var DirLightColor     = new Vector4(1.0f, 1.0f, 1.0f, 3.5f);
                var DirLightDirection = new Vector3(0.0f, -1.5f, 1.0f);
                DirLightDirection.Normalize();

                var SkyLightColor = new Vector3(0.12f, 0.12f, 0.25f);

                BaseSceneView.mDirLightDirection_Leak = new Vector4(DirLightDirection, 0.05f);
                BaseSceneView.DirLightColor_Intensity = DirLightColor;
                BaseSceneView.mSkyLightColor          = SkyLightColor;

                var Tex2DDesc = mOpaqueSE.EnvMap.TxPicDesc;
                BaseSceneView.mEnvMapMipMaxLevel = Tex2DDesc.MipLevel - 1;

                Tex2DDesc = mOpaqueSE.mEyeEnvMap.TxPicDesc;
                BaseSceneView.mEyeEnvMapMaxMipLevel = Tex2DDesc.MipLevel - 1;

                var ViewportSizeAndRcp = new Vector4(width, height, 1.0f / width, 1.0f / height);
                BaseSceneView.mViewportSizeAndRcp = ViewportSizeAndRcp;
                mCopyPostprocessPass.mScreenView.ViewportSizeAndRcp = ViewportSizeAndRcp;
            }

            this.OnDrawUI += (CCommandList cmd, Graphics.View.CGfxScreenView view) =>
            {
                if (BaseSceneView.UIHost != null)
                {
                    BaseSceneView.UIHost.Draw(CEngine.Instance.RenderContext, cmd, view);
                }
            };

#if Test_Snapshot
            await TestSnapRender(rc);
#endif
            return(true);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public async System.Threading.Tasks.Task <bool> Init(UInt32 width, UInt32 height, CGfxCamera camera)
        {
            CGfxSceneViewInfo VI_PickedSetUp = new CGfxSceneViewInfo();

            VI_PickedSetUp.mUseDSV = true;
            UInt32 TempWidth  = width;
            UInt32 TempHeight = height;

            VI_PickedSetUp.Width  = TempWidth;
            VI_PickedSetUp.Height = TempHeight;
            VI_PickedSetUp.mDSVDesc.Init();
            VI_PickedSetUp.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D24_UNORM_S8_UINT;
            VI_PickedSetUp.mDSVDesc.Width  = TempWidth;
            VI_PickedSetUp.mDSVDesc.Height = TempHeight;

            CRenderTargetViewDesc RTVDesc_PickeSetUp = new CRenderTargetViewDesc();

            RTVDesc_PickeSetUp.Init();
            RTVDesc_PickeSetUp.Format = EPixelFormat.PXF_R16G16_FLOAT;
            RTVDesc_PickeSetUp.Width  = TempWidth;
            RTVDesc_PickeSetUp.Height = TempHeight;
            VI_PickedSetUp.mRTVDescArray.Add(RTVDesc_PickeSetUp);

            mSV_PickedSetUp = new CGfxSceneView();
            if (false == mSV_PickedSetUp.Init(mRHICtx, null, VI_PickedSetUp))
            {
                return(false);
            }

            mSE_PickedSetUp  = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxPickedSetUpSE>();
            mSE_PickedBlurH  = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxPickedBlurHSE>();
            mSE_PickedBlurV  = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxPickedBlurVSE>();
            mSE_PickedHollow = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxPickedHollowSE>();
            mBlurAndHollowSEArray.Add(mSE_PickedBlurH);
            mBlurAndHollowSEArray.Add(mSE_PickedHollow);

            var ScreenAlignedTriangle = CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(mRHICtx, CEngineDesc.ScreenAlignedTriangleName, true);
            var DefaultMtlInst        = await CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(mRHICtx, RName.GetRName("Material/defaultmaterial.instmtl"));

            mScreenAlignedTriangle = CEngine.Instance.MeshManager.CreateMesh(mRHICtx, ScreenAlignedTriangle);
            mScreenAlignedTriangle.SetMaterialInstance(mRHICtx, 0, DefaultMtlInst, CEngine.Instance.PrebuildPassData.DefaultShadingEnvs);
            //await mScreenAlignedTriangle.AwaitEffects();

            //blur h and hollow;
            {
                CGfxScreenViewDesc VI_BlurH = new CGfxScreenViewDesc();
                VI_BlurH.UseDepthStencilView = false;
                VI_BlurH.Width  = TempWidth;
                VI_BlurH.Height = TempHeight;

                var RTVDesc_BlurH = new CRenderTargetViewDesc();
                RTVDesc_BlurH.Init();
                RTVDesc_BlurH.Format = EPixelFormat.PXF_R16G16_FLOAT;
                VI_BlurH.mRTVDescArray.Add(RTVDesc_BlurH);
                mSV_PickedBlurH = new CGfxScreenView();
                if (await mSV_PickedBlurH.InitForMultiPassMode(mRHICtx, VI_BlurH, mBlurAndHollowSEArray, DefaultMtlInst, mScreenAlignedTriangle) == false)
                {
                    return(false);
                }
            }

            //blur v;
            {
                CGfxScreenViewDesc VI_BlurV = new CGfxScreenViewDesc();
                VI_BlurV.UseDepthStencilView = false;
                VI_BlurV.Width  = TempWidth;
                VI_BlurV.Height = TempHeight;

                var RTVDesc_BlurV = new CRenderTargetViewDesc();
                RTVDesc_BlurV.Init();
                RTVDesc_BlurV.Format = EPixelFormat.PXF_R16G16_FLOAT;
                VI_BlurV.mRTVDescArray.Add(RTVDesc_BlurV);
                mSV_PickedBlurV = new CGfxScreenView();
                if (await mSV_PickedBlurV.Init(mRHICtx, null, VI_BlurV, mSE_PickedBlurV, DefaultMtlInst, mScreenAlignedTriangle) == false)
                {
                    return(false);
                }
            }

            mCamera = camera;

            mRenderPassDesc_Picked = new CRenderPassDesc();
            FrameBufferClearColor TempClearColor = new FrameBufferClearColor();

            TempClearColor.r = 0.0f;
            TempClearColor.g = 1.0f;
            TempClearColor.b = 0.0f;
            TempClearColor.a = 0.0f;
            mRenderPassDesc_Picked.mFBLoadAction_Color    = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Picked.mFBStoreAction_Color   = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Picked.mFBClearColorRT0       = TempClearColor;
            mRenderPassDesc_Picked.mFBLoadAction_Depth    = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Picked.mFBStoreAction_Depth   = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Picked.mDepthClearValue       = 1.0f;
            mRenderPassDesc_Picked.mFBLoadAction_Stencil  = FrameBufferLoadAction.LoadActionClear;
            mRenderPassDesc_Picked.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore;
            mRenderPassDesc_Picked.mStencilClearValue     = 0u;

            mSE_PickedBlurH.mSRV_PickedSetUp  = mSV_PickedSetUp.FrameBuffer.GetSRV_RenderTarget(0);
            mSE_PickedBlurV.mSRV_PickedBlurH  = mSV_PickedBlurH.FrameBuffer.GetSRV_RenderTarget(0);
            mSE_PickedHollow.mSRV_PickedSetUp = mSV_PickedSetUp.FrameBuffer.GetSRV_RenderTarget(0);
            mSE_PickedHollow.mSRV_PickedBlur  = mSV_PickedBlurV.FrameBuffer.GetSRV_RenderTarget(0);

            var ViewportSizeAndRcp = new Vector4(TempWidth, TempHeight, 1.0f / TempWidth, 1.0f / TempHeight);

            mSV_PickedBlurH.ViewportSizeAndRcp = ViewportSizeAndRcp;
            mSV_PickedBlurV.ViewportSizeAndRcp = ViewportSizeAndRcp;

            return(true);
        }