Exemplo n.º 1
0
 public Scene()
 {
     m_ViewportCamera     = new Camera();
     m_ShadowCamera       = new Camera(true);
     m_SimpleSceneWrapper = new SimpleSceneWrapper();
     m_ShadowsInitialized = false;
 }
Exemplo n.º 2
0
        public void PartialGIUpdate(DeviceContext context, SimpleSceneWrapper sceneWrapper, RenderTargetSet resolvedShadow)
        {
            Vector3 min    = m_SceneBoundsMin;
            Vector3 max    = m_SceneBoundsMax;
            Vector3 bounds = m_SceneBoundsMax - m_SceneBoundsMin;

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

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

                resolvedShadow.BindSRV(context, 0);
                ExecutePass(context, sceneWrapper, capturePosition);
            }
        }
Exemplo n.º 3
0
 public Scene()
 {
     m_ViewportCamera = new Camera();
     m_ShadowCamera = new Camera(true);
     m_SimpleSceneWrapper = new SimpleSceneWrapper();
     m_ShadowsInitialized = false;
 }
Exemplo n.º 4
0
        public void ExecutePass(DeviceContext context, SimpleSceneWrapper sceneWrapper, Vector3 position)
        {
            //using (new GpuProfilePoint(context, "CubemapRender"))
            {
                context.PixelShader.SetShaderResource(m_GIVolumeR.m_ShaderResourceView, 5);
                context.PixelShader.SetShaderResource(m_GIVolumeG.m_ShaderResourceView, 6);
                context.PixelShader.SetShaderResource(m_GIVolumeB.m_ShaderResourceView, 7);

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

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

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

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

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

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

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

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

                ContextHelper.ClearCSContext(context);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        public void PartialGIUpdate(DeviceContext context, SimpleSceneWrapper sceneWrapper, RenderTargetSet resolvedShadow)
        {
            Vector3 min = m_SceneBoundsMin;
            Vector3 max = m_SceneBoundsMax;
            Vector3 bounds = m_SceneBoundsMax - m_SceneBoundsMin;

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

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

                resolvedShadow.BindSRV(context, 0);
                ExecutePass(context, sceneWrapper, capturePosition);
            }
        }
Exemplo n.º 8
0
        public void ExecutePass(DeviceContext context, SimpleSceneWrapper sceneWrapper, Vector3 position)
        {
            //using (new GpuProfilePoint(context, "CubemapRender"))
            {
                context.PixelShader.SetShaderResource(m_GIVolumeR.m_ShaderResourceView, 5);
                context.PixelShader.SetShaderResource(m_GIVolumeG.m_ShaderResourceView, 6);
                context.PixelShader.SetShaderResource(m_GIVolumeB.m_ShaderResourceView, 7);

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

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

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

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

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

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

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

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

                ContextHelper.ClearCSContext(context);
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
            }
        }