Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public void RenderVolumetricFog(DeviceContext context, TextureObject shadowMap, GlobalIlluminationRenderer giRenderer)
        {
            // Not using temporal manager as it was designed for render target sets; TODO
            TextureObject previousFrameAccumulationTexture = m_Phase ? m_LightingTexturePing : m_LightingTexturePong;
            TextureObject currentFrameAccumulationTexture  = m_Phase ? m_LightingTexturePong : m_LightingTexturePing;

            m_Phase = !m_Phase;

            using (new GpuProfilePoint(context, "VolumetricFog"))
            {
#if false
                using (new GpuProfilePoint(context, "DensityEstimation"))
                {
                    context.ComputeShader.SetUnorderedAccessView(m_DensityTexture.m_UnorderedAccessView, 0);
                    ShaderManager.ExecuteComputeForResource(context, m_DensityTexture, "CalculateDensity");
                    ContextHelper.ClearCSContext(context);
                }
#endif

                using (new GpuProfilePoint(context, "LitFogVolume"))
                {
                    context.ComputeShader.SetShaderResource(giRenderer.m_GIVolumeR.m_ShaderResourceView, 5);
                    context.ComputeShader.SetShaderResource(giRenderer.m_GIVolumeG.m_ShaderResourceView, 6);
                    context.ComputeShader.SetShaderResource(giRenderer.m_GIVolumeB.m_ShaderResourceView, 7);

                    context.ComputeShader.SetShaderResource(previousFrameAccumulationTexture.m_ShaderResourceView, 8);

                    context.ComputeShader.SetShaderResource(m_DensityTexture.m_ShaderResourceView, 0);
                    context.ComputeShader.SetShaderResource(shadowMap.m_ShaderResourceView, 1);
                    context.ComputeShader.SetUnorderedAccessView(currentFrameAccumulationTexture.m_UnorderedAccessView, 1);
                    ShaderManager.ExecuteComputeForResource(context, currentFrameAccumulationTexture, "LitFogVolume");
                    ContextHelper.ClearCSContext(context);
                }

                using (new GpuProfilePoint(context, "ComputeScattering"))
                {
                    context.ComputeShader.SetShaderResource(currentFrameAccumulationTexture.m_ShaderResourceView, 0);
                    context.ComputeShader.SetUnorderedAccessView(m_ScatteringTexture.m_UnorderedAccessView, 2);
                    ShaderManager.ExecuteComputeForSize(context, m_VolumeX, m_VolumeY, 1, "ComputeScattering");
                    ContextHelper.ClearCSContext(context);
                }
            }
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        public SSAOEffectPass(SlimDX.Direct3D11.Device device, int resolutionX, int resolutionY)
        {
            m_RTDescriptor = new RenderTargetSet.RenderTargetDescriptor()
                {
                    m_Format = Format.R16G16_Float,
                    m_HasDepth = false,
                    m_NumSurfaces = 1,
                    m_Height = resolutionY,
                    m_Width = resolutionX
                };

            m_UpsampleDebugRTDescriptor = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = Format.R8_UNorm,
                m_HasDepth = false,
                m_NumSurfaces = 1,
                m_Height = resolutionY * 2,
                m_Width = resolutionX * 2
            };

            TemporalSurfaceManager.InitializeRenderTarget("SSAO", m_RTDescriptor);

            m_SSAOBuffer = ShaderManager.CreateConstantBufferInstance("SSAOBuffer", device);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 public static void RenderFullscreenTriangle(DeviceContext context, string pixelShader, bool maxZ = false)
 {
     context.InputAssembler.InputLayout       = null;
     context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
     context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding());
     context.InputAssembler.SetIndexBuffer(null, Format.Unknown, 0);
     context.VertexShader.Set(maxZ ? ShaderManager.GetVertexShader("VertexFullScreenTriangleMaxZ") : ShaderManager.GetVertexShader("VertexFullScreenTriangle"));
     context.PixelShader.Set(ShaderManager.GetPixelShader(pixelShader));
     context.Draw(3, 0);
 }
        public void Initialize(Device device, string sceneName)
        {
            m_ObjectLoader.Load(sceneName + ".obj");
            m_ObjectLoader.LoadMaterials(sceneName + ".mtl");

            m_MaterialsResources = new TexWrapper[m_ObjectLoader.m_MatTexMappingDiffuse.Count];
            int counter = 0;

            foreach (var v in m_ObjectLoader.m_MatTexMappingDiffuse)
            {
                TexWrapper tex   = new TexWrapper();
                bool       found = false;

                foreach (var t in m_MaterialsResources)
                {
                    if (t.textureName == v.Value)
                    {
                        tex.name          = v.Key;
                        tex.textureName   = v.Value;
                        tex.textureObject = t.textureObject;
                        tex.textureSrv    = t.textureSrv;

                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    tex.name        = v.Key;
                    tex.textureName = v.Value;

                    try
                    {
                        tex.textureObject = Texture2D.FromFile(device, v.Value);
                        tex.textureSrv    = new ShaderResourceView(device, tex.textureObject);
                    }
                    catch
                    {
                        tex.textureObject = null;
                        tex.textureSrv    = null;
                    }
                }

                m_MaterialsResources[counter++] = tex;
            }

            int numVertices = m_ObjectLoader.m_Vertices.Count;
            int numIndices  = m_ObjectLoader.m_Indices.Count;

            // create test vertex data, making sure to rewind the stream afterward
            var vertices = new DataStream(8 * sizeof(System.Single) * numVertices, true, true);

            foreach (var vertex in m_ObjectLoader.m_Vertices)
            {
                vertices.Write(new Vector3(vertex.x, vertex.y, vertex.z));
                Vector3 normal = new Vector3(vertex.nx, vertex.ny, vertex.nz);
                vertices.Write(normal);
                Vector2 uv = new Vector2(vertex.u, vertex.v);
                vertices.Write(uv);
            }
            vertices.Position = 0;

            var indices = new DataStream(sizeof(System.Int32) * numIndices, true, true);

            foreach (var index in m_ObjectLoader.m_Indices)
            {
                indices.Write(index);
            }
            indices.Position = 0;

            // create the vertex layout and buffer
            var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0) };

            m_SceneInputLayout = new InputLayout(device, ShaderManager.GetVertexShaderSignature("VertexScene"), elements);
            m_VertexBuffer     = new Buffer(device, vertices, 8 * sizeof(System.Single) * numVertices, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            m_IndexBuffer      = new Buffer(device, indices, 4 * numIndices, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
        }
Esempio n. 8
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,
            };
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        static void Main()
        {
            Device    device;
            SwapChain swapChain;

            //var form = new RenderForm("CSharpRenderer");
            var form  = new CSharpRendererMainForm();
            var panel = form.GetRenderingPanel();

            form.ClientSize = new System.Drawing.Size(ResolutionX, ResolutionY);

            var description = new SwapChainDescription()
            {
                BufferCount       = 2,
                Usage             = Usage.RenderTargetOutput,
                OutputHandle      = panel.Handle,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(ResolutionX, ResolutionY, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out device, out swapChain);
            var swapChainResource = Resource.FromSwapChain <Texture2D>(swapChain, 0);

            SamplerStates.Initialize(device);
            ShaderManager.Initialize(device);
            GPUProfiler.Initialize(device);
            ContextHelper.Initialize(device);
            RenderTargetManager.Initialize(device);
            PostEffectHelper.Initialize(device, ResolutionX, ResolutionY);
            CubemapRenderHelper.Initialize(device);

            Dictionary <CustomConstantBufferDefinition.ConstantBufferPropertyField, Tuple <TrackBar, TextBox> > propertyControlBindings =
                new Dictionary <CustomConstantBufferDefinition.ConstantBufferPropertyField, Tuple <TrackBar, TextBox> >();

            {
                TableLayoutPanel tableLayout = form.GetTableLayoutPanel();

                var contantBuffers = ShaderManager.GetConstantBufferDefinitions();

                int tableParamCounter = 1;
                foreach (var cb in contantBuffers)
                {
                    var paramProperties = cb.GetParamProperties();

                    if (paramProperties.Count > 0)
                    {
                        Label groupLabel = new Label();
                        groupLabel.Text        = cb.m_Name;
                        groupLabel.BorderStyle = BorderStyle.FixedSingle;
                        groupLabel.Anchor      = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                        tableLayout.Controls.Add(groupLabel, 0, tableParamCounter);
                        tableParamCounter++;

                        foreach (var param in paramProperties)
                        {
                            Label lb = new Label();
                            lb.Text   = param.name;
                            lb.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                            TextBox  text = new TextBox();
                            TrackBar tb   = new TrackBar();
                            tb.Size     = new System.Drawing.Size(400, 10);
                            tb.Anchor   = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                            tb.Minimum  = 0;
                            tb.Maximum  = 1024;
                            tb.Value    = (int)(((Single)param.paramValue - param.paramRangeMin) / (param.paramRangeMax - param.paramRangeMin) * 1024);
                            text.Text   = ((Single)param.paramValue).ToString();
                            text.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                            tableLayout.Controls.Add(lb, 0, tableParamCounter);
                            tableLayout.Controls.Add(tb, 1, tableParamCounter);
                            tableLayout.Controls.Add(text, 2, tableParamCounter);
                            propertyControlBindings.Add(param, new Tuple <TrackBar, TextBox>(tb, text));
                            tableParamCounter++;
                        }
                    }
                }
            }

            Scene scene = new Scene();

            scene.Initialize(device, form, panel, ResolutionX, ResolutionY);

            var resolvedRenderTarget = RenderTargetSet.CreateRenderTargetSet(device, ResolutionX, ResolutionY, Format.R8G8B8A8_UNorm, 1, false);

            RenderTargetSet.BindNull(device.ImmediateContext);

            // setting a viewport is required if you want to actually see anything
            var context = device.ImmediateContext;

            // prevent DXGI handling of alt+enter, which doesn't work properly with Winforms
            using (var factory = swapChain.GetParent <Factory>())
                factory.SetWindowAssociation(panel.Handle, WindowAssociationFlags.IgnoreAltEnter);

            int counter = 0;

            Dictionary <string, double> profilers;

            profilers = new Dictionary <String, double>();

            MessagePump.Run(form, () =>
            {
                TemporalSurfaceManager.UpdateTemporalSurfaces();
                ShaderManager.UpdateShaderManager(device);

                GPUProfiler.BeginFrameProfiling(context);
                scene.RenderFrame(context, 0.0f, resolvedRenderTarget);
                context.CopyResource(resolvedRenderTarget.m_RenderTargets[0].m_TextureObject2D, swapChainResource);
                GPUProfiler.EndFrameProfiling(context);
                swapChain.Present(0, PresentFlags.None);
                context.PixelShader.SetShaderResource(null, 0);

                if (GPUProfiler.m_CurrentFrameProfilerTree != null)
                {
                    Action <GPUProfiler.ProfilerTreeMember, String> processLevel = null;

                    processLevel = (GPUProfiler.ProfilerTreeMember treeMember, String level) =>
                    {
                        string finalName = level + treeMember.m_Name;

                        if (profilers.ContainsKey(finalName))
                        {
                            profilers[finalName] += treeMember.m_Time;
                        }
                        else
                        {
                            profilers.Add(finalName, treeMember.m_Time);
                        }

                        foreach (var v in treeMember.m_ChildMembers)
                        {
                            processLevel(v, level + "_");
                        }
                    };

                    processLevel(GPUProfiler.m_CurrentFrameProfilerTree, "");
                }

                if (++counter == 10)
                {
                    foreach (var propertyBinding in propertyControlBindings)
                    {
                        var property = propertyBinding.Key;
                        var trackBar = propertyBinding.Value.Item1;
                        var textBox  = propertyBinding.Value.Item2;

                        float rawVal = (float)trackBar.Value / 1024.0f;
                        if (property.isGamma)
                        {
                            rawVal = (float)Math.Pow((double)rawVal, 2.2);
                        }
                        float val           = rawVal * (property.paramRangeMax - property.paramRangeMin) + property.paramRangeMin;
                        property.paramValue = val;
                        textBox.Text        = val.ToString("F");
                    }

                    DataGridView dataGridView = form.GetDataGridView();
                    dataGridView.Rows.Clear();

                    foreach (var profilerEntry in profilers)
                    {
                        DataGridViewRow row = new DataGridViewRow();
                        row.CreateCells(dataGridView);
                        row.Cells[0].Value = profilerEntry.Key;
                        row.Cells[1].Value = String.Format("{0}", Math.Round(profilerEntry.Value * 100.0 / 10.0) / 100.0);
                        dataGridView.Rows.Add(row);
                    }

                    profilers.Clear();

                    counter = 0;
                }
                System.Threading.Thread.Sleep(15);
            });
        }
Esempio n. 11
0
        static void Main()
        {
            m_FrameNumber = 0;
            m_Time        = 0.0f;

            Device    device;
            SwapChain swapChain;

            //var form = new RenderForm("CSharpRenderer");
            var form  = new CSharpRendererMainForm();
            var panel = form.GetRenderingPanel();

            form.ClientSize = new System.Drawing.Size(ResolutionX, ResolutionY);

            var description = new SwapChainDescription()
            {
                BufferCount       = 2,
                Usage             = Usage.RenderTargetOutput,
                OutputHandle      = panel.Handle,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(ResolutionX, ResolutionY, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out device, out swapChain);
            var swapChainResource = Resource.FromSwapChain <Texture2D>(swapChain, 0);

            SamplerStates.Initialize(device);
            ShaderManager.Initialize(device);
            GPUProfiler.Initialize(device);
            ContextHelper.Initialize(device);
            RenderTargetManager.Initialize(device);
            PostEffectHelper.Initialize(device, ResolutionX, ResolutionY);
            CubemapRenderHelper.Initialize(device);
            PerlinNoiseRenderHelper.Initialize(device, device.ImmediateContext);
            LightingLUTHelper.Initialize(device, device.ImmediateContext);
            DebugManager.Initialize(device, ResolutionX, ResolutionY);

            InitializeControls(form);

            Scene scene = new Scene();

            scene.Initialize(device, form, panel, ResolutionX, ResolutionY);

            var resolvedRenderTarget = RenderTargetSet.CreateRenderTargetSet(device, ResolutionX, ResolutionY, Format.R8G8B8A8_UNorm, 1, false);

            RenderTargetSet.BindNull(device.ImmediateContext);

            // setting a viewport is required if you want to actually see anything
            var context = device.ImmediateContext;

            // prevent DXGI handling of alt+enter, which doesn't work properly with Winforms
            using (var factory = swapChain.GetParent <Factory>())
                factory.SetWindowAssociation(panel.Handle, WindowAssociationFlags.IgnoreAltEnter);

            int counter = 0;

            Dictionary <string, double> profilers;

            profilers = new Dictionary <String, double>();

            DateTime now = DateTime.Now;

            CustomConstantBufferInstance globalFrameConstantBuffer = ShaderManager.CreateConstantBufferInstance("GlobalFrameBuffer", device);

            MessagePump.Run(form, () =>
            {
                TemporalSurfaceManager.UpdateTemporalSurfaces();
                if (ShaderManager.UpdateShaderManager(device))
                {
                    InitializeControls(form);
                }

                GPUProfiler.BeginFrameProfiling(context);

                double timeDelta = (DateTime.Now - now).TotalMilliseconds;

                if (!form.GetFreezeTime())
                {
                    m_Time += timeDelta / 1000.0;
                    m_FrameNumber++;
                }

                UpdateGlobalConstantBuffer(context, globalFrameConstantBuffer, form);

                scene.RenderFrame(context, timeDelta, resolvedRenderTarget);
                now = DateTime.Now;
                DebugManager.PresentDebug(context, resolvedRenderTarget);
                context.CopyResource(resolvedRenderTarget.m_RenderTargets[0].m_TextureObject2D, swapChainResource);
                GPUProfiler.EndFrameProfiling(context);
                swapChain.Present(0, PresentFlags.None);
                context.PixelShader.SetShaderResource(null, 0);

                if (GPUProfiler.m_CurrentFrameProfilerTree != null)
                {
                    Action <GPUProfiler.ProfilerTreeMember, String> processLevel = null;

                    processLevel = (GPUProfiler.ProfilerTreeMember treeMember, String level) =>
                    {
                        string finalName = level + treeMember.m_Name;

                        if (profilers.ContainsKey(finalName))
                        {
                            profilers[finalName] += treeMember.m_Time;
                        }
                        else
                        {
                            profilers.Add(finalName, treeMember.m_Time);
                        }

                        foreach (var v in treeMember.m_ChildMembers)
                        {
                            processLevel(v, level + "_");
                        }
                    };

                    processLevel(GPUProfiler.m_CurrentFrameProfilerTree, "");
                }

                CheckAndUpdateDebugUI(context, form);

                if (++counter == 10)
                {
                    UpdateControls();
                    DataGridView dataGridView = form.GetDataGridView();
                    dataGridView.Rows.Clear();

                    foreach (var profilerEntry in profilers)
                    {
                        DataGridViewRow row = new DataGridViewRow();
                        row.CreateCells(dataGridView);
                        row.Cells[0].Value = profilerEntry.Key;
                        row.Cells[1].Value = String.Format("{0}", Math.Round(profilerEntry.Value * 100.0 / 10.0) / 100.0);
                        dataGridView.Rows.Add(row);
                    }

                    profilers.Clear();

                    counter = 0;
                }
                else
                {
                    // avoid 2ms frame times...
                    System.Threading.Thread.Sleep(10);
                }
            });
        }
Esempio n. 12
0
        private static void InitializeControls(CSharpRendererMainForm form)
        {
            Dictionary <String, int> oldValues = new Dictionary <String, int>();

            // record old values
            if (m_PropertyControlBindings != null)
            {
                foreach (var propertyBinding in m_PropertyControlBindings)
                {
                    oldValues.Add(propertyBinding.Key.name, propertyBinding.Value.Item1.Value);
                }
            }

            m_PropertyControlBindings = new Dictionary <CustomConstantBufferDefinition.ConstantBufferPropertyField, Tuple <TrackBar, TextBox> >();

            TableLayoutPanel tableLayout = form.GetTableLayoutPanel();

            tableLayout.Controls.Clear();
            var contantBuffers = ShaderManager.GetConstantBufferDefinitions();

            int tableParamCounter = 1;

            foreach (var cb in contantBuffers)
            {
                var paramProperties = cb.GetParamProperties();

                if (paramProperties.Count > 0)
                {
                    Label groupLabel = new Label();
                    groupLabel.Text        = cb.m_Name;
                    groupLabel.BorderStyle = BorderStyle.FixedSingle;
                    groupLabel.Anchor      = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                    tableLayout.Controls.Add(groupLabel, 0, tableParamCounter);
                    tableParamCounter++;

                    foreach (var param in paramProperties)
                    {
                        Label lb = new Label();
                        lb.Text   = param.name;
                        lb.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                        TextBox  text = new TextBox();
                        TrackBar tb   = new TrackBar();
                        tb.Size    = new System.Drawing.Size(400, 10);
                        tb.Anchor  = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                        tb.Minimum = 0;
                        tb.Maximum = 1024;

                        string key   = param.name;
                        int    value = (int)(((Single)param.paramValue - param.paramRangeMin) / (param.paramRangeMax - param.paramRangeMin) * 1024);
                        int    potentialOldVal;

                        if (oldValues.TryGetValue(key, out potentialOldVal))
                        {
                            value = potentialOldVal;
                        }

                        tb.Value    = value;
                        text.Text   = key;
                        text.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                        tableLayout.Controls.Add(lb, 0, tableParamCounter);
                        tableLayout.Controls.Add(tb, 1, tableParamCounter);
                        tableLayout.Controls.Add(text, 2, tableParamCounter);
                        m_PropertyControlBindings.Add(param, new Tuple <TrackBar, TextBox>(tb, text));
                        tableParamCounter++;
                    }
                }
            }
        }
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_ViewportCamera.BindToInput(form, panel);
        }
Esempio n. 14
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);
            }
        }
Esempio n. 15
0
 public static void Initialize(Device device)
 {
     m_CurrentViewportBuffer = ShaderManager.CreateConstantBufferInstance("CurrentViewport", device);
 }
Esempio n. 16
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 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);
        }