Esempio n. 1
0
        public void Initialize(Device device, int resolutionX, int resolutionY)
        {
            m_BokehSpriteTexture = Texture2D.FromFile(device, "textures\\bokeh.dds");
            m_BokehSpriteTextureSRV = new ShaderResourceView(device, m_BokehSpriteTexture);

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

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

            m_NumQuads = resolutionX * resolutionY / 4;
        }
Esempio n. 2
0
        public void Initialize(Device device, int resolutionX, int resolutionY)
        {
            m_BokehSpriteTexture    = Texture2D.FromFile(device, "textures\\bokeh.dds");
            m_BokehSpriteTextureSRV = new ShaderResourceView(device, m_BokehSpriteTexture);

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

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

            m_NumQuads = resolutionX * resolutionY / 4;
        }
Esempio n. 3
0
        public SSReflectionsEffectPass(SlimDX.Direct3D11.Device device, int resolutionX, int resolutionY)
        {
            m_ResultsRTDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R16G16B16A16_Float,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };

            TemporalSurfaceManager.InitializeRenderTarget("SSReflections", m_ResultsRTDescriptor);
        }
Esempio n. 4
0
        public SSReflectionsEffectPass(SlimDX.Direct3D11.Device device, int resolutionX, int resolutionY)
        {
            m_ResultsRTDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R16G16B16A16_Float,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY,
                m_Width = resolutionX
            };

            TemporalSurfaceManager.InitializeRenderTarget("SSReflections", m_ResultsRTDescriptor);
        }
        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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public SSAOEffectPass(SlimDX.Direct3D11.Device device, int resolutionX, int resolutionY)
        {
            m_RTDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R8G8B8A8_UNorm,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };

            TemporalSurfaceManager.InitializeRenderTarget("SSAO", m_RTDescriptor);

            m_SSAOBuffer = ShaderManager.CreateConstantBufferInstance("SSAOBuffer", device);
        }
Esempio n. 10
0
        public SSAOEffectPass(SlimDX.Direct3D11.Device device, int resolutionX, int resolutionY)
        {
            m_RTDescriptor = new RenderTargetSet.RenderTargetDescriptor()
                {
                    m_Format = Format.R8G8B8A8_UNorm,
                    m_HasDepth = false,
                    m_NumSurfaces = 1,
                    m_Height = resolutionY,
                    m_Width = resolutionX
                };

            TemporalSurfaceManager.InitializeRenderTarget("SSAO", m_RTDescriptor);

            m_SSAOBuffer = ShaderManager.CreateConstantBufferInstance("SSAOBuffer", device);
        }
Esempio n. 11
0
        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;
        }
Esempio n. 12
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);
            }
        }
Esempio n. 13
0
        public void Initialize(Device device, Form form, Panel panel, int resolutionX, int resolutionY)
        {
            m_ResolutionX = resolutionX;
            m_ResolutionY = resolutionY;

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

            m_FullResAndDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R16G16B16A16_Float,
                m_HasDepth = true,
                m_NumSurfaces = 1,
                m_Height = resolutionY,
                m_Width = resolutionX
            };

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

            m_LinearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R32_Float,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY,
                m_Width = resolutionX
            };
            m_SSAODescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R8_UNorm,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY,
                m_Width = resolutionX
            };

            m_SimpleSceneWrapper.Initialize(device, "sponza");

            TemporalSurfaceManager.InitializeRenderTarget("ResolvedColor", m_ResolvedColorDescriptor );

            TemporalSurfaceManager.InitializeRenderTarget("MotionVectors",
                new RenderTargetSet.RenderTargetDescriptor()
                {
                    m_Format = Format.R16G16_Float,
                    m_HasDepth = false,
                    m_NumSurfaces = 1,
                    m_Height = resolutionY,
                    m_Width = resolutionX
                });


            m_PostEffectsConstantBuffer = ShaderManager.CreateConstantBufferInstance("PostEffects", device);
            m_ForwardPassBuffer = ShaderManager.CreateConstantBufferInstance("ForwardPassBuffer", device);
            m_ViewportConstantBuffer = ShaderManager.CreateConstantBufferInstance("GlobalViewportBuffer", device);
            m_CurrentViewportBuffer = ShaderManager.CreateConstantBufferInstance("CurrentViewport", device);

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

            m_GIRenderer = new GlobalIlluminationRenderer(device, min, max);

            // Init passes
            m_ScatterDOFPass = new ScatterDOFPass();
            m_ScatterDOFPass.Initialize(device, resolutionX, resolutionY);

            m_ResolveHDRPass = new ResolveHDRPass();

            m_ResolveMotionVectorsPass = new ResolveMotionVectorsPass();

            m_ResolveTemporalPass = new ResolveTemporalMotionBasedPass();

            m_FxaaPass = new FxaaPass();

            m_SSAOPass = new SSAOEffectPass(device, resolutionX, resolutionY);

            m_LuminanceCalculations = new LuminanceCalculations(device, resolutionX, resolutionY);

            m_ShadowEVSMGenerator = new ShadowEVSMGenerator();

            m_VolumetricFog = new VolumetricFog();
            m_VolumetricFog.Initialize(device);

            m_StartTime = DateTime.Now;

            m_ViewportCamera.BindToInput(form, panel);

            POISSON_SAMPLES = new float[POISSON_SAMPLE_NUM * 2]
                {
                    0.655897408497f, 0.95575996511f, 
                    0.944576716895f, 0.455478901428f, 
                    0.203683172197f, 0.0177149729234f, 
                    0.383628747896f, 0.379284571357f, 
                    0.945473563065f, 0.779431977074f, 
                    0.570420562284f, 0.576156483093f, 
                    0.674354533289f, 0.286346887653f, 
                    0.347776132801f, 0.734938485879f, 
                };
        }
        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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public void Initialize(Device device, Form form, Panel panel, int resolutionX, int resolutionY)
        {
            m_ResolutionX = resolutionX;
            m_ResolutionY = resolutionY;

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

            m_FullResAndDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R16G16B16A16_Float,
                m_HasDepth    = true,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };

            m_ResolvedColorDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R8G8B8A8_UNorm,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };
            m_LinearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R32_Float,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };
            m_SSAODescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R8_UNorm,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };

            m_SimpleSceneWrapper.Initialize(device, "sponza");

            TemporalSurfaceManager.InitializeRenderTarget("ResolvedColor", m_ResolvedColorDescriptor);

            TemporalSurfaceManager.InitializeRenderTarget("MotionVectors",
                                                          new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R16G16_Float,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            });


            m_PostEffectsConstantBuffer = ShaderManager.CreateConstantBufferInstance("PostEffects", device);
            m_ForwardPassBuffer         = ShaderManager.CreateConstantBufferInstance("ForwardPassBuffer", device);
            m_ViewportConstantBuffer    = ShaderManager.CreateConstantBufferInstance("GlobalViewportBuffer", device);
            m_CurrentViewportBuffer     = ShaderManager.CreateConstantBufferInstance("CurrentViewport", device);

            Vector3 min, max;

            m_SimpleSceneWrapper.GetSceneBounds(out min, out max);

            m_GIRenderer = new GlobalIlluminationRenderer(device, min, max);

            // Init passes
            m_ScatterDOFPass = new ScatterDOFPass();
            m_ScatterDOFPass.Initialize(device, resolutionX, resolutionY);

            m_ResolveHDRPass = new ResolveHDRPass();

            m_ResolveMotionVectorsPass = new ResolveMotionVectorsPass();

            m_ResolveTemporalPass = new ResolveTemporalMotionBasedPass();

            m_FxaaPass = new FxaaPass();

            m_SSAOPass = new SSAOEffectPass(device, resolutionX, resolutionY);

            m_LuminanceCalculations = new LuminanceCalculations(device, resolutionX, resolutionY);

            m_ShadowEVSMGenerator = new ShadowEVSMGenerator();

            m_ViewportCamera.BindToInput(form, panel);
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
        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;
        }
