public static void PresentDebug(DeviceContext context, RenderTargetSet target)
 {
     if (m_CurrentDebugSurface != "None")
     {
         PostEffectHelper.Copy(context, target, m_DebugRenderTarget);
     }
 }
Example #2
0
        private void InitializeShadowmapAndCubemaps(DeviceContext context, double timeElapsed)
        {
            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);

            m_ResolvedShadow = m_ShadowEVSMGenerator.RenderShadows(context, m_SimpleSceneWrapper);

            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);
            m_ResolvedShadow.BindSRV(context, 0);

            CubemapRenderHelper.RenderCubemap(context, m_CubeObject, m_CubeDepthObject, m_SimpleSceneWrapper, m_ViewportCamera.m_CameraPosition, 256.0f, false, new Color4(1.0f, 1.0f, 1.0f, 1.5f));
            CubemapRenderHelper.GenerateCubemapMips(context, "PrefilterEnvLighting", m_CubeObjectFiltered, m_CubeObject);

            m_ShadowsInitialized = true;
        }
Example #3
0
 public static void RegisterDebug(DeviceContext context, string name, RenderTargetSet debuggedRT, int rtNum = 0)
 {
     if (m_AvailableModes.Contains(name))
     {
         if (m_CurrentDebugSurface == name)
         {
             if (m_CurrentDebugMode == "A")
             {
                 PostEffectHelper.CopyAlpha(context, m_DebugRenderTarget, debuggedRT, rtNum);
             }
             else if (m_CurrentDebugMode == "FRAC")
             {
                 PostEffectHelper.CopyFrac(context, m_DebugRenderTarget, debuggedRT, rtNum);
             }
             else if (m_CurrentDebugMode == "RGBGamma")
             {
                 PostEffectHelper.CopyGamma(context, m_DebugRenderTarget, debuggedRT, rtNum);
             }
             else
             {
                 PostEffectHelper.Copy(context, m_DebugRenderTarget, debuggedRT, rtNum);
             }
         }
     }
     else
     {
         m_IsUIRebuildRequired = true;
         m_AvailableModes.Add(name);
     }
 }
Example #4
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 RegisterDebug(DeviceContext context, string name, RenderTargetSet debuggedRT)
 {
     if (m_AvailableModes.Contains(name))
     {
         if (m_CurrentDebugSurface == name)
         {
             if (m_CurrentDebugMode == "A")
             {
                 PostEffectHelper.CopyAlpha(context, m_DebugRenderTarget, debuggedRT);
             }
             else if (m_CurrentDebugMode == "FRAC")
             {
                 PostEffectHelper.CopyFrac(context, m_DebugRenderTarget, debuggedRT);
             }
             else
             {
                 PostEffectHelper.Copy(context, m_DebugRenderTarget, debuggedRT);
             }
         }
     }
     else
     {
         m_IsUIRebuildRequired = true;
         m_AvailableModes.Add(name);
     }
 }
        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);
        }
        public GlobalIlluminationRenderer(Device device, Vector3 sceneBoundsMin, Vector3 sceneBoundsMax)
        {
            m_CubeObject      = TextureObject.CreateCubeTexture(device, 128, 128, 1, Format.R16G16B16A16_Float, false, true);
            m_CubeObjectDepth = TextureObject.CreateCubeTexture(device, 128, 128, 1, Format.R32_Typeless, true, true);

            if (System.IO.File.Exists("textures\\givolumer.dds"))
            {
                m_GIVolumeR = TextureObject.CreateTexture3DFromFile(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumer.dds");
                m_GIVolumeG = TextureObject.CreateTexture3DFromFile(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumeg.dds");
                m_GIVolumeB = TextureObject.CreateTexture3DFromFile(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumeb.dds");
            }
            else
            {
                m_GIVolumeR = TextureObject.CreateTexture3D(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float);
                m_GIVolumeG = TextureObject.CreateTexture3D(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float);
                m_GIVolumeB = TextureObject.CreateTexture3D(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float);
            }


            m_InitialSHSet = RenderTargetSet.CreateRenderTargetSet(device, 128, 128, Format.R16G16B16A16_Float, 3, false);

            m_Downsampled16x16SHSetR = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false);
            m_Downsampled16x16SHSetG = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false);
            m_Downsampled16x16SHSetB = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false);

            m_Downsampled4x4SHSetR = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false);
            m_Downsampled4x4SHSetG = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false);
            m_Downsampled4x4SHSetB = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false);

            m_GIConstantBuffer = ShaderManager.CreateConstantBufferInstance("GIConstantBuffer", device);

            m_SceneBoundsMin = sceneBoundsMin;
            m_SceneBoundsMax = sceneBoundsMax;
        }
