public async System.Threading.Tasks.Task <bool> InitForMultiPassMode(CRenderContext RHICtx, CGfxScreenViewDesc ViewInfo, List <CGfxShadingEnv> ShadingEnvArray, CGfxMaterialInstance MtlInst, CGfxMesh ViewportMesh) { if (ShadingEnvArray == null) { return(false); } if (ViewportMesh == null) { var RectMesh = CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(RHICtx, CEngineDesc.FullScreenRectName, true); ViewportMesh = CEngine.Instance.MeshManager.CreateMesh(RHICtx, RectMesh); ViewportMesh.SetMaterialInstance(RHICtx, 0, await CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(RHICtx, RName.GetRName("Material/defaultmaterial.instmtl")), CEngine.Instance.PrebuildPassData.DefaultShadingEnvs); //await ViewportMesh.AwaitEffects(); } mViewInfo = ViewInfo; mViewport = new CViewport(); mViewport.Width = ViewInfo.Width; mViewport.Height = ViewInfo.Height; mViewport.TopLeftX = 0.0f; mViewport.TopLeftY = 0.0f; mViewport.MinDepth = 0.0f; mViewport.MaxDepth = 1.0f; var ShaderProgram = CEngine.Instance.EffectManager.DefaultEffect.ShaderProgram; mScreenViewCB = RHICtx.CreateConstantBuffer(ShaderProgram, CEngine.Instance.EffectManager.DefaultEffect.CacheData.CBID_View); if (mScreenViewCB == null) { return(false); } mIDViewportSizeAndRcp = mScreenViewCB.FindVar("gViewportSizeAndRcp"); mID_SunPosNDC = mScreenViewCB.FindVar("gSunPosNDC"); mID_AoParam = mScreenViewCB.FindVar("gAoParam"); CRasterizerStateDesc RSDesc = new CRasterizerStateDesc(); RSDesc.InitForCustom(); mRasterState = CEngine.Instance.RasterizerStateManager.GetRasterizerState(RHICtx, RSDesc); CDepthStencilStateDesc DSSDesc = new CDepthStencilStateDesc(); DSSDesc.InitForCustomLayers(); mDepthStencilState = CEngine.Instance.DepthStencilStateManager.GetDepthStencilState(RHICtx, DSSDesc); CBlendStateDesc BlendDesc = new CBlendStateDesc(); BlendDesc.InitForCustomLayers(); mBlendState = CEngine.Instance.BlendStateManager.GetBlendState(RHICtx, BlendDesc); for (UInt32 idx = 0; idx < ShadingEnvArray.Count; idx++) { var refPass = RHICtx.CreatePass(); if (false == await refPass.InitPassForViewportView(RHICtx, ShadingEnvArray[(int)idx], MtlInst, ViewportMesh)) { return(false); } mPassArray.Add(refPass); } return(OnResize(RHICtx, null, ViewInfo.Width, ViewInfo.Height)); }
public async System.Threading.Tasks.Task <bool> Init(CRenderContext RHICtx, CSwapChain SwapChain, CGfxScreenViewDesc ViewInfo, CGfxShadingEnv ShadingEnv, CGfxMaterialInstance MtlInst, CGfxMesh ViewportMesh) { if (ShadingEnv == null) { return(false); } if (ViewportMesh == null) { var ScreenAlignedTriangle = CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(RHICtx, CEngineDesc.ScreenAlignedTriangleName, true); ViewportMesh = CEngine.Instance.MeshManager.CreateMesh(RHICtx, ScreenAlignedTriangle); ViewportMesh.SetMaterialInstance(RHICtx, 0, await CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(RHICtx, RName.GetRName("Material/defaultmaterial.instmtl")), CEngine.Instance.PrebuildPassData.DefaultShadingEnvs); //await ViewportMesh.AwaitEffects(); } mViewInfo = ViewInfo; mViewport = new CViewport(); mViewport.Width = ViewInfo.Width; mViewport.Height = ViewInfo.Height; mViewport.TopLeftX = 0.0f; mViewport.TopLeftY = 0.0f; mViewport.MinDepth = 0.0f; mViewport.MaxDepth = 1.0f; var ShaderProgram = CEngine.Instance.EffectManager.DefaultEffect.ShaderProgram; mScreenViewCB = RHICtx.CreateConstantBuffer(ShaderProgram, CEngine.Instance.EffectManager.DefaultEffect.CacheData.CBID_View); if (mScreenViewCB == null) { return(false); } mIDViewportSizeAndRcp = mScreenViewCB.FindVar("gViewportSizeAndRcp"); mID_SunPosNDC = mScreenViewCB.FindVar("gSunPosNDC"); mID_DirLightColor_Intensity = mScreenViewCB.FindVar("gDirLightColor_Intensity"); mID_AoParam = mScreenViewCB.FindVar("gAoParam"); CRasterizerStateDesc RSDesc = new CRasterizerStateDesc(); RSDesc.InitForCustom(); mRasterState = CEngine.Instance.RasterizerStateManager.GetRasterizerState(RHICtx, RSDesc); CDepthStencilStateDesc DSSDesc = new CDepthStencilStateDesc(); DSSDesc.InitForCustomLayers(); mDepthStencilState = CEngine.Instance.DepthStencilStateManager.GetDepthStencilState(RHICtx, DSSDesc); CBlendStateDesc BlendDesc = new CBlendStateDesc(); BlendDesc.InitForCustomLayers(); mBlendState = CEngine.Instance.BlendStateManager.GetBlendState(RHICtx, BlendDesc); mPass = RHICtx.CreatePass(); if (false == await mPass.InitPassForViewportView(RHICtx, ShadingEnv, MtlInst, ViewportMesh)) { return(false); } return(OnResize(RHICtx, SwapChain, ViewInfo.Width, ViewInfo.Height)); }