public CPass GetPass(PrebuildPassIndex index) { if (mPrebuildPassArray[(int)index] == null) { return(null); } return(mPrebuildPassArray[(int)index]); }
public void RefreshPassEffect(CRenderContext RHICtx, PrebuildPassIndex ppi) { var refPass = GetPass(ppi); if (refPass == null) { return; } refPass.Effect.Editor_RefreshEffect(RHICtx, false); refPass.PreUse(); }
public void SetRLayerParameter(View.ERenderLayer layer, PrebuildPassIndex passIndex, CGfxShadingEnv shadingEnv) { RLayerParameter parameter; if (mLayerParameter.TryGetValue(layer, out parameter) == false) { parameter = new RLayerParameter(); mLayerParameter.Add(layer, parameter); } parameter.Layer = layer; parameter.PassIndex = passIndex; parameter.ShadingEnv = shadingEnv; }
public void OnCookRenderData(Graphics.CGfxShadingEnv ShadingEnv, PrebuildPassIndex ppi) { //当CookSpecRenderLayerDataToPass调用后的回调,在这里保留一个可以以后做最后渲染数据的hack //如Effect if (this.ShadingEnv.EnvCode.Version != EnvCodeVersion) { var src = this.Effect.Desc; var desc = Graphics.CGfxEffectDesc.CreateDesc(src.MtlShaderPatch, src.MdfQueueShaderPatch, this.ShadingEnv.EnvCode); var effect = CEngine.Instance.EffectManager.GetEffect(CEngine.Instance.RenderContext, desc); EnvCodeVersion = this.ShadingEnv.EnvCode.Version; //await effect.AwaitLoad(); effect.PreUse((success) => { this.Effect = effect; }); } }
public void FillPassData(CRenderContext RHICtx, CPass refPass, CGfxEffect effect, PrebuildPassIndex ppi, bool flushVars = false) { refPass.Effect = effect; if (effect.CacheData.PerInstanceId != UInt32.MaxValue) { ReCreateCBuffer(RHICtx, effect, flushVars); } refPass.BindCBuffer(effect.ShaderProgram, effect.CacheData.PerInstanceId, CBuffer); MtlInst.BindTextures(refPass.ShaderResources, effect.ShaderProgram); refPass.BindShaderTextures(this); var tempSampler = new CShaderSamplers(); this.GetSamplerBinder(RHICtx, effect.ShaderProgram, tempSampler); refPass.ShaderSamplerBinder = tempSampler; var PrebuildPassData = CEngine.Instance.PrebuildPassData; if (ppi == PrebuildPassIndex.PPI_HitProxy || ppi == PrebuildPassIndex.PPI_SceneCapture) { switch (MtlInst.mRenderLayer) { case View.ERenderLayer.RL_Opaque: { refPass.RenderPipeline.RasterizerState = PrebuildPassData.mOpaqueRasterStat; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mOpaqueDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mOpaqueBlendStat; } break; case View.ERenderLayer.RL_Translucent: { refPass.RenderPipeline.RasterizerState = PrebuildPassData.mTranslucentRasterStat; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mTranslucentDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mOpaqueBlendStat; } break; case View.ERenderLayer.RL_CustomOpaque: case View.ERenderLayer.RL_CustomTranslucent: case View.ERenderLayer.RL_Gizmos: case View.ERenderLayer.RL_Sky: { refPass.RenderPipeline.RasterizerState = MtlInst.CustomRasterizerState; refPass.RenderPipeline.DepthStencilState = MtlInst.CustomDepthStencilState; refPass.RenderPipeline.BlendState = PrebuildPassData.mOpaqueBlendStat; } break; } } else if (ppi == PrebuildPassIndex.PPI_Snapshot) { switch (MtlInst.mRenderLayer) { case View.ERenderLayer.RL_Opaque: { refPass.RenderPipeline.RasterizerState = PrebuildPassData.mOpaqueRasterStat; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mOpaqueDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mOpaqueBlendStat; } break; case View.ERenderLayer.RL_Translucent: { refPass.RenderPipeline.RasterizerState = PrebuildPassData.mTranslucentRasterStat; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mTranslucentDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mSnapshotBlendStat; } break; case View.ERenderLayer.RL_CustomOpaque: case View.ERenderLayer.RL_CustomTranslucent: case View.ERenderLayer.RL_Gizmos: case View.ERenderLayer.RL_Sky: { refPass.RenderPipeline.RasterizerState = MtlInst.CustomRasterizerState; refPass.RenderPipeline.DepthStencilState = MtlInst.CustomDepthStencilState; refPass.RenderPipeline.BlendState = PrebuildPassData.mSnapshotBlendStat; } break; } } else if (ppi == PrebuildPassIndex.PPI_PickedEditor) { switch (MtlInst.mRenderLayer) { case View.ERenderLayer.RL_Opaque: { refPass.RenderPipeline.RasterizerState = PrebuildPassData.mOpaqueRasterStat; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mOpaqueDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mOpaqueBlendStat; } break; case View.ERenderLayer.RL_Translucent: { refPass.RenderPipeline.RasterizerState = PrebuildPassData.mTranslucentRasterStat; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mTranslucentDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mOpaqueBlendStat; } break; case View.ERenderLayer.RL_CustomOpaque: case View.ERenderLayer.RL_CustomTranslucent: case View.ERenderLayer.RL_Gizmos: case View.ERenderLayer.RL_Sky: { refPass.RenderPipeline.RasterizerState = MtlInst.CustomRasterizerState; refPass.RenderPipeline.DepthStencilState = MtlInst.CustomDepthStencilState; refPass.RenderPipeline.BlendState = PrebuildPassData.mOpaqueBlendStat; } break; } } else if (ppi == PrebuildPassIndex.PPI_SSM) { refPass.RenderPipeline.RasterizerState = MtlInst.mShadowRasterState; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mOpaqueDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mShadowBlendStat; } else { switch (MtlInst.mRenderLayer) { case View.ERenderLayer.RL_Shadow: { refPass.RenderPipeline.RasterizerState = MtlInst.mShadowRasterState; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mOpaqueDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mShadowBlendStat; } break; case View.ERenderLayer.RL_Opaque: { refPass.RenderPipeline.RasterizerState = PrebuildPassData.mOpaqueRasterStat; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mOpaqueDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mOpaqueBlendStat; } break; case View.ERenderLayer.RL_Translucent: { refPass.RenderPipeline.RasterizerState = PrebuildPassData.mTranslucentRasterStat; refPass.RenderPipeline.DepthStencilState = PrebuildPassData.mTranslucentDSStat; refPass.RenderPipeline.BlendState = PrebuildPassData.mTranslucentBlendStat; } break; case View.ERenderLayer.RL_CustomOpaque: case View.ERenderLayer.RL_CustomTranslucent: { refPass.RenderPipeline.RasterizerState = MtlInst.CustomRasterizerState; refPass.RenderPipeline.DepthStencilState = MtlInst.CustomDepthStencilState; refPass.RenderPipeline.BlendState = MtlInst.CustomBlendState; // PrebuildPassData.mOpaqueBlendStat; } break; case View.ERenderLayer.RL_Gizmos: case View.ERenderLayer.RL_Sky: { refPass.RenderPipeline.RasterizerState = MtlInst.CustomRasterizerState; refPass.RenderPipeline.DepthStencilState = MtlInst.CustomDepthStencilState; refPass.RenderPipeline.BlendState = MtlInst.CustomBlendState; } break; } } }
public void CookSpecRenderLayerDataToPass(CRenderContext RHICtx, ERenderLayer RenderLayer, CGfxCamera ViewerCamera, CGfxShadingEnv ShadingEnv, PrebuildPassIndex ppi) { ScopeCook2Pass.Begin(); if (ViewerCamera == null || RenderLayer == ERenderLayer.RL_Shadow) { return; } if (RenderLayer == ERenderLayer.RL_Num) { RenderLayer = ERenderLayer.RL_Num - 1; return; } var SpecRenderLayer = ViewerCamera.mSceneRenderLayer[(int)RenderLayer]; int Count = SpecRenderLayer.GetRenderLayerAtomNum(); for (uint idx = 0; idx < Count; idx++) { var MtlMesh = SpecRenderLayer.GetMtlMeshFromArray(idx); if (MtlMesh == null) { break; } var SceneMesh = MtlMesh.mRootSceneMesh; if (MtlMesh == null || SceneMesh == null) { Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"NullPtr here", ""); continue; } if (ppi == PrebuildPassIndex.PPI_HitProxy && SceneMesh.mMeshVars.mHitProxyId == 0) { continue; } if (ppi == PrebuildPassIndex.PPI_PickedEditor) { if (SceneMesh.mSelected == false) { continue; } } MtlMesh.UpdatePerMtlMeshCBuffer(RHICtx, ViewerCamera); CPass refPass = MtlMesh.GetPass(ppi); if (refPass == null) { continue; } if (false == refPass.PreUse()) { continue; } refPass.OnCookRenderData(ShadingEnv, ppi); switch (ppi) { case PrebuildPassIndex.PPI_PickedEditor: refPass.BindShaderTextures(MtlMesh); refPass.ShaderSamplerBinder = MtlMesh.GetSamplerBinder_PickedEditor(RHICtx, refPass.Effect.ShaderProgram); ShadingEnv.BindResources(SceneMesh, refPass); break; case PrebuildPassIndex.PPI_HitProxy: { refPass.BindShaderTextures(MtlMesh); refPass.ShaderSamplerBinder = MtlMesh.GetSamplerBinder_HitProxy(RHICtx, refPass.Effect.ShaderProgram); ShadingEnv.BindResources(SceneMesh, refPass); } break; case PrebuildPassIndex.PPI_SceneCapture: case PrebuildPassIndex.PPI_OpaquePbr: case PrebuildPassIndex.PPI_TransparentPbr: case PrebuildPassIndex.PPI_CustomTranslucentPbr: case PrebuildPassIndex.PPI_OpaquePbrEditor: case PrebuildPassIndex.PPI_CustomTranslucentPbrEditor: case PrebuildPassIndex.PPI_Gizmos: case PrebuildPassIndex.PPI_Snapshot: case PrebuildPassIndex.PPI_Sky: { refPass.BindShaderTextures(MtlMesh); //refPass.ShaderSamplerBinder = MtlMesh.GetSamplerBinder(RHICtx, refPass.Effect.ShaderProgram); ShadingEnv.BindResources(SceneMesh, refPass); //var sEnv = refPass.Effect.Desc.EnvShaderPatch; //sEnv.BindResources(SceneMesh, refPass); } break; default: break; } refPass.ViewPort = Viewport; #if DEBUG if (ViewerCamera.CBuffer == null) { System.Diagnostics.Debug.Assert(false); } #endif refPass.BindCBuffer(refPass.Effect.ShaderProgram, refPass.Effect.CacheData.CBID_Camera, ViewerCamera.CBuffer); refPass.BindCBuffer(refPass.Effect.ShaderProgram, refPass.Effect.CacheData.CBID_View, SceneViewCB); SceneMesh.MdfQueue.OnSetPassData(refPass, false); SendPassToCorrectRenderLayer(RenderLayer, refPass); } ScopeCook2Pass.End(); }