Example #8
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 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);
        }
Example #10
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);
        }
        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);
        }
Example #12
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 ReleaseRenderTargetToPool(RenderTargetSet renderTargetSet)
        {
            var result = m_RenderTargets.Where(rt => (rt.m_Used == true) && (rt.m_RT == renderTargetSet));
            if(result.Count() != 1)
            {
                throw new Exception("Wrong release of render target set in render target manager");
            }

            result.First().m_Used = false;
        }
Example #14
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);
     }
 }
Example #15
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);
     }
 }
Example #17
0
        public static void ReleaseRenderTargetToPool(RenderTargetSet renderTargetSet)
        {
            var result = m_RenderTargets.Where(rt => (rt.m_Used == true) && (rt.m_RT == renderTargetSet));

            if (result.Count() != 1)
            {
                throw new Exception("Wrong release of render target set in render target manager");
            }

            result.First().m_Used = false;
        }
 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);
     }
 }
 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);
     }
 }
Example #20
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);
     }
 }
            public TemporalRenderTargetSetDescriptor(List<RenderTargetSet> sets)
            {
                m_RenderTargets = new RenderTargetSet[sets.Count];

                int count = 0;
                foreach( RenderTargetSet set in sets)
                {
                    m_RenderTargets[count++] = set;
                }

                m_Phase = 0;
            }
Example #22
0
        public static RenderTargetSet CreateRenderTargetSet(Device device, int width, int height, Format format, int numSurfaces, bool needsDepth)
        {
            RenderTargetSet rt = new RenderTargetSet();

            rt.m_Descriptor = new RenderTargetDescriptor()
            {
                m_Format      = format,
                m_HasDepth    = needsDepth,
                m_Height      = height,
                m_NumSurfaces = numSurfaces,
                m_Width       = width
            };

            rt.m_NumRTs = numSurfaces;
            for (int i = 0; i < numSurfaces; ++i)
            {
                rt.m_RenderTargets[i] = TextureObject.CreateTexture(device, width, height, 1, format, false, true);
            }

            if (needsDepth)
            {
                rt.m_DepthStencil = TextureObject.CreateTexture(device, width, height, 1, Format.R32_Typeless, true, false);
            }

            rt.m_Viewport = new Viewport(0, 0, width, height, 0.0f, 1.0f);

            if (m_DepthStencilState == null)
            {
                DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled   = true,
                    IsStencilEnabled = false,
                    DepthWriteMask   = DepthWriteMask.All,
                    DepthComparison  = Comparison.Less,
                };

                m_DepthStencilState = DepthStencilState.FromDescription(device, dsStateDesc);

                dsStateDesc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled   = false,
                    IsStencilEnabled = false,
                    DepthWriteMask   = DepthWriteMask.Zero,
                    DepthComparison  = Comparison.Always,
                };

                m_DepthStencilStateNoDepth = DepthStencilState.FromDescription(device, dsStateDesc);
            }


            return(rt);
        }
Example #23
0
            public TemporalRenderTargetSetDescriptor(List <RenderTargetSet> sets)
            {
                m_RenderTargets = new RenderTargetSet[sets.Count];

                int count = 0;

                foreach (RenderTargetSet set in sets)
                {
                    m_RenderTargets[count++] = set;
                }

                m_Phase = 0;
            }
Example #24
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);
        }
Example #25
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);
        }
        public static void Initialize(Device device, int resolutionX, int resolutionY)
        {
            RenderTargetSet.RenderTargetDescriptor rtDesc = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                m_HasDepth = false,
                m_Width = resolutionX,
                m_Height = resolutionY,
                m_NumSurfaces = 1,
            };

            m_DebugRenderTarget = RenderTargetManager.RequestRenderTargetFromPool(rtDesc);
            m_DebugAppendBuffer = GPUBufferObject.CreateBuffer(device, 1024, 8 * sizeof(uint), null, true, true);
        }
        public static void Initialize(Device device, int resolutionX, int resolutionY)
        {
            RenderTargetSet.RenderTargetDescriptor rtDesc = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                m_HasDepth    = false,
                m_Width       = resolutionX,
                m_Height      = resolutionY,
                m_NumSurfaces = 1,
            };

            m_DebugRenderTarget = RenderTargetManager.RequestRenderTargetFromPool(rtDesc);
            m_DebugAppendBuffer = GPUBufferObject.CreateBuffer(device, 1024, 8 * sizeof(uint), null, true, true);
        }
Example #28
0
        public DepthOperationsPass(int resolutionX, int resolutionY)
        {
            RenderTargetSet.RenderTargetDescriptor linearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R16_Float,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY,
                m_Width = resolutionX,
            };

            m_LinearDepth = RenderTargetManager.RequestRenderTargetFromPool(linearDepthDescriptor);

            RenderTargetSet.RenderTargetDescriptor halfLinearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R16_Float,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY / 2,
                m_Width = resolutionX / 2,
            };

            m_HalfLinearDepth = RenderTargetManager.RequestRenderTargetFromPool(halfLinearDepthDescriptor);

            RenderTargetSet.RenderTargetDescriptor normalsDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R8G8B8A8_UNorm,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY / 2,
                m_Width = resolutionX / 2,
            };

            m_HalfNormals = RenderTargetManager.RequestRenderTargetFromPool(normalsDescriptor);

            m_HalfLinearDepth.m_RenderTargets[1] = m_HalfNormals.m_RenderTargets[0];
            m_HalfLinearDepth.m_NumRTs++;

            RenderTargetSet.RenderTargetDescriptor bilateralUpsampleDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R8G8_SNorm,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY,
                m_Width = resolutionX,
            };

            m_BilateralUpsampleOffsets = RenderTargetManager.RequestRenderTargetFromPool(bilateralUpsampleDescriptor);
        }
Example #29
0
        public DepthOperationsPass(int resolutionX, int resolutionY)
        {
            RenderTargetSet.RenderTargetDescriptor linearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R16_Float,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX,
            };

            m_LinearDepth = RenderTargetManager.RequestRenderTargetFromPool(linearDepthDescriptor);

            RenderTargetSet.RenderTargetDescriptor halfLinearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R16_Float,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY / 2,
                m_Width       = resolutionX / 2,
            };

            m_HalfLinearDepth = RenderTargetManager.RequestRenderTargetFromPool(halfLinearDepthDescriptor);

            RenderTargetSet.RenderTargetDescriptor normalsDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R8G8B8A8_UNorm,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY / 2,
                m_Width       = resolutionX / 2,
            };

            m_HalfNormals = RenderTargetManager.RequestRenderTargetFromPool(normalsDescriptor);

            m_HalfLinearDepth.m_RenderTargets[1] = m_HalfNormals.m_RenderTargets[0];
            m_HalfLinearDepth.m_NumRTs++;

            RenderTargetSet.RenderTargetDescriptor bilateralUpsampleDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R8G8_SNorm,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX,
            };

            m_BilateralUpsampleOffsets = RenderTargetManager.RequestRenderTargetFromPool(bilateralUpsampleDescriptor);
        }
Example #30
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);
        }
Example #31
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);
            }
        }
Example #32
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);
            }
        }
