private void UpdateCBMeshbatch(EngineNS.CCommandList cmd, Graphics.CGfxCamera Camera) { var varIdx = mCBMeshBatch.FindVar("ClusterNumber"); mCBMeshBatch.SetValue(varIdx, GpuClusters.Count, 0); varIdx = mCBMeshBatch.FindVar("MeshBatchVertexStride"); mCBMeshBatch.SetValue(varIdx, AllVertices.Count, 0); if (Camera != null) { unsafe { varIdx = mCBMeshBatch.FindVar("GpuDrivenCameraPlanes"); var pPlanes = stackalloc Plane[6]; Camera.CullingFrustum.GetPlanes(pPlanes); for (uint i = 0; i < 6; i++) { mCBMeshBatch.SetValue(varIdx, pPlanes[i], i); } varIdx = mCBMeshBatch.FindVar("GpuDrivenCameraPosition"); mCBMeshBatch.SetValue(varIdx, Camera.CullingFrustum.TipPos, 0); BoundingBox box = new BoundingBox(); Camera.CullingFrustum.GetBoundBox(ref box); varIdx = mCBMeshBatch.FindVar("GpuDrivenFrustumMinPoint"); mCBMeshBatch.SetValue(varIdx, box.Minimum, 0); varIdx = mCBMeshBatch.FindVar("GpuDrivenFrustumMaxPoint"); mCBMeshBatch.SetValue(varIdx, box.Maximum, 0); varIdx = mCBMeshBatch.FindVar("EnableGpuCulling"); mCBMeshBatch.SetValue(varIdx, (uint)(1), 0); } } else { varIdx = mCBMeshBatch.FindVar("EnableGpuCulling"); mCBMeshBatch.SetValue(varIdx, (uint)(0), 0); } }
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)); }