Пример #1
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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
        }
Пример #4
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);
            }
        }