Example #33
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);
        }
        public static void InitializeRenderTarget( string name, RenderTargetSet.RenderTargetDescriptor descriptor, int countHistory = 1)
        {
            if (m_TemporalRenderTargets.ContainsKey(name))
            {
                throw new Exception("Temporal surface with given name already exists");
            }

            List<RenderTargetSet> sets = new List<RenderTargetSet>();

            while (countHistory-- >= 0)
            {
                sets.Add(RenderTargetManager.RequestRenderTargetFromPool(descriptor));
            }
            TemporalRenderTargetSetDescriptor set = new TemporalRenderTargetSetDescriptor(sets);
            m_TemporalRenderTargets[name] = set;
        }
Example #35
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);
        }
        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);
                }
            }
        }
        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);
        }
Example #39
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);
        }
        public GlobalIlluminationRenderer(Device device, Vector3 sceneBoundsMin, Vector3 sceneBoundsMax)
        {
            m_VolumeSizeX = (int)ShaderManager.GetUIntShaderDefine("GI_VOLUME_RESOLUTION_X");
            m_VolumeSizeY = (int)ShaderManager.GetUIntShaderDefine("GI_VOLUME_RESOLUTION_Y");
            m_VolumeSizeZ = (int)ShaderManager.GetUIntShaderDefine("GI_VOLUME_RESOLUTION_Z");

            m_CubeObject      = TextureObject.CreateCubeTexture(device, 128, 128, 1, Format.R16G16B16A16_Float, false, true);
            m_CubeObjectDepth = TextureObject.CreateCubeTexture(device, 128, 128, 1, Format.R32_Typeless, true, true);

            if (System.IO.File.Exists("textures\\givolumer.dds"))
            {
                m_GIVolumeR = TextureObject.CreateTexture3DFromFile(device, m_VolumeSizeX, m_VolumeSizeY, m_VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumer.dds");
                m_GIVolumeG = TextureObject.CreateTexture3DFromFile(device, m_VolumeSizeX, m_VolumeSizeY, m_VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumeg.dds");
                m_GIVolumeB = TextureObject.CreateTexture3DFromFile(device, m_VolumeSizeX, m_VolumeSizeY, m_VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumeb.dds");
            }
            else
            {
                m_GIVolumeR = TextureObject.CreateTexture3D(device, m_VolumeSizeX, m_VolumeSizeY, m_VolumeSizeZ, Format.R16G16B16A16_Float);
                m_GIVolumeG = TextureObject.CreateTexture3D(device, m_VolumeSizeX, m_VolumeSizeY, m_VolumeSizeZ, Format.R16G16B16A16_Float);
                m_GIVolumeB = TextureObject.CreateTexture3D(device, m_VolumeSizeX, m_VolumeSizeY, m_VolumeSizeZ, Format.R16G16B16A16_Float);
            }
            

            m_InitialSHSet = RenderTargetSet.CreateRenderTargetSet(device, 128, 128, Format.R16G16B16A16_Float, 3, false);

            m_Downsampled16x16SHSetR = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false);
            m_Downsampled16x16SHSetG = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false);
            m_Downsampled16x16SHSetB = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false);

            m_Downsampled4x4SHSetR = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false);
            m_Downsampled4x4SHSetG = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false);
            m_Downsampled4x4SHSetB = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false);

            m_GIConstantBuffer = ShaderManager.CreateConstantBufferInstance("GIConstantBuffer", device);

            m_SceneBoundsMin = sceneBoundsMin;
            m_SceneBoundsMax = sceneBoundsMax;
        }
        public static RenderTargetSet RequestRenderTargetFromPool( RenderTargetSet.RenderTargetDescriptor descriptor )
        {
            var result = m_RenderTargets.Where(rt => (rt.m_Used == false) && (rt.m_Descriptor == descriptor) );
            if (result.Count() > 0)
            {
                var firstElement = result.First();
                firstElement.m_Used = true;
                return firstElement.m_RT;
            }
            else
            {
                RenderTargetSet rt = RenderTargetSet.CreateRenderTargetSet(m_Device, descriptor);
                RenderTargetContainer containter = new RenderTargetContainer()
                {
                    m_Descriptor = descriptor,
                    m_RT = rt,
                    m_Used = true,
                };
                m_RenderTargets.Add(containter);

                return rt;
            }
        }
