示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="srcDst"></param>
        /// <param name="temporary"></param>
        /// <param name="sigma"></param>
        /// <param name="kernelSize"></param>
        void GaussBlurInternal(RenderTarget2D src, RenderTarget2D dst, RenderTarget2D temporary, float sigma, float sharpness, int mipLevel, ShaderResource depthData, ShaderResource normalData)
        {
            var taps = GetGaussWeightsBuffer(sigma, mipLevel);

            SetDefaultRenderStates();

            gaussWeightsCB.SetData(taps);


            int combination = (int)ShaderFlags.GAUSS_BLUR;

            if (depthData != null && normalData != null)
            {
                combination |= (int)ShaderFlags.BILATERAL;
            }



            using (new PixEvent("GaussBlur")) {
                SetViewport(temporary.GetSurface(mipLevel));
                device.SetTargets(null, temporary.GetSurface(mipLevel));

                device.PipelineState            = factory[combination | (int)ShaderFlags.PASS1];
                device.VertexShaderResources[0] = src;
                device.PixelShaderResources[0]  = src;
                device.PixelShaderResources[1]  = depthData;
                device.PixelShaderResources[2]  = normalData;

                device.PixelShaderConstants[0] = gaussWeightsCB;

                device.PixelShaderSamplers[0] = SamplerState.LinearPointClamp;
                device.PixelShaderSamplers[1] = SamplerState.PointClamp;

                device.Draw(3, 0);



                device.VertexShaderResources[0] = null;
                device.PixelShaderResources[0]  = null;

                SetViewport(dst.GetSurface(mipLevel));
                device.SetTargets(null, dst.GetSurface(mipLevel));

                device.PipelineState            = factory[combination | (int)ShaderFlags.PASS2];
                device.VertexShaderResources[0] = temporary;
                device.PixelShaderResources[0]  = temporary;
                device.PixelShaderResources[1]  = depthData;
                device.PixelShaderResources[2]  = normalData;

                device.PixelShaderConstants[0] = gaussWeightsCB;

                device.PixelShaderSamplers[0] = SamplerState.LinearPointClamp;
                device.PixelShaderSamplers[1] = SamplerState.PointClamp;

                device.Draw(3, 0);
            }
            device.ResetStates();
        }
示例#2
0
        /// <summary>
        ///	Updates page table using GPU
        /// </summary>
        void UpdatePageTable()
        {
            int tableSize = VTConfig.VirtualPageCount;

            using (new PixEvent("UpdatePageTable")) {
                var pages = tileCache.GetGpuPageData();

                if (pages.Any())
                {
                    PageData.SetData(pages);
                }

                for (int mip = 0; mip < VTConfig.MipCount; mip++)
                {
                    Params.SetData(new Int4(pages.Length, mip, 0, 0));

                    var device = Game.GraphicsDevice;
                    device.ResetStates();

                    device.PipelineState = factory[0];

                    device.ComputeShaderConstants[0] = Params;
                    device.ComputeShaderResources[0] = PageData;
                    device.SetCSRWTexture(0, PageTable.GetSurface(mip));

                    int targetSize  = tableSize >> mip;
                    int groupCountX = MathUtil.IntDivUp(targetSize, BlockSizeX);
                    int groupCountY = MathUtil.IntDivUp(targetSize, BlockSizeX);

                    device.Dispatch(groupCountX, groupCountY, 1);
                }
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="srcDst">source and destination target</param>
        /// <param name="temporary">temporaru target for two pass filter</param>

        /*public void GaussBlur3x3( RenderTarget2D srcDst, RenderTarget2D temporary )
         * {
         *      SetDefaultRenderStates();
         *
         *      using( new PixEvent() ) {
         *              srcDst.SetViewport();
         *              rs.PixelShaderSamplers[0] = SamplerState.LinearPointClamp;
         *
         *              rs.PipelineState			=	factory[ (int)ShaderFlags.GAUSS_BLUR_3x3 ];
         * shaders.SetPixelShader( (int)(ShaderFlags.GAUSS_BLUR_3x3) );
         * shaders.SetVertexShader( (int)(ShaderFlags.GAUSS_BLUR_3x3) );
         *
         * rs.SetTargets( null, temporary );
         *              rs.VertexShaderResources[0] = srcDst;
         *              rs.PixelShaderResources[0] = srcDst;
         *
         *              rs.Draw( Primitive.TriangleList, 3, 0 );
         *
         * shaders.SetPixelShader( (int)(ShaderFlags.GAUSS_BLUR_3x3 | ShaderFlags.PASS2) );
         * shaders.SetVertexShader( (int)(ShaderFlags.GAUSS_BLUR_3x3 | ShaderFlags.PASS2) );
         *
         * rs.SetTargets( null, srcDst );
         *              rs.VertexShaderResources[0] = temporary;
         *              rs.PixelShaderResources[0] = temporary;
         *
         * rs.Draw( Primitive.TriangleList, 3, 0 );
         *      }
         *      rs.ResetStates();
         * }	*/



        /// <summary>
        ///
        /// </summary>
        /// <param name="srcDst"></param>
        /// <param name="temporary"></param>
        /// <param name="sigma"></param>
        /// <param name="kernelSize"></param>
        public void GaussBlur(RenderTarget2D srcDst, RenderTarget2D temporary, float sigma, int mipLevel)
        {
            var taps = GetGaussWeightsBuffer(sigma, mipLevel);

            SetDefaultRenderStates();

            gaussWeightsCB.SetData(taps);

            using (new PixEvent()) {
                SetViewport(temporary.GetSurface(mipLevel));
                rs.SetTargets(null, temporary.GetSurface(mipLevel));

                rs.PipelineState            = factory[(int)(ShaderFlags.GAUSS_BLUR | ShaderFlags.PASS1)];
                rs.VertexShaderResources[0] = srcDst;
                rs.PixelShaderResources[0]  = srcDst;
                rs.PixelShaderConstants[0]  = gaussWeightsCB;

                rs.PixelShaderSamplers[0] = SamplerState.LinearPointClamp;

                rs.Draw(3, 0);


                rs.VertexShaderResources[0] = null;
                rs.PixelShaderResources[0]  = null;

                SetViewport(srcDst.GetSurface(mipLevel));
                rs.SetTargets(null, srcDst.GetSurface(mipLevel));

                rs.PipelineState            = factory[(int)(ShaderFlags.GAUSS_BLUR | ShaderFlags.PASS2)];
                rs.VertexShaderResources[0] = temporary;
                rs.PixelShaderResources[0]  = temporary;
                rs.PixelShaderConstants[0]  = gaussWeightsCB;

                rs.PixelShaderSamplers[0] = SamplerState.LinearPointClamp;

                rs.Draw(3, 0);
            }
            rs.ResetStates();
        }
示例#4
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="srcDst"></param>
		/// <param name="temporary"></param>
		/// <param name="sigma"></param>
		/// <param name="kernelSize"></param>
		void GaussBlurInternal ( RenderTarget2D srcDst, RenderTarget2D temporary, float sigma, float sharpness, int mipLevel, ShaderResource depthData, ShaderResource normalData )
		{
			var taps = GetGaussWeightsBuffer( sigma, mipLevel );

			SetDefaultRenderStates();

			gaussWeightsCB.SetData( taps );


			int combination	=	(int)ShaderFlags.GAUSS_BLUR;

			if (depthData!=null && normalData!=null) {
				combination |=	(int)ShaderFlags.BILATERAL;
			}



			using( new PixEvent("GaussBlur") ) {

				SetViewport(temporary.GetSurface(mipLevel));
				rs.SetTargets( null, temporary.GetSurface(mipLevel) );

				rs.PipelineState			=	factory[ combination|(int)ShaderFlags.PASS1 ];
				rs.VertexShaderResources[0]	=	srcDst;
				rs.PixelShaderResources[0]	=	srcDst;
				rs.PixelShaderResources[1]	=	depthData;
				rs.PixelShaderResources[2]	=	normalData;

				rs.PixelShaderConstants[0]	=	gaussWeightsCB;
				
				rs.PixelShaderSamplers[0]	=	SamplerState.LinearPointClamp;
				rs.PixelShaderSamplers[1]	=	SamplerState.PointClamp;

				rs.Draw( 3, 0 );



				rs.VertexShaderResources[0] =	null;
				rs.PixelShaderResources[0]	=	null;

				SetViewport(srcDst.GetSurface(mipLevel));
				rs.SetTargets( null, srcDst.GetSurface(mipLevel) );

				rs.PipelineState			=	factory[ combination|(int)ShaderFlags.PASS2 ];
				rs.VertexShaderResources[0] =	temporary;
				rs.PixelShaderResources[0]	=	temporary;
				rs.PixelShaderResources[1]	=	depthData;
				rs.PixelShaderResources[2]	=	normalData;

				rs.PixelShaderConstants[0]	=	gaussWeightsCB;

				rs.PixelShaderSamplers[0]	=	SamplerState.LinearPointClamp;
				rs.PixelShaderSamplers[1]	=	SamplerState.PointClamp;

				rs.Draw( 3, 0 );
			}
			rs.ResetStates();
		}
示例#5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="srcDst">source and destination target</param>
        /// <param name="temporary">temporaru target for two pass filter</param>
        /*public void GaussBlur3x3( RenderTarget2D srcDst, RenderTarget2D temporary )
        {
            SetDefaultRenderStates();

            using( new PixEvent() ) {
                srcDst.SetViewport();
                rs.PixelShaderSamplers[0] = SamplerState.LinearPointClamp;

                rs.PipelineState			=	factory[ (int)ShaderFlags.GAUSS_BLUR_3x3 ];
                shaders.SetPixelShader( (int)(ShaderFlags.GAUSS_BLUR_3x3) );
                shaders.SetVertexShader( (int)(ShaderFlags.GAUSS_BLUR_3x3) );

                rs.SetTargets( null, temporary );
                rs.VertexShaderResources[0] = srcDst;
                rs.PixelShaderResources[0] = srcDst;

                rs.Draw( Primitive.TriangleList, 3, 0 );

                shaders.SetPixelShader( (int)(ShaderFlags.GAUSS_BLUR_3x3 | ShaderFlags.PASS2) );
                shaders.SetVertexShader( (int)(ShaderFlags.GAUSS_BLUR_3x3 | ShaderFlags.PASS2) );

                rs.SetTargets( null, srcDst );
                rs.VertexShaderResources[0] = temporary;
                rs.PixelShaderResources[0] = temporary;

                rs.Draw( Primitive.TriangleList, 3, 0 );
            }
            rs.ResetStates();
        }	*/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="srcDst"></param>
        /// <param name="temporary"></param>
        /// <param name="sigma"></param>
        /// <param name="kernelSize"></param>
        public void GaussBlur( RenderTarget2D srcDst, RenderTarget2D temporary, float sigma, int mipLevel )
        {
            var taps = GetGaussWeightsBuffer( sigma, mipLevel );

            SetDefaultRenderStates();

            gaussWeightsCB.SetData( taps );

            using( new PixEvent() ) {

                SetViewport(temporary.GetSurface(mipLevel));
                rs.SetTargets( null, temporary.GetSurface(mipLevel) );

                rs.PipelineState			=	factory[ (int)(ShaderFlags.GAUSS_BLUR | ShaderFlags.PASS1) ];
                rs.VertexShaderResources[0]	=	srcDst;
                rs.PixelShaderResources[0]	=	srcDst;
                rs.PixelShaderConstants[0]	=	gaussWeightsCB;

                rs.PixelShaderSamplers[0]	=	SamplerState.LinearPointClamp;

                rs.Draw( 3, 0 );

                rs.VertexShaderResources[0] =	null;
                rs.PixelShaderResources[0]	=	null;

                SetViewport(srcDst.GetSurface(mipLevel));
                rs.SetTargets( null, srcDst.GetSurface(mipLevel) );

                rs.PipelineState			=	factory[ (int)(ShaderFlags.GAUSS_BLUR | ShaderFlags.PASS2) ];
                rs.VertexShaderResources[0] =	temporary;
                rs.PixelShaderResources[0]	=	temporary;
                rs.PixelShaderConstants[0]	=	gaussWeightsCB;

                rs.PixelShaderSamplers[0]	=	SamplerState.LinearPointClamp;

                rs.Draw( 3, 0 );
            }
            rs.ResetStates();
        }