示例#1
0
        public void ExecutePass(DeviceContext context, RenderTargetSet sourceSet)
        {
            PostEffectHelper.LinearizeDepth(context, m_LinearDepth, sourceSet);
            DebugManager.RegisterDebug(context, "LinearDepth", m_LinearDepth);

            using (new GpuProfilePoint(context, "DownsampleDepthNormals"))
            {
                m_LinearDepth.BindSRV(context, 0);
                sourceSet.BindSRV(context, 1);

                m_HalfLinearDepth.BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "DownsampleDepthNormals");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);
            }
            DebugManager.RegisterDebug(context, "HalfLinearDepth", m_HalfLinearDepth);
            DebugManager.RegisterDebug(context, "HalfNormals", m_HalfLinearDepth, 1);

            using (new GpuProfilePoint(context, "OutputBilateralOffsets"))
            {
                m_LinearDepth.BindSRV(context, 0);
                m_HalfLinearDepth.BindSRV(context, 2);

                m_BilateralUpsampleOffsets.BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "OutputBilateralOffsets");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);
            }

            DebugManager.RegisterDebug(context, "BilateralOffsets", m_BilateralUpsampleOffsets);
        }
示例#2
0
        public void ExecutePass(
            DeviceContext context,
            RenderTargetSet target,
            RenderTargetSet sourceCurrent,
            RenderTargetSet sourceHistory,
            RenderTargetSet motionVectors,
            RenderTargetSet motionVectorsPrevious,
            bool accumulateHistory = false)
        {
            using (new GpuProfilePoint(context, "ResolveTemporalMotionBased"))
            {
                sourceCurrent.BindSRV(context, 0);
                sourceHistory.BindSRV(context, 1);
                motionVectors.BindSRV(context, 2);
                motionVectorsPrevious.BindSRV(context, 3);

                target.BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, accumulateHistory ? "ResolveTemporalHistoryAccumulation" : "ResolveTemporalMotionBased");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);

                if (accumulateHistory)
                {
                    PostEffectHelper.Copy(context, sourceCurrent, target);
                }
            }
        }
        public static void Initialize(Device device, DeviceContext context)
        {
            // Create helper textures
            m_PermTexture       = RenderTargetSet.CreateRenderTargetSet(device, 256, 1, Format.R8_UNorm, 1, false);
            m_PermTexture2D     = RenderTargetSet.CreateRenderTargetSet(device, 256, 256, Format.R8G8B8A8_UNorm, 1, false);
            m_GradTexture       = RenderTargetSet.CreateRenderTargetSet(device, 16, 1, Format.R8G8B8A8_SNorm, 1, false);
            m_PermGradTexture   = RenderTargetSet.CreateRenderTargetSet(device, 256, 1, Format.R8G8B8A8_SNorm, 1, false);
            m_PermGrad4DTexture = RenderTargetSet.CreateRenderTargetSet(device, 256, 1, Format.R8G8B8A8_SNorm, 1, false);
            m_GradTexture4D     = RenderTargetSet.CreateRenderTargetSet(device, 32, 1, Format.R8G8B8A8_SNorm, 1, false);

            m_PermTexture.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "GeneratePermTexture");
            RenderTargetSet.BindNull(context);

            m_PermTexture2D.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "GeneratePermTexture2d");
            RenderTargetSet.BindNull(context);

            m_GradTexture.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "GenerateGradTexture");
            RenderTargetSet.BindNull(context);

            m_PermGradTexture.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "GeneratePermGradTexture");
            RenderTargetSet.BindNull(context);

            m_PermGrad4DTexture.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "GeneratePermGrad4dTexture");
            RenderTargetSet.BindNull(context);

            m_GradTexture4D.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "GenerateGradTexture4d");
            RenderTargetSet.BindNull(context);
        }
示例#4
0
        public void ExecutePass(DeviceContext context, SimpleSceneWrapper sceneWrapper, Vector3 position)
        {
            //using (new GpuProfilePoint(context, "CubemapRender"))
            {
                context.PixelShader.SetShaderResource(m_GIVolumeR.m_ShaderResourceView, 5);
                context.PixelShader.SetShaderResource(m_GIVolumeG.m_ShaderResourceView, 6);
                context.PixelShader.SetShaderResource(m_GIVolumeB.m_ShaderResourceView, 7);

                CubemapRenderHelper.RenderCubemap(context, m_CubeObject, m_CubeObjectDepth, sceneWrapper, position, 50.0f, false, new Color4(1.0f, 0.75f, 0.75f, 1.0f));
            }

            //using (new GpuProfilePoint(context, "InitSH"))
            {
                context.PixelShader.SetShaderResource(m_CubeObject.m_ShaderResourceView, 0);
                m_InitialSHSet.BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "GIInitSH");
                RenderTargetSet.BindNull(context);

                DownsamplePass(context, m_InitialSHSet, m_Downsampled16x16SHSetR, m_Downsampled16x16SHSetG, m_Downsampled16x16SHSetB);

                m_Downsampled16x16SHSetR.BindSRV(context, 0);
                m_Downsampled4x4SHSetR.BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4");
                RenderTargetSet.BindNull(context);

                m_Downsampled16x16SHSetG.BindSRV(context, 0);
                m_Downsampled4x4SHSetG.BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4");
                RenderTargetSet.BindNull(context);

                m_Downsampled16x16SHSetB.BindSRV(context, 0);
                m_Downsampled4x4SHSetB.BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4");
                RenderTargetSet.BindNull(context);

                Vector3 sceneMin, sceneMax;
                sceneWrapper.GetSceneBounds(out sceneMin, out sceneMax);
                Vector3 positionInVolume = position - sceneMin;
                positionInVolume.X = positionInVolume.X / (sceneMax.X - sceneMin.X);
                positionInVolume.Y = positionInVolume.Y / (sceneMax.Y - sceneMin.Y);
                positionInVolume.Z = positionInVolume.Z / (sceneMax.Z - sceneMin.Z);
                dynamic scb = m_GIConstantBuffer;
                scb.g_InjectPosition = new Vector4(new Vector3(positionInVolume.X * (float)(m_VolumeSizeX - 1), positionInVolume.Y * (float)(m_VolumeSizeY - 1), positionInVolume.Z * (float)(m_VolumeSizeZ - 1)), 0);
                m_GIConstantBuffer.CompileAndBind(context);

                m_Downsampled4x4SHSetR.BindSRV(context, 2);
                m_Downsampled4x4SHSetG.BindSRV(context, 3);
                m_Downsampled4x4SHSetB.BindSRV(context, 4);
                context.ComputeShader.SetUnorderedAccessView(m_GIVolumeR.m_UnorderedAccessView, 0);
                context.ComputeShader.SetUnorderedAccessView(m_GIVolumeG.m_UnorderedAccessView, 1);
                context.ComputeShader.SetUnorderedAccessView(m_GIVolumeB.m_UnorderedAccessView, 2);
                ShaderManager.ExecuteComputeForSize(context, 1, 1, 1, "InjectSHIntoVolume");

                ContextHelper.ClearCSContext(context);
            }
        }
 public static void CopyFrac(DeviceContext context, RenderTargetSet target, RenderTargetSet source, int rtNum = 0)
 {
     using (new GpuProfilePoint(context, "Copy"))
     {
         source.BindSRV(context, 0, rtNum);
         target.BindAsRenderTarget(context);
         PostEffectHelper.RenderFullscreenTriangle(context, "CopyFrac");
         RenderTargetSet.BindNull(context);
         ContextHelper.ClearSRVs(context);
     }
 }
示例#6
0
 public void ExecutePass(DeviceContext context, RenderTargetSet target, RenderTargetSet source)
 {
     using (new GpuProfilePoint(context, "ResolveMotionVectors"))
     {
         source.BindDepthAsSRV(context, 0);
         target.BindAsRenderTarget(context);
         PostEffectHelper.RenderFullscreenTriangle(context, "ResolveMotionVectors");
         RenderTargetSet.BindNull(context);
         ContextHelper.ClearSRVs(context);
     }
 }
 public static void LinearizeDepth(DeviceContext context, RenderTargetSet target, RenderTargetSet source)
 {
     using (new GpuProfilePoint(context, "LinearizeDepth"))
     {
         source.BindDepthAsSRV(context, 0);
         target.BindAsRenderTarget(context);
         PostEffectHelper.RenderFullscreenTriangle(context, "LinearizeDepth");
         RenderTargetSet.BindNull(context);
         ContextHelper.ClearSRVs(context);
     }
 }
 public static void Difference(DeviceContext context, RenderTargetSet target, RenderTargetSet source1, RenderTargetSet source2, int rtNum = 0)
 {
     using (new GpuProfilePoint(context, "Difference"))
     {
         source1.BindSRV(context, 0, rtNum);
         source2.BindSRV(context, 1, rtNum);
         target.BindAsRenderTarget(context);
         PostEffectHelper.RenderFullscreenTriangle(context, "Difference");
         RenderTargetSet.BindNull(context);
         ContextHelper.ClearSRVs(context);
     }
 }
示例#9
0
 public void ExecutePass(DeviceContext context, RenderTargetSet target, RenderTargetSet source, RenderTargetSet luminanceTexture)
 {
     using (new GpuProfilePoint(context, "HDR Resolve"))
     {
         source.BindSRV(context, 0);
         luminanceTexture.BindSRV(context, 1);
         target.BindAsRenderTarget(context);
         PostEffectHelper.RenderFullscreenTriangle(context, "ResolveHDR");
         RenderTargetSet.BindNull(context);
         ContextHelper.ClearSRVs(context);
     }
 }
示例#10
0
        public void ExecutePass(DeviceContext context, RenderTargetSet target, RenderTargetSet linearDepth, RenderTargetSet motionVectors)
        {
            RenderTargetSet ssaoCurrent = TemporalSurfaceManager.GetRenderTargetCurrent("SSAO");
            RenderTargetSet ssaoHistory = TemporalSurfaceManager.GetRenderTargetHistory("SSAO");

            RenderTargetSet tempBlurBuffer = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptor);

            Random rand = new Random();

            dynamic scb = m_SSAOBuffer;

            scb.g_SSAOPhase = (float)rand.NextDouble() * 3.1415f;
            m_SSAOBuffer.CompileAndBind(context);

            using (new GpuProfilePoint(context, "SSAO"))
            {
                using (new GpuProfilePoint(context, "SSAOCalculate"))
                {
                    linearDepth.BindSRV(context, 0);
                    ssaoHistory.BindSRV(context, 1);
                    motionVectors.BindSRV(context, 2);
                    ssaoCurrent.BindAsRenderTarget(context);
                    PostEffectHelper.RenderFullscreenTriangle(context, "SSAOCalculate");
                    RenderTargetSet.BindNull(context);
                    ContextHelper.ClearSRVs(context);
                }

                SurfaceDebugManager.RegisterDebug(context, "SSAOMain", ssaoCurrent);

                using (new GpuProfilePoint(context, "SSAOBlur"))
                {
                    ssaoCurrent.BindSRV(context, 1);
                    tempBlurBuffer.BindAsRenderTarget(context);
                    PostEffectHelper.RenderFullscreenTriangle(context, "SSAOBlurHorizontal");
                    RenderTargetSet.BindNull(context);
                    ContextHelper.ClearSRVs(context);

                    SurfaceDebugManager.RegisterDebug(context, "SSAOBlurH", tempBlurBuffer);

                    tempBlurBuffer.BindSRV(context, 1);
                    target.BindAsRenderTarget(context);
                    PostEffectHelper.RenderFullscreenTriangle(context, "SSAOBlurVertical");
                    RenderTargetSet.BindNull(context);
                    ContextHelper.ClearSRVs(context);

                    SurfaceDebugManager.RegisterDebug(context, "SSAOBlurV", target);
                }
            }

            RenderTargetManager.ReleaseRenderTargetToPool(tempBlurBuffer);
        }
示例#11
0
        public void ExecutePass(DeviceContext context, RenderTargetSet target, RenderTargetSet source, RenderTargetSet depthSource)
        {
            using (new GpuProfilePoint(context, "Bokeh DoF"))
            {
                RenderTargetSet halfResColorCoC = RenderTargetManager.RequestRenderTargetFromPool(m_HalfResDescriptor);
                RenderTargetSet bokehAccumulate = RenderTargetManager.RequestRenderTargetFromPool(m_HalfHeightDescriptor);

                using (new GpuProfilePoint(context, "Downsample"))
                {
                    source.BindSRV(context, 0);
                    depthSource.BindDepthAsSRV(context, 1);
                    halfResColorCoC.BindAsRenderTarget(context);
                    PostEffectHelper.RenderFullscreenTriangle(context, "DownsampleColorCoC");
                    ContextHelper.ClearSRVs(context);
                }

                using (new GpuProfilePoint(context, "Sprites"))
                {
                    bokehAccumulate.Clear(context, new Color4(0.0f, 0.0f, 0.0f, 0.0f));
                    bokehAccumulate.BindAsRenderTarget(context, false);
                    halfResColorCoC.BindSRV(context, 0);
                    context.PixelShader.SetShaderResource(m_BokehSpriteTextureSRV, 4);

                    context.VertexShader.Set(ShaderManager.GetVertexShader("VertexFullScreenDofGrid"));
                    context.PixelShader.Set(ShaderManager.GetPixelShader("BokehSprite"));

                    ContextHelper.SetBlendState(context, ContextHelper.BlendType.Additive);
                    PostEffectHelper.RenderFullscreenGrid(context, m_NumQuads);
                    ContextHelper.SetBlendState(context, ContextHelper.BlendType.None);
                    ContextHelper.ClearSRVs(context);
                }

                using (new GpuProfilePoint(context, "ResolveBokeh"))
                {
                    target.BindAsRenderTarget(context);
                    source.BindSRV(context, 0);
                    bokehAccumulate.BindSRV(context, 2);
                    halfResColorCoC.BindSRV(context, 3);
                    PostEffectHelper.RenderFullscreenTriangle(context, m_DebugBokeh ? "ResolveBokehDebug" : "ResolveBokeh");
                    ContextHelper.ClearSRVs(context);
                }

                RenderTargetManager.ReleaseRenderTargetToPool(halfResColorCoC);
                RenderTargetManager.ReleaseRenderTargetToPool(bokehAccumulate);

                RenderTargetSet.BindNull(context);
            }
        }
示例#12
0
        public void ExecutePass(DeviceContext context, RenderTargetSet linearDepth, RenderTargetSet motionVectors, RenderTargetSet surfaceNormals, RenderTargetSet sourceColor, Camera sceneCam, DepthOperationsPass depthOps)
        {
            RenderTargetSet ssrCurrent = TemporalSurfaceManager.GetRenderTargetCurrent("SSReflections");
            RenderTargetSet ssrHistory = TemporalSurfaceManager.GetRenderTargetHistory("SSReflections");
            RenderTargetSet traceRT    = RenderTargetManager.RequestRenderTargetFromPool(m_ResultsRTDescriptor);

            if (DebugManager.IsFeatureOn("SSReflections"))
            {
                using (new GpuProfilePoint(context, "SSReflections"))
                {
                    using (new GpuProfilePoint(context, "SSReflectionsRaytrace"))
                    {
                        context.PixelShader.SetShaderResource(PostEffectHelper.m_RandomNumbersBuffer.m_ShaderResourceView, 39);
                        linearDepth.BindSRV(context, 0);
                        surfaceNormals.BindSRV(context, 1);
                        sourceColor.BindSRV(context, 2);
                        motionVectors.BindSRV(context, 3);
                        traceRT.BindAsRenderTarget(context);
                        PostEffectHelper.RenderFullscreenTriangle(context, "SSReflectionsRaytrace");
                        RenderTargetSet.BindNull(context);
                        ContextHelper.ClearSRVs(context);
                    }

                    using (new GpuProfilePoint(context, "SSReflectionsBlur"))
                    {
                        linearDepth.BindSRV(context, 0);
                        surfaceNormals.BindSRV(context, 1);
                        traceRT.BindSRV(context, 2);
                        motionVectors.BindSRV(context, 3);
                        ssrHistory.BindSRV(context, 4);
                        ssrCurrent.BindAsRenderTarget(context);
                        PostEffectHelper.RenderFullscreenTriangle(context, "SSReflectionsBlur");
                        RenderTargetSet.BindNull(context);
                        ContextHelper.ClearSRVs(context);
                    }
                }
            }
            else
            {
                traceRT.Clear(context, new Color4(0.0f, 0.0f, 0.0f, 0.0f));
                ssrCurrent.Clear(context, new Color4(0.0f, 0.0f, 0.0f, 0.0f));
            }

            DebugManager.RegisterDebug(context, "SSRRaytrace", traceRT);
            DebugManager.RegisterDebug(context, "SSRBlur", ssrCurrent);

            RenderTargetManager.ReleaseRenderTargetToPool(traceRT);
        }
示例#13
0
        void DownsamplePass(DeviceContext context, RenderTargetSet inputSet, RenderTargetSet targetRSet, RenderTargetSet targetGSet, RenderTargetSet targetBSet)
        {
            inputSet.BindSRV(context, 0, 0);
            targetRSet.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4");
            RenderTargetSet.BindNull(context);

            inputSet.BindSRV(context, 0, 1);
            targetGSet.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4");
            RenderTargetSet.BindNull(context);

            inputSet.BindSRV(context, 0, 2);
            targetBSet.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4");
            RenderTargetSet.BindNull(context);
        }
        public static void GenerateCubemapMips(DeviceContext context, string shader, TextureObject targetTexture, TextureObject sourceTexture)
        {
            for (int m = 0; m < targetTexture.m_Mips; ++m)
            {
                for (int i = 0; i < 6; ++i)
                {
                    dynamic cdb = m_CubemapDownsampleBuffer;
                    cdb.g_Mip  = (float)m;
                    cdb.g_Face = i;
                    m_CubemapDownsampleBuffer.CompileAndBind(context);

                    RenderTargetSet.BindTextureAsRenderTarget(context, targetTexture.m_ArrayRenderTargetViews[m * 6 + i], null, targetTexture.m_Width >> m, targetTexture.m_Height >> m);
                    context.PixelShader.SetShaderResource(PostEffectHelper.m_RandomNumbersBuffer.m_ShaderResourceView, 39);
                    context.PixelShader.SetShaderResource(sourceTexture.m_ShaderResourceView, 0);
                    PostEffectHelper.RenderFullscreenTriangle(context, shader);
                    RenderTargetSet.BindNull(context);
                }
            }
        }
示例#15
0
        public static void Initialize(Device device, DeviceContext context)
        {
            // Create helper textures
            m_EnvLightingLUT   = RenderTargetSet.CreateRenderTargetSet(device, 128, 128, Format.R16G16_Float, 1, false);
            m_GGXLightingDLUT  = RenderTargetSet.CreateRenderTargetSet(device, 256, 128, Format.R16_Float, 1, false);
            m_GGXLightingFVLUT = RenderTargetSet.CreateRenderTargetSet(device, 256, 128, Format.R16G16_Float, 1, false);

            m_GGXLightingDLUT.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "GenerateGGXLightingDLUT");
            RenderTargetSet.BindNull(context);

            m_GGXLightingFVLUT.BindAsRenderTarget(context);
            PostEffectHelper.RenderFullscreenTriangle(context, "GenerateGGXLightingFVLUT");
            RenderTargetSet.BindNull(context);

            m_EnvLightingLUT.BindAsRenderTarget(context);
            context.PixelShader.SetShaderResource(PostEffectHelper.m_RandomNumbersBuffer.m_ShaderResourceView, 39);
            PostEffectHelper.RenderFullscreenTriangle(context, "GenerateEnvLightingLUT");
            RenderTargetSet.BindNull(context);
        }
示例#16
0
        public void RenderFrame(DeviceContext context, double timeElapsed, RenderTargetSet targetRT)
        {
            ShaderManager.BindSamplerStates(context);
            PerlinNoiseRenderHelper.BindTextures(context);
            RenderTargetSet currentFrameMainBuffer = RenderTargetManager.RequestRenderTargetFromPool(m_FullResAndDepthDescriptor);
            RenderTargetSet linearDepth            = RenderTargetManager.RequestRenderTargetFromPool(m_LinearDepthDescriptor);
            RenderTargetSet ssaoRT = RenderTargetManager.RequestRenderTargetFromPool(m_SSAODescriptor);

            if (!m_ShadowsInitialized)
            {
                m_ShadowCamera.m_CameraForward = new Vector3(-0.15f, -1.0f, 0.15f);
                m_ShadowCamera.m_CameraForward.Normalize();

                Vector3 min, max;
                m_SimpleSceneWrapper.GetSceneBounds(out min, out max);

                Vector3 sceneTop = (min + max) * 0.5f;
                sceneTop.Y = max.Y;

                m_ShadowCamera.m_OrthoZoomX = (max.X - min.X) * 0.7f; // some overlap
                m_ShadowCamera.m_OrthoZoomY = (max.Z - min.Z) * 0.7f;

                m_ShadowCamera.m_CameraPosition = sceneTop - m_ShadowCamera.m_CameraForward * 50.0f;
                m_ShadowCamera.m_CameraUp       = new Vector3(0, 0, 1);
            }

            CalculateAndUpdateConstantBuffer(context, timeElapsed);

            if (!m_ShadowsInitialized)
            {
                m_ResolvedShadow     = m_ShadowEVSMGenerator.RenderShadows(context, m_SimpleSceneWrapper);
                m_ShadowsInitialized = true;
            }

            if (false)
            {
                m_GIRenderer.PartialGIUpdate(context, m_SimpleSceneWrapper, m_ResolvedShadow);
            }

            m_CurrentViewportBuffer.Bind(context);

            using (new GpuProfilePoint(context, "DepthPrepass"))
            {
                // set the shaders
                context.VertexShader.Set(ShaderManager.GetVertexShader("VertexScene"));
                context.PixelShader.Set(ShaderManager.GetPixelShader("DepthNormalPrepass"));

                currentFrameMainBuffer.Clear(context, new Color4(1.0f, 1.0f, 1.0f, 1.5f), true);
                currentFrameMainBuffer.BindAsRenderTarget(context, true, false);
                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.DepthWriteCompare);

                // render triangles
                m_SimpleSceneWrapper.Render(context);

                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.NoDepth);

                RenderTargetSet.BindNull(context);
            }

            RenderTargetSet motionVectorsSurface         = TemporalSurfaceManager.GetRenderTargetCurrent("MotionVectors");
            RenderTargetSet motionVectorsSurfacePrevious = TemporalSurfaceManager.GetRenderTargetHistory("MotionVectors");

            m_ResolveMotionVectorsPass.ExecutePass(context, motionVectorsSurface, currentFrameMainBuffer);

            PostEffectHelper.LinearizeDepth(context, linearDepth, currentFrameMainBuffer);
            SurfaceDebugManager.RegisterDebug(context, "LinearDepth", linearDepth);
            m_SSAOPass.ExecutePass(context, ssaoRT, linearDepth, motionVectorsSurface);

            m_VolumetricFog.RenderVolumetricFog(context, m_ResolvedShadow.m_RenderTargets[0], m_GIRenderer);

            using (new GpuProfilePoint(context, "MainForwardRender"))
            {
                // set the shaders
                context.VertexShader.Set(ShaderManager.GetVertexShader("VertexScene"));
                context.PixelShader.Set(ShaderManager.GetPixelShader("PixelScene"));

                currentFrameMainBuffer.BindAsRenderTarget(context, true);

                m_ResolvedShadow.BindSRV(context, 0);
                ssaoRT.BindSRV(context, 1);

                context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeR.m_ShaderResourceView, 5);
                context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeG.m_ShaderResourceView, 6);
                context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeB.m_ShaderResourceView, 7);

                context.PixelShader.SetShaderResource(m_VolumetricFog.m_ScatteringTexture.m_ShaderResourceView, 8);

                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.DepthCompare);

                // render triangles
                m_SimpleSceneWrapper.Render(context);

                // render sky
                PostEffectHelper.RenderFullscreenTriangle(context, "Sky", true);

                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.NoDepth);

                RenderTargetSet.BindNull(context);
            }

            using (new GpuProfilePoint(context, "PostEffects"))
            {
                RenderTargetSet postEffectSurfacePong = RenderTargetManager.RequestRenderTargetFromPool(m_FullResDescriptor);

                RenderTargetSet source, dest;
                source = currentFrameMainBuffer;
                dest   = postEffectSurfacePong;

                dynamic ppcb = m_PostEffectsConstantBuffer;
                if (ppcb.g_DofCoCScale > 0.0f)
                {
                    m_ScatterDOFPass.ExecutePass(context, dest, currentFrameMainBuffer, currentFrameMainBuffer);

                    PostEffectHelper.Swap(ref source, ref dest);
                }

                RenderTargetSet luminanceTexture = m_LuminanceCalculations.ExecutePass(context, source);

                RenderTargetSet resolvedCurrent = TemporalSurfaceManager.GetRenderTargetCurrent("ResolvedColor");
                RenderTargetSet resolvedHistory = TemporalSurfaceManager.GetRenderTargetHistory("ResolvedColor");

                m_ResolveHDRPass.ExecutePass(context, resolvedCurrent, source, luminanceTexture);

                RenderTargetSet resolvedTemporal = RenderTargetManager.RequestRenderTargetFromPool(m_ResolvedColorDescriptor);
                m_ResolveTemporalPass.ExecutePass(context, resolvedTemporal, resolvedCurrent, resolvedHistory, motionVectorsSurface, motionVectorsSurfacePrevious, true);
                SurfaceDebugManager.RegisterDebug(context, "ResolvedNoFXAA", resolvedTemporal);
                m_FxaaPass.ExecutePass(context, targetRT, resolvedTemporal);

                RenderTargetManager.ReleaseRenderTargetToPool(resolvedTemporal);
                RenderTargetManager.ReleaseRenderTargetToPool(postEffectSurfacePong);
            }

            RenderTargetManager.ReleaseRenderTargetToPool(ssaoRT);
            RenderTargetManager.ReleaseRenderTargetToPool(linearDepth);
            RenderTargetManager.ReleaseRenderTargetToPool(currentFrameMainBuffer);
        }
        public RenderTargetSet RenderShadows(DeviceContext context, SimpleSceneWrapper simpleSceneWrapper)
        {
            RenderTargetSet.RenderTargetDescriptor evsmDescriptor =
                new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R32G32B32A32_Float,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = 1024,
                m_Width       = 1024
            };

            RenderTargetSet EVSMTexture = m_EVSMTexture == null?RenderTargetManager.RequestRenderTargetFromPool(evsmDescriptor) : m_EVSMTexture;

            {
                RenderTargetSet.RenderTargetDescriptor shadowMapDescriptor =
                    new RenderTargetSet.RenderTargetDescriptor()
                {
                    m_Format      = Format.Unknown,
                    m_HasDepth    = true,
                    m_NumSurfaces = 0,
                    m_Height      = 2048,
                    m_Width       = 2048
                };

                RenderTargetSet shadowBuffer = RenderTargetManager.RequestRenderTargetFromPool(shadowMapDescriptor);

                using (new GpuProfilePoint(context, "Shadowmap"))
                {
                    // set the shaders
                    context.VertexShader.Set(ShaderManager.GetVertexShader("VertexShadow"));
                    context.PixelShader.Set(null);

                    shadowBuffer.Clear(context, new Color4(), true);
                    shadowBuffer.BindAsRenderTarget(context, true);

                    ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.DepthWriteCompare);

                    // render triangles
                    simpleSceneWrapper.RenderNoMaterials(context);

                    RenderTargetSet.BindNull(context);
                }

                using (new GpuProfilePoint(context, "EVSM Resolve"))
                {
                    shadowBuffer.BindDepthAsSRV(context, 0);
                    EVSMTexture.BindAsRenderTarget(context);
                    PostEffectHelper.RenderFullscreenTriangle(context, "ReconstructEVSM");
                    RenderTargetSet.BindNull(context);
                    ContextHelper.ClearSRVs(context);
                }

                RenderTargetSet EVSMTextureTemp = RenderTargetManager.RequestRenderTargetFromPool(evsmDescriptor);

                using (new GpuProfilePoint(context, "EVSM Blur"))
                {
                    EVSMTexture.BindSRV(context, 1);
                    EVSMTextureTemp.BindAsRenderTarget(context);
                    PostEffectHelper.RenderFullscreenTriangle(context, "BlurEVSMHorizontal");
                    RenderTargetSet.BindNull(context);
                    ContextHelper.ClearSRVs(context);

                    EVSMTextureTemp.BindSRV(context, 1);
                    EVSMTexture.BindAsRenderTarget(context);
                    PostEffectHelper.RenderFullscreenTriangle(context, "BlurEVSMVertical");
                    RenderTargetSet.BindNull(context);
                    ContextHelper.ClearSRVs(context);
                }

                RenderTargetManager.ReleaseRenderTargetToPool(shadowBuffer);
                RenderTargetManager.ReleaseRenderTargetToPool(EVSMTextureTemp);
            }

            m_EVSMTexture = EVSMTexture;
            return(EVSMTexture);
        }
示例#18
0
        public RenderTargetSet ExecutePass(DeviceContext context, RenderTargetSet source)
        {
            RenderTargetSet[] luminanceTargets = new RenderTargetSet[6];
            luminanceTargets[0] = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptorLuminance4x4);
            luminanceTargets[1] = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptorLuminance16x16);
            luminanceTargets[2] = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptorLuminance32x32);
            luminanceTargets[3] = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptorLuminance64x64);
            luminanceTargets[4] = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptorLuminance128x128);
            luminanceTargets[5] = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptorLuminance256x256);

            using (new GpuProfilePoint(context, "Calculate luminance"))
            {
                source.BindSRV(context, 0);
                luminanceTargets[0].BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4CalculateLuminance");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);

                luminanceTargets[0].BindSRV(context, 0);
                luminanceTargets[1].BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4Luminance");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);

                luminanceTargets[1].BindSRV(context, 0);
                luminanceTargets[2].BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample2x2Luminance");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);


                luminanceTargets[2].BindSRV(context, 0);
                luminanceTargets[3].BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample2x2Luminance");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);

                luminanceTargets[3].BindSRV(context, 0);
                luminanceTargets[4].BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample2x2Luminance");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);

                luminanceTargets[4].BindSRV(context, 0);
                luminanceTargets[5].BindAsRenderTarget(context);
                PostEffectHelper.RenderFullscreenTriangle(context, "Downsample2x2Luminance");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);

                luminanceTargets[5].BindSRV(context, 0);
                context.ComputeShader.SetUnorderedAccessView(m_FinalLuminance.m_RenderTargets[0].m_UnorderedAccessView, 0);
                ShaderManager.ExecuteComputeForSize(context, 1, 1, 1, "FinalCalculateAverageLuminance");
                ContextHelper.ClearSRVs(context);
                ContextHelper.ClearCSContext(context);
            }

            foreach (var lt in luminanceTargets)
            {
                RenderTargetManager.ReleaseRenderTargetToPool(lt);
            }

            return(m_FinalLuminance);
        }
示例#19
0
        public void RenderFrame(DeviceContext context, double timeElapsed, RenderTargetSet targetRT)
        {
            ShaderManager.BindSamplerStates(context);
            PerlinNoiseRenderHelper.BindTextures(context);
            RenderTargetSet currentFrameMainBuffer = TemporalSurfaceManager.GetRenderTargetCurrent("SceneMainRender");
            RenderTargetSet ssaoRT      = RenderTargetManager.RequestRenderTargetFromPool(m_SSAODescriptor);
            bool            useTemporal = !DebugManager.m_DisabledTemporal;

            if (!m_ShadowsInitialized)
            {
                InitializeShadowmapAndCubemaps(context, timeElapsed);
            }

            CalculateAndUpdateConstantBuffer(context, timeElapsed);

            if (false)
            {
                m_GIRenderer.PartialGIUpdate(context, m_SimpleSceneWrapper, m_ResolvedShadow);
            }

            m_CurrentViewportBuffer.Bind(context);

            using (new GpuProfilePoint(context, "DepthPrepass"))
            {
                // set the shaders
                context.VertexShader.Set(ShaderManager.GetVertexShader("VertexScene"));
                context.PixelShader.Set(ShaderManager.GetPixelShader("DepthNormalPrepass"));

                currentFrameMainBuffer.Clear(context, new Color4(1.0f, 1.0f, 1.0f, 1.5f), true);
                currentFrameMainBuffer.BindAsRenderTarget(context, true, true);
                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.DepthWriteCompare);

                // render triangles
                m_SimpleSceneWrapper.Render(context);

                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.NoDepth);

                RenderTargetSet.BindNull(context);

                DebugManager.RegisterDebug(context, "NormalsPrepass", currentFrameMainBuffer);
            }

            RenderTargetSet motionVectorsSurface         = TemporalSurfaceManager.GetRenderTargetCurrent("MotionVectors");
            RenderTargetSet motionVectorsSurfacePrevious = TemporalSurfaceManager.GetRenderTargetHistory("MotionVectors");

            m_ResolveMotionVectorsPass.ExecutePass(context, motionVectorsSurface, currentFrameMainBuffer);
            DebugManager.RegisterDebug(context, "MotionVectors", motionVectorsSurface);

            m_DepthOperationsPass.ExecutePass(context, currentFrameMainBuffer);
            RenderTargetSet linearDepth = m_DepthOperationsPass.m_LinearDepth;

            m_SSAOPass.ExecutePass(context, ssaoRT, m_DepthOperationsPass.m_HalfLinearDepth, motionVectorsSurface, m_DepthOperationsPass.m_HalfNormals, m_DepthOperationsPass);
            m_SSReflectionsPass.ExecutePass(context, m_DepthOperationsPass.m_HalfLinearDepth, motionVectorsSurface, m_DepthOperationsPass.m_HalfNormals, TemporalSurfaceManager.GetRenderTargetHistory("SceneMainRender"), m_ViewportCamera, m_DepthOperationsPass);
            m_VolumetricFog.RenderVolumetricFog(context, m_ResolvedShadow.m_RenderTargets[0], m_GIRenderer);

            using (new GpuProfilePoint(context, "MainForwardRender"))
            {
                // set the shaders
                context.VertexShader.Set(ShaderManager.GetVertexShader("VertexScene"));
                context.PixelShader.Set(ShaderManager.GetPixelShader("PixelScene"));

                currentFrameMainBuffer.BindAsRenderTarget(context, true);

                m_ResolvedShadow.BindSRV(context, 0);
                ssaoRT.BindSRV(context, 1);
                TemporalSurfaceManager.GetRenderTargetCurrent("SSReflections").BindSRV(context, 2);
                m_DepthOperationsPass.m_BilateralUpsampleOffsets.BindSRV(context, 10);

                context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeR.m_ShaderResourceView, 5);
                context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeG.m_ShaderResourceView, 6);
                context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeB.m_ShaderResourceView, 7);

                context.PixelShader.SetShaderResource(m_VolumetricFog.m_ScatteringTexture.m_ShaderResourceView, 8);

                context.PixelShader.SetShaderResource(m_CubeObjectFiltered.m_ShaderResourceView, 11);

                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.DepthCompare);

                LightingLUTHelper.BindTextures(context);

                // render triangles
                m_SimpleSceneWrapper.Render(context);

                // render sky
                PostEffectHelper.RenderFullscreenTriangle(context, "Sky", true);

                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.NoDepth);

                RenderTargetSet.BindNull(context);
            }
            RenderTargetManager.ReleaseRenderTargetToPool(ssaoRT);

            using (new GpuProfilePoint(context, "PostEffects"))
            {
                RenderTargetSet postEffectSurfacePong = RenderTargetManager.RequestRenderTargetFromPool(m_FullResDescriptor);

                RenderTargetSet source, dest;
                source = currentFrameMainBuffer;
                dest   = postEffectSurfacePong;

                dynamic ppcb = m_PostEffectsConstantBuffer;
                if (ppcb.g_DofCoCScale > 0.0f)
                {
                    m_ScatterDOFPass.ExecutePass(context, dest, currentFrameMainBuffer, currentFrameMainBuffer);

                    PostEffectHelper.Swap(ref source, ref dest);
                }

                RenderTargetSet luminanceTexture = m_LuminanceCalculations.ExecutePass(context, source);

                RenderTargetSet resolvedCurrent = TemporalSurfaceManager.GetRenderTargetCurrent("ResolvedColor");
                RenderTargetSet resolvedHistory = TemporalSurfaceManager.GetRenderTargetHistory("ResolvedColor");

                m_ResolveHDRPass.ExecutePass(context, resolvedCurrent, source, luminanceTexture);
                DebugManager.RegisterDebug(context, "ResolvedNoTemporal", resolvedCurrent);

                RenderTargetSet resolvedTemporal    = RenderTargetManager.RequestRenderTargetFromPool(m_ResolvedColorDescriptor);
                RenderTargetSet finalResolvedTarget = resolvedCurrent;
                if (useTemporal)
                {
                    m_ResolveTemporalPass.ExecutePass(context, resolvedTemporal, resolvedCurrent, resolvedHistory, motionVectorsSurface, motionVectorsSurfacePrevious, true);
                    finalResolvedTarget = resolvedTemporal;
                }

                DebugManager.RegisterDebug(context, "ResolvedNoFXAA", finalResolvedTarget);
                m_FxaaPass.ExecutePass(context, targetRT, finalResolvedTarget);

                RenderTargetManager.ReleaseRenderTargetToPool(resolvedTemporal);
                RenderTargetManager.ReleaseRenderTargetToPool(postEffectSurfacePong);
            }
        }
示例#20
0
        public void ExecutePass(DeviceContext context, RenderTargetSet target, RenderTargetSet linearDepth, RenderTargetSet motionVectors, RenderTargetSet surfaceNormals, DepthOperationsPass depthOps)
        {
            RenderTargetSet ssaoCurrent = TemporalSurfaceManager.GetRenderTargetCurrent("SSAO");
            RenderTargetSet ssaoHistory = TemporalSurfaceManager.GetRenderTargetHistory("SSAO");

            if (DebugManager.IsFeatureOn("SSAO"))
            {
                RenderTargetSet tempBlurBuffer = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptor);

                Random rand = new Random();

                dynamic scb = m_SSAOBuffer;
                scb.g_SSAOPhase = (float)rand.NextDouble() * 3.1415f;
                m_SSAOBuffer.CompileAndBind(context);

                using (new GpuProfilePoint(context, "SSAO"))
                {
                    using (new GpuProfilePoint(context, "SSAOCalculate"))
                    {
                        linearDepth.BindSRV(context, 0);
                        ssaoHistory.BindSRV(context, 1);
                        motionVectors.BindSRV(context, 2);
                        surfaceNormals.BindSRV(context, 3);
                        ssaoCurrent.BindAsRenderTarget(context);
                        PostEffectHelper.RenderFullscreenTriangle(context, "SSAOCalculate");
                        RenderTargetSet.BindNull(context);
                        ContextHelper.ClearSRVs(context);
                    }

                    DebugManager.RegisterDebug(context, "SSAOMain", ssaoCurrent);

                    using (new GpuProfilePoint(context, "SSAOBlur"))
                    {
                        ssaoCurrent.BindSRV(context, 1);
                        tempBlurBuffer.BindAsRenderTarget(context);
                        PostEffectHelper.RenderFullscreenTriangle(context, "SSAOBlurHorizontal");
                        RenderTargetSet.BindNull(context);
                        ContextHelper.ClearSRVs(context);

                        DebugManager.RegisterDebug(context, "SSAOBlurH", tempBlurBuffer);

                        tempBlurBuffer.BindSRV(context, 1);
                        target.BindAsRenderTarget(context);
                        PostEffectHelper.RenderFullscreenTriangle(context, "SSAOBlurVertical");
                        RenderTargetSet.BindNull(context);
                        ContextHelper.ClearSRVs(context);

                        DebugManager.RegisterDebug(context, "SSAOBlurV", target);
                    }
                }

                RenderTargetManager.ReleaseRenderTargetToPool(tempBlurBuffer);
            }
            else
            {
                target.Clear(context, new SlimDX.Color4(1.0f, 1.0f, 1.0f, 1.0f));
            }

            if (DebugManager.IsDebugging("UpsampledSSAO"))
            {
                RenderTargetSet tempFullResBuffer = RenderTargetManager.RequestRenderTargetFromPool(m_UpsampleDebugRTDescriptor);

                target.BindSRV(context, 0);
                depthOps.m_BilateralUpsampleOffsets.BindSRV(context, 10);
                tempFullResBuffer.BindAsRenderTarget(context);

                PostEffectHelper.RenderFullscreenTriangle(context, "BilateralUpsample");
                RenderTargetSet.BindNull(context);
                ContextHelper.ClearSRVs(context);

                DebugManager.RegisterDebug(context, "UpsampledSSAO", tempFullResBuffer);
                RenderTargetManager.ReleaseRenderTargetToPool(tempFullResBuffer);
            }
        }