Example #42
0
 public static void PresentDebug(DeviceContext context, RenderTargetSet target)
 {
     if (m_CurrentDebugSurface != "None")
     {
         PostEffectHelper.Copy(context, target, m_DebugRenderTarget);
     }
     if (m_TakeSnapshot)
     {
         PostEffectHelper.Copy(context, m_SnapshotRenderTarget, target);
         m_TakeSnapshot = false;
     }
     if (m_ShowSnapshot)
     {
         if (m_ShowSnapshotDifference)
         {
             PostEffectHelper.Copy(context, m_DebugRenderTarget, target);
             PostEffectHelper.Difference(context, target, m_SnapshotRenderTarget, m_DebugRenderTarget);
         }
         else
         {
             PostEffectHelper.Copy(context, target, m_SnapshotRenderTarget);
         }
     }
 }
Example #43
0
        public static RenderTargetSet RequestRenderTargetFromPool(RenderTargetSet.RenderTargetDescriptor descriptor)
        {
            var result = m_RenderTargets.Where(rt => (rt.m_Used == false) && (rt.m_Descriptor == descriptor));

            if (result.Count() > 0)
            {
                var firstElement = result.First();
                firstElement.m_Used = true;
                return(firstElement.m_RT);
            }
            else
            {
                RenderTargetSet       rt         = RenderTargetSet.CreateRenderTargetSet(m_Device, descriptor);
                RenderTargetContainer containter = new RenderTargetContainer()
                {
                    m_Descriptor = descriptor,
                    m_RT         = rt,
                    m_Used       = true,
                };
                m_RenderTargets.Add(containter);

                return(rt);
            }
        }
Example #44
0
 public static void PresentDebug(DeviceContext context, RenderTargetSet target)
 {
     if (m_CurrentDebugSurface != "None")
     {
         PostEffectHelper.Copy(context, target, m_DebugRenderTarget);
     }
     if (m_TakeSnapshot)
     {
         PostEffectHelper.Copy(context, m_SnapshotRenderTarget, target);
         m_TakeSnapshot = false;
     }
     if (m_ShowSnapshot)
     {
         if (m_ShowSnapshotDifference)
         {
             PostEffectHelper.Copy(context, m_DebugRenderTarget, target);
             PostEffectHelper.Difference(context, target, m_SnapshotRenderTarget, m_DebugRenderTarget);
         }
         else
         {
             PostEffectHelper.Copy(context, target, m_SnapshotRenderTarget);
         }
     }
 }
 public static void PresentDebug(DeviceContext context, RenderTargetSet target)
 {
     if (m_CurrentDebugSurface != "None")
     {
         PostEffectHelper.Copy(context, target, m_DebugRenderTarget);
     }
 }
Example #46
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);

        }
Example #47
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);
            }
        }
Example #48
0
        private void InitializeShadowmapAndCubemaps(DeviceContext context, double timeElapsed)
        {
            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);

            m_ResolvedShadow = m_ShadowEVSMGenerator.RenderShadows(context, m_SimpleSceneWrapper);

            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);
            m_ResolvedShadow.BindSRV(context, 0);

            CubemapRenderHelper.RenderCubemap(context, m_CubeObject, m_CubeDepthObject, m_SimpleSceneWrapper, m_ViewportCamera.m_CameraPosition, 256.0f, false, new Color4(1.0f, 1.0f, 1.0f, 1.5f));
            CubemapRenderHelper.GenerateCubemapMips(context, "PrefilterEnvLighting", m_CubeObjectFiltered, m_CubeObject);

            m_ShadowsInitialized = true;
        }
