Exemplo n.º 1
0
        internal static unsafe void RunForwardPostprocess(IRtvBindable rt, IDsvBindable depthDsv, ISrvBindable depthSrv,
                                                          ref Matrix viewMatrix, ref Matrix projMatrix)
        {
            MyGpuProfiler.IC_BeginBlock("Postprocess");
            var viewMatrixT = Matrix.Transpose(viewMatrix);
            var projMatrixT = Matrix.Transpose(projMatrix);
            var mapping     = MyMapping.MapDiscard(RC, TransformConstants);

            mapping.WriteAndPosition(ref viewMatrixT);
            mapping.WriteAndPosition(ref projMatrixT);
            mapping.WriteAndPosition(ref MyRender11.Environment.Data.EnvironmentLight.SunLightDirection);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, TransformConstants);

            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            RC.SetRtv(rt);
            RC.PixelShader.SetSrv(0, depthSrv);
            MyFileTextureManager texManager = MyManagers.FileTextures;

            RC.PixelShader.SetSrv(MyCommon.SKYBOX_SLOT, texManager.GetTexture(MyRender11.Environment.Data.Skybox, MyFileTextureEnum.CUBEMAP, true));
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.Set(m_ps);

            MyScreenPass.DrawFullscreenQuad(new MyViewport(m_viewportSize, m_viewportSize));
            MyGpuProfiler.IC_EndBlock();

            var nearestAtmosphereId = MyAtmosphereRenderer.GetNearestAtmosphereId();

            if (nearestAtmosphereId != null)
            {
                MyGpuProfiler.IC_BeginBlock("Atmosphere");
                RC.PixelShader.SetSrv(0, depthSrv);
                var viewProj = viewMatrix * projMatrix;
                MyAtmosphereRenderer.RenderEnvProbe(MyRender11.Environment.Matrices.CameraPosition, ref viewProj, nearestAtmosphereId.Value);

                MyGpuProfiler.IC_EndBlock();
            }

            RC.SetRtv(null);
        }