Esempio n. 19
0
        public void Initialize(Device device, Form form, Panel panel, int resolutionX, int resolutionY)
        {
            m_ResolutionX = resolutionX;
            m_ResolutionY = resolutionY;

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

            m_FullResAndDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R16G16B16A16_Float,
                m_HasDepth    = true,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };

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

            m_LinearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R32_Float,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };
            m_SSAODescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R8_UNorm,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            };

            m_SimpleSceneWrapper.Initialize(device, "sponza");

            TemporalSurfaceManager.InitializeRenderTarget("ResolvedColor", m_ResolvedColorDescriptor);

            TemporalSurfaceManager.InitializeRenderTarget("MotionVectors",
                                                          new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = Format.R16G16_Float,
                m_HasDepth    = false,
                m_NumSurfaces = 1,
                m_Height      = resolutionY,
                m_Width       = resolutionX
            });


            m_PostEffectsConstantBuffer = ShaderManager.CreateConstantBufferInstance("PostEffects", device);
            m_ForwardPassBuffer         = ShaderManager.CreateConstantBufferInstance("ForwardPassBuffer", device);
            m_ViewportConstantBuffer    = ShaderManager.CreateConstantBufferInstance("GlobalViewportBuffer", device);
            m_CurrentViewportBuffer     = ShaderManager.CreateConstantBufferInstance("CurrentViewport", device);

            Vector3 min, max;

            m_SimpleSceneWrapper.GetSceneBounds(out min, out max);

            m_GIRenderer = new GlobalIlluminationRenderer(device, min, max);

            // Init passes
            m_ScatterDOFPass = new ScatterDOFPass();
            m_ScatterDOFPass.Initialize(device, resolutionX, resolutionY);

            m_ResolveHDRPass = new ResolveHDRPass();

            m_ResolveMotionVectorsPass = new ResolveMotionVectorsPass();

            m_ResolveTemporalPass = new ResolveTemporalMotionBasedPass();

            m_FxaaPass = new FxaaPass();

            m_SSAOPass = new SSAOEffectPass(device, resolutionX, resolutionY);

            m_LuminanceCalculations = new LuminanceCalculations(device, resolutionX, resolutionY);

            m_ShadowEVSMGenerator = new ShadowEVSMGenerator();

            m_VolumetricFog = new VolumetricFog();
            m_VolumetricFog.Initialize(device);

            m_StartTime = DateTime.Now;

            m_ViewportCamera.BindToInput(form, panel);

            POISSON_SAMPLES = new float[POISSON_SAMPLE_NUM * 2]
            {
                0.655897408497f, 0.95575996511f,
                0.944576716895f, 0.455478901428f,
                0.203683172197f, 0.0177149729234f,
                0.383628747896f, 0.379284571357f,
                0.945473563065f, 0.779431977074f,
                0.570420562284f, 0.576156483093f,
                0.674354533289f, 0.286346887653f,
                0.347776132801f, 0.734938485879f,
            };
        }