Example #49
0
        public LuminanceCalculations(SlimDX.Direct3D11.Device device, int resolutionX, int resolutionY)
        {
            Format luminanceFormat = Format.R16_Float;

            m_RTDescriptorLuminance4x4 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = luminanceFormat,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY / 4,
                m_Width       = resolutionX / 4
            };

            m_RTDescriptorLuminance16x16 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = luminanceFormat,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY / 16,
                m_Width       = resolutionX / 16
            };

            m_RTDescriptorLuminance32x32 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = luminanceFormat,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY / 32,
                m_Width       = resolutionX / 32
            };

            m_RTDescriptorLuminance64x64 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = luminanceFormat,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY / 64,
                m_Width       = resolutionX / 64
            };

            m_RTDescriptorLuminance128x128 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = luminanceFormat,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY / 128,
                m_Width       = resolutionX / 128
            };

            m_RTDescriptorLuminance256x256 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = luminanceFormat,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY / 256,
                m_Width       = resolutionX / 256
            };

            m_RTDescriptorFinalLuminance = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R32_Float, // to be able to read and write at the same time...
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = 1,
                m_Width       = 1
            };

            m_FinalLuminance = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptorFinalLuminance);
        }
        public void PartialGIUpdate(DeviceContext context, SimpleSceneWrapper sceneWrapper, RenderTargetSet resolvedShadow)
        {
            Vector3 min = m_SceneBoundsMin;
            Vector3 max = m_SceneBoundsMax;
            Vector3 bounds = m_SceneBoundsMax - m_SceneBoundsMin;

            for (int i = 0; i < 128; ++i)
            {
                Vector3 capturePosition = 
                    new Vector3((float)m_CurrentCellX / ((float)m_VolumeSizeX) * bounds.X + min.X, 
                                (float)m_CurrentCellY / ((float)m_VolumeSizeY) * bounds.Y + min.Y, 
                                (float)m_CurrentCellZ / ((float)m_VolumeSizeZ) * bounds.Z + min.Z);

                if (++m_CurrentCellX >= m_VolumeSizeX)
                {
                    m_CurrentCellX = 0;
                    if (++m_CurrentCellZ >= m_VolumeSizeZ)
                    {
                        m_CurrentCellZ = 0;
                        if (++m_CurrentCellY >= m_VolumeSizeY)
                        {
                            Texture3D.SaveTextureToFile(context, m_GIVolumeR.m_TextureObject3D, ImageFileFormat.Dds, "textures\\givolumer.dds");
                            Texture3D.SaveTextureToFile(context, m_GIVolumeG.m_TextureObject3D, ImageFileFormat.Dds, "textures\\givolumeg.dds");
                            Texture3D.SaveTextureToFile(context, m_GIVolumeB.m_TextureObject3D, ImageFileFormat.Dds, "textures\\givolumeb.dds");
                            m_CurrentCellY = 0;
                        }
                    }
                }

                resolvedShadow.BindSRV(context, 0);
                ExecutePass(context, sceneWrapper, capturePosition);
            }
        }
 public RenderTargetContainer()
 {
     m_RT = null;
     m_Used = false;
 }
Example #52
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);
        }
 public ShadowEVSMGenerator()
 {
     m_EVSMTexture = null;
 }
Example #54
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);
            }
        }
        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;
        }
Example #56
0
        public static void RenderCubemap(DeviceContext context, TextureObject targetTexture, TextureObject targetDepth, SimpleSceneWrapper sceneWrapper, Vector3 position, float range, bool depthOnly = false, Color4 clearColor = new Color4())
        {
            //using (new GpuProfilePoint(context, "CubemapRendering"))
            {
                // some hardcoded near plane
                Matrix projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 2.0f, 1.0f, 0.05f, range);

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

                // set the shaders
                context.VertexShader.Set(ShaderManager.GetVertexShader("VertexScene"));
                context.PixelShader.Set(depthOnly ? null : ShaderManager.GetPixelShader("PixelSceneSimple"));

                dynamic cvpb = m_CurrentViewportBuffer;

                for (int i = 0; i < 6; ++i)
                {
                    Vector3 lookAt = new Vector3();
                    Vector3 upVec  = new Vector3();

                    switch (i)
                    {
                    case 0:
                        lookAt = new Vector3(1.0f, 0.0f, 0.0f);
                        upVec  = new Vector3(0.0f, 1.0f, 0.0f);
                        break;

                    case 1:
                        lookAt = new Vector3(-1.0f, 0.0f, 0.0f);
                        upVec  = new Vector3(0.0f, 1.0f, 0.0f);
                        break;

                    case 2:
                        lookAt = new Vector3(0.0f, 1.0f, 0.0f);
                        upVec  = new Vector3(0.0f, 0.0f, -1.0f);
                        break;

                    case 3:
                        lookAt = new Vector3(0.0f, -1.0f, 0.0f);
                        upVec  = new Vector3(0.0f, 0.0f, 1.0f);
                        break;

                    case 4:
                        lookAt = new Vector3(0.0f, 0.0f, 1.0f);
                        upVec  = new Vector3(0.0f, 1.0f, 0.0f);
                        break;

                    case 5:
                        lookAt = new Vector3(0.0f, 0.0f, -1.0f);
                        upVec  = new Vector3(0.0f, 1.0f, 0.0f);
                        break;
                    }

                    Matrix viewMatrix = Matrix.LookAtLH(position, position + lookAt, upVec);

                    cvpb.g_ProjMatrix     = projectionMatrix;
                    cvpb.g_ViewMatrix     = viewMatrix;
                    cvpb.g_ViewProjMatrix = viewMatrix * projectionMatrix;

                    {
                        context.ClearRenderTargetView(targetTexture.m_ArrayRenderTargetViews[i], clearColor);
                        context.ClearDepthStencilView(targetDepth.m_ArrayDepthStencilViews[i], DepthStencilClearFlags.Depth, 1.0f, 0);

                        RenderTargetSet.BindTextureAsRenderTarget(context, targetTexture.m_ArrayRenderTargetViews[i], targetDepth.m_ArrayDepthStencilViews[i], targetTexture.m_Width, targetTexture.m_Height);

                        m_CurrentViewportBuffer.CompileAndBind(context);

                        // render triangles
                        sceneWrapper.Render(context);

                        RenderTargetSet.BindNull(context);
                    }
                }
                ContextHelper.SetDepthStencilState(context, ContextHelper.DepthConfigurationType.NoDepth);
            }
        }
        public LuminanceCalculations(SlimDX.Direct3D11.Device device, int resolutionX, int resolutionY)
        {
            Format luminanceFormat = Format.R16_Float;
            m_RTDescriptorLuminance4x4 = new RenderTargetSet.RenderTargetDescriptor()
                {
                    m_Format = luminanceFormat,
                    m_HasDepth = false,
                    m_NumSurfaces = 1,
                    m_Height = resolutionY / 4,
                    m_Width = resolutionX / 4
                };

            m_RTDescriptorLuminance16x16 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = luminanceFormat,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY / 16,
                m_Width = resolutionX / 16
            };

            m_RTDescriptorLuminance32x32 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = luminanceFormat,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY / 32,
                m_Width = resolutionX / 32
            };

            m_RTDescriptorLuminance64x64 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = luminanceFormat,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY / 64,
                m_Width = resolutionX / 64
            };

            m_RTDescriptorLuminance128x128 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = luminanceFormat,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY / 128,
                m_Width = resolutionX / 128
            };

            m_RTDescriptorLuminance256x256 = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = luminanceFormat,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY / 256,
                m_Width = resolutionX / 256
            };

            m_RTDescriptorFinalLuminance = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R32_Float, // to be able to read and write at the same time...
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = 1,
                m_Width = 1
            };

            m_FinalLuminance = RenderTargetManager.RequestRenderTargetFromPool(m_RTDescriptorFinalLuminance);
        }
        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;
        }
Example #59
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);
        }