예제 #1
0
        internal static void Run(RenderTargetView renderTarget, RenderTargetView intermediateRenderTarget, ShaderResourceView intermediateResourceView, ShaderResourceView initialResourceView,
                                 int maxOffset = 5, MyBlurDensityFunctionType densityFunctionType = MyBlurDensityFunctionType.Gaussian, float WeightParameter = 1.5f,
                                 DepthStencilState depthStencilState = null, int stencilRef       = 0x0, bool copyOnStencilFail = false,
                                 float depthDiscardThreshold         = 0.0f, MyViewport?viewport  = null)
        {
            ProfilerShort.Begin("MyBlur.Run");
            MyGpuProfiler.IC_BeginBlock("MyBlur.Run");
            Debug.Assert(initialResourceView != null);
            Debug.Assert(intermediateResourceView != null);
            Debug.Assert(intermediateRenderTarget != null);
            Debug.Assert(renderTarget != null);

            int shaderKey = InitShaders(densityFunctionType, maxOffset, copyOnStencilFail, depthDiscardThreshold);

            RC.DeviceContext.PixelShader.SetConstantBuffer(5, m_blurConstantBuffer);

            BlurConstants constants = new BlurConstants
            {
                DistributionWeight = WeightParameter,
                StencilRef         = stencilRef,
            };
            var mapping = MyMapping.MapDiscard(m_blurConstantBuffer);

            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            // Horizontal pass
            MyRender11.DeviceContext.ClearRenderTargetView(intermediateRenderTarget, Color4.White);
            RC.DeviceContext.OutputMerger.SetTargets(intermediateRenderTarget);
            RC.SetDS(depthStencilState, stencilRef);
            RC.DeviceContext.PixelShader.SetShaderResource(0, MyGBuffer.Main.DepthStencil.m_SRV_depth);
            RC.DeviceContext.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            RC.DeviceContext.PixelShader.SetShaderResource(5, initialResourceView);
            RC.SetPS(m_blurShaders[shaderKey].Item1);
            MyScreenPass.DrawFullscreenQuad(viewport);
            RC.DeviceContext.PixelShader.SetShaderResource(5, null);

            // Vertical pass
            MyRender11.DeviceContext.ClearRenderTargetView(renderTarget, Color4.White);
            RC.DeviceContext.OutputMerger.SetTargets(renderTarget);
            RC.SetDS(depthStencilState, stencilRef);
            RC.DeviceContext.PixelShader.SetShaderResource(0, MyGBuffer.Main.DepthStencil.m_SRV_depth);
            RC.DeviceContext.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            RC.DeviceContext.PixelShader.SetShaderResource(5, intermediateResourceView);
            RC.SetPS(m_blurShaders[shaderKey].Item2);
            MyScreenPass.DrawFullscreenQuad(viewport);

            RC.DeviceContext.PixelShader.SetShaderResource(0, null);
            RC.DeviceContext.PixelShader.SetShaderResource(4, null);
            RC.DeviceContext.PixelShader.SetShaderResource(5, null);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }
예제 #2
0
        internal static void Run(RenderTargetView renderTarget, RenderTargetView intermediateRenderTarget, ShaderResourceView intermediateResourceView, ShaderResourceView initialResourceView,
                                 int maxOffset = 5, MyBlurDensityFunctionType densityFunctionType = MyBlurDensityFunctionType.Gaussian, float WeightParameter = 1.5f,
                                 DepthStencilState depthStencilState = null, int stencilRef = 0x0, bool copyOnStencilFail = false,
                                 float depthDiscardThreshold = 0.0f, MyViewport? viewport = null)
        {
            ProfilerShort.Begin("MyBlur.Run");
            MyGpuProfiler.IC_BeginBlock("MyBlur.Run");
            Debug.Assert(initialResourceView != null);
            Debug.Assert(intermediateResourceView != null);
            Debug.Assert(intermediateRenderTarget != null);
            Debug.Assert(renderTarget != null);

            int shaderKey = InitShaders(densityFunctionType, maxOffset, copyOnStencilFail, depthDiscardThreshold);

            RC.DeviceContext.PixelShader.SetConstantBuffer(5, m_blurConstantBuffer);

            BlurConstants constants = new BlurConstants
            {
                DistributionWeight = WeightParameter,
                StencilRef = stencilRef,
            };
            var mapping = MyMapping.MapDiscard(m_blurConstantBuffer);
            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            // Horizontal pass
            MyRender11.DeviceContext.ClearRenderTargetView(intermediateRenderTarget, Color4.White);
            RC.DeviceContext.OutputMerger.SetTargets(intermediateRenderTarget);
            RC.SetDS(depthStencilState, stencilRef);
            RC.DeviceContext.PixelShader.SetShaderResource(0, MyGBuffer.Main.DepthStencil.m_SRV_depth);
            RC.DeviceContext.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            RC.DeviceContext.PixelShader.SetShaderResource(5, initialResourceView);
            RC.SetPS(m_blurShaders[shaderKey].Item1);
            MyScreenPass.DrawFullscreenQuad(viewport);
            RC.DeviceContext.PixelShader.SetShaderResource(5, null);

            // Vertical pass
            MyRender11.DeviceContext.ClearRenderTargetView(renderTarget, Color4.White);
            RC.DeviceContext.OutputMerger.SetTargets(renderTarget);
            RC.SetDS(depthStencilState, stencilRef);
            RC.DeviceContext.PixelShader.SetShaderResource(0, MyGBuffer.Main.DepthStencil.m_SRV_depth);
            RC.DeviceContext.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            RC.DeviceContext.PixelShader.SetShaderResource(5, intermediateResourceView);
            RC.SetPS(m_blurShaders[shaderKey].Item2);
            MyScreenPass.DrawFullscreenQuad(viewport);

            RC.DeviceContext.PixelShader.SetShaderResource(0, null);
            RC.DeviceContext.PixelShader.SetShaderResource(4, null);
            RC.DeviceContext.PixelShader.SetShaderResource(5, null);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }
예제 #3
0
        /// <param name="clearColor">Color used to clear render targets. Defaults to black</param>
        internal static void Run(IRtvBindable renderTarget, IRtvTexture intermediate, ISrvBindable initialResourceView,
            int maxOffset = 5, MyBlurDensityFunctionType densityFunctionType = MyBlurDensityFunctionType.Gaussian, float WeightParameter = 1.5f,
            IDepthStencilState depthStencilState = null, int stencilRef = 0x0, Color4 clearColor = default(Color4),
            float depthDiscardThreshold = 0.0f, MyViewport? viewport = null)
        {
            ProfilerShort.Begin("MyBlur.Run");
            MyGpuProfiler.IC_BeginBlock("MyBlur.Run");
            Debug.Assert(initialResourceView != null);
            Debug.Assert(intermediate != null);
            Debug.Assert(renderTarget != null);

            int shaderKey = InitShaders(densityFunctionType, maxOffset, depthDiscardThreshold);

            RC.PixelShader.SetConstantBuffer(5, m_blurConstantBuffer);

            BlurConstants constants = new BlurConstants
            {
                DistributionWeight = WeightParameter,
                StencilRef = stencilRef,
            };
            var mapping = MyMapping.MapDiscard(m_blurConstantBuffer);
            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            // Horizontal pass
            // NOTE: DepthStencilState is not used here because the resulted target
            // would not be usable to perform vertical pass. DepthStencil is stil
            // bindinded as SRV since it is sampled in the shader 
            RC.ClearRtv(intermediate, clearColor);
            RC.SetRtv(intermediate);
            RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
            RC.PixelShader.SetSrv(4, MyGBuffer.Main.DepthStencil.SrvStencil);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            RC.PixelShader.SetSrv(5, initialResourceView);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item1);
            MyScreenPass.DrawFullscreenQuad(viewport);
            RC.PixelShader.SetSrv(5, null);

            // Vertical pass
            RC.ClearRtv(renderTarget, clearColor);
            if (depthStencilState == null)
            {
                RC.SetRtv(renderTarget);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilRef);
                RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, renderTarget);
            }

            RC.PixelShader.SetSrv(5, intermediate);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item2);
            MyScreenPass.DrawFullscreenQuad(viewport);

            RC.PixelShader.SetSrv(0, null);
            RC.PixelShader.SetSrv(4, null);
            RC.PixelShader.SetSrv(5, null);
            RC.SetRtv(null);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }
예제 #4
0
파일: MyBlur.cs 프로젝트: viktorius/Viktor
        /// <param name="clearColor">Color used to clear render targets. Defaults to black</param>
        internal static void Run(IRtvBindable renderTarget, IRtvTexture intermediate, ISrvBindable initialResourceView,
                                 int maxOffset = 5, MyBlurDensityFunctionType densityFunctionType = MyBlurDensityFunctionType.Gaussian, float WeightParameter = 1.5f,
                                 IDepthStencilState depthStencilState = null, int stencilRef      = 0x0, Color4 clearColor = default(Color4),
                                 float depthDiscardThreshold          = 0.0f, MyViewport?viewport = null)
        {
            ProfilerShort.Begin("MyBlur.Run");
            MyGpuProfiler.IC_BeginBlock("MyBlur.Run");
            Debug.Assert(initialResourceView != null);
            Debug.Assert(intermediate != null);
            Debug.Assert(renderTarget != null);

            int shaderKey = InitShaders(densityFunctionType, maxOffset, depthDiscardThreshold);

            RC.PixelShader.SetConstantBuffer(5, m_blurConstantBuffer);

            BlurConstants constants = new BlurConstants
            {
                DistributionWeight = WeightParameter,
                StencilRef         = stencilRef,
            };
            var mapping = MyMapping.MapDiscard(m_blurConstantBuffer);

            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            // Horizontal pass
            // NOTE: DepthStencilState is not used here because the resulted target
            // would not be usable to perform vertical pass. DepthStencil is stil
            // bindinded as SRV since it is sampled in the shader
            RC.ClearRtv(intermediate, clearColor);
            RC.SetRtv(intermediate);
            RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
            RC.PixelShader.SetSrv(4, MyGBuffer.Main.DepthStencil.SrvStencil);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            RC.PixelShader.SetSrv(5, initialResourceView);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item1);
            MyScreenPass.DrawFullscreenQuad(viewport);
            RC.PixelShader.SetSrv(5, null);

            // Vertical pass
            RC.ClearRtv(renderTarget, clearColor);
            if (depthStencilState == null)
            {
                RC.SetRtv(renderTarget);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilRef);
                RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, renderTarget);
            }

            RC.PixelShader.SetSrv(5, intermediate);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item2);
            MyScreenPass.DrawFullscreenQuad(viewport);

            RC.PixelShader.SetSrv(0, null);
            RC.PixelShader.SetSrv(4, null);
            RC.PixelShader.SetSrv(5, null);
            RC.SetRtv(null);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }