当前位置: 首页>>代码示例>>C#>>正文


C# Texture2D.UnMap方法代码示例

本文整理汇总了C#中Texture2D.UnMap方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.UnMap方法的具体用法?C# Texture2D.UnMap怎么用?C# Texture2D.UnMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Texture2D的用法示例。


在下文中一共展示了Texture2D.UnMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ComputeBRDFIntegral

		unsafe void	ComputeBRDFIntegral( System.IO.FileInfo _TableFileName, uint _TableSize ) {

//			ComputeShader	CS = new ComputeShader( m_Device, new System.IO.FileInfo( "Shaders/ComputeBRDFIntegral.hlsl" ), "CS", new ShaderMacro[0] );
			ComputeShader	CS = new ComputeShader( m_Device, new System.IO.FileInfo( "Shaders/ComputeBRDFIntegral.hlsl" ), "CS", new ShaderMacro[] { new ShaderMacro( "IMPORTANCE_SAMPLING", "1" ) } );

			Texture2D		TexTable = new Texture2D( m_Device, _TableSize, _TableSize, 1, 1, PIXEL_FORMAT.RG32_FLOAT, false, true, null );
			TexTable.SetCSUAV( 0 );
			CS.Use();
			CS.Dispatch( _TableSize >> 4, _TableSize >> 4, 1 );
			CS.Dispose();



			string	DDSFileName = System.IO.Path.GetFileNameWithoutExtension( _TableFileName.FullName ) + ".dds";
//			DirectXTexManaged.TextureCreator.CreateDDS( DDSFileName, TexTable );
throw new Exception( "Deprecated!" );


 
			Texture2D		TexTableStaging = new Texture2D( m_Device, _TableSize, _TableSize, 1, 1, PIXEL_FORMAT.RG32_FLOAT, true, false, null );
			TexTableStaging.CopyFrom( TexTable );
			TexTable.Dispose();

			// Write tables
			float2	Temp = new float2();
			float	F0_analytical;
			float	ambient_analytical;
			float	maxAbsoluteError_F0 = 0.0f;
			float	maxRelativeError_F0 = 0.0f;
			float	avgAbsoluteError_F0 = 0.0f;
			float	avgRelativeError_F0 = 0.0f;
			float	maxAbsoluteError_ambient = 0.0f;
			float	maxRelativeError_ambient = 0.0f;
			float	avgAbsoluteError_ambient = 0.0f;
			float	avgRelativeError_ambient = 0.0f;

			float2[]	Integral_SpecularReflectance = new float2[_TableSize];

			PixelsBuffer Buff = TexTableStaging.Map( 0, 0 );
			using ( System.IO.BinaryReader R = Buff.OpenStreamRead() )
				using ( System.IO.FileStream S = _TableFileName.Create() )
					using ( System.IO.BinaryWriter W = new System.IO.BinaryWriter( S ) )
						for ( int Y=0; Y < _TableSize; Y++ ) {
							float2	SumSpecularlyReflected = float2.Zero;
							for ( int X=0; X < _TableSize; X++ ) {
								Temp.x = R.ReadSingle();
								Temp.y = R.ReadSingle();
								W.Write( Temp.x );
								W.Write( Temp.y );

								SumSpecularlyReflected.x += Temp.x;
								SumSpecularlyReflected.y += Temp.y;

								// Check analytical solution
								float	NdotV = (float) X / (_TableSize-1);
								float	roughness = (float) Y / (_TableSize-1);
								AnalyticalBRDFIntegral_Order3( NdotV, roughness, out F0_analytical, out ambient_analytical );
//								AnalyticalBRDFIntegral_Order2( NdotV, roughness, out F0_analytical, out ambient_analytical );

								float	absoluteError_F0 = Math.Abs( F0_analytical - Temp.x );
								float	relativeError_F0 = F0_analytical > 1e-6f ? Temp.x / F0_analytical : 0.0f;
								maxAbsoluteError_F0 = Math.Max( maxAbsoluteError_F0, absoluteError_F0 );
								maxRelativeError_F0 = Math.Max( maxRelativeError_F0, relativeError_F0 );
								avgAbsoluteError_F0 += absoluteError_F0;
								avgRelativeError_F0 += relativeError_F0;

								float	absoluteError_ambient = Math.Abs( ambient_analytical - Temp.y );
								float	relativeError_ambient = ambient_analytical > 1e-6f ? Temp.x / ambient_analytical : 0.0f;
								maxAbsoluteError_ambient = Math.Max( maxAbsoluteError_ambient, absoluteError_ambient );
								maxRelativeError_ambient = Math.Max( maxRelativeError_ambient, relativeError_ambient );
								avgAbsoluteError_ambient += absoluteError_ambient;
								avgRelativeError_ambient += relativeError_ambient;
							}

							// Normalize and store "not specularly reflected" light
							SumSpecularlyReflected = SumSpecularlyReflected / _TableSize;

							float	sum_dielectric = 1.0f - (0.04f * SumSpecularlyReflected.x + SumSpecularlyReflected.y);
							float	sum_metallic = 1.0f - (SumSpecularlyReflected.x + SumSpecularlyReflected.y);

							Integral_SpecularReflectance[Y] = SumSpecularlyReflected;
						}
			TexTableStaging.UnMap( 0, 0 );

			avgAbsoluteError_F0 /= _TableSize*_TableSize;
			avgRelativeError_F0 /= _TableSize*_TableSize;
			avgAbsoluteError_ambient /= _TableSize*_TableSize;
			avgRelativeError_ambient /= _TableSize*_TableSize;

			string	TotalSpecularReflectionTableFileName = System.IO.Path.GetFileNameWithoutExtension( _TableFileName.FullName ) + ".table";
			using ( System.IO.FileStream S = new System.IO.FileInfo( TotalSpecularReflectionTableFileName ).Create() )
				using ( System.IO.BinaryWriter W = new System.IO.BinaryWriter( S ) )
					for ( int i=0; i < _TableSize; i++ ) {
						W.Write( Integral_SpecularReflectance[i].x );
						W.Write( Integral_SpecularReflectance[i].y );
					}
		}
开发者ID:Patapom,项目名称:GodComplex,代码行数:97,代码来源:AreaLightForm.cs

示例2: HistogramTexture2Array

        /// <summary>
        /// Reads back a lobe texture histogram into an array
        /// </summary>
        /// <param name="_texHistogram_CPU"></param>
        /// <param name="_scatteringOrder"></param>
        /// <returns></returns>
        public static double[,] HistogramTexture2Array( Texture2D _texHistogram_CPU, int _scatteringOrder )
        {
            int	scattMin = _scatteringOrder-1;		// Because scattering order 1 is actually stored in first slice of the texture array
            int	scattMax = scattMin+1;				// To simulate a single scattering order
            //			int	scattMax = MAX_SCATTERING_ORDER;	// To simulate all scattering orders accumulated

            int			W = _texHistogram_CPU.Width;
            int			H = _texHistogram_CPU.Height;
            double[,]	histogramData = new double[W,H];

            for ( int scatteringOrder=scattMin; scatteringOrder < scattMax; scatteringOrder++ ) {
                PixelsBuffer	Content = _texHistogram_CPU.Map( 0, scatteringOrder );
                using ( BinaryReader R = Content.OpenStreamRead() )
                    for ( int Y=0; Y < H; Y++ )
                        for ( int X=0; X < W; X++ )
                            histogramData[X,Y] += W * H * R.ReadSingle();
                Content.CloseStream();
                _texHistogram_CPU.UnMap( 0, scatteringOrder );
            }

            return histogramData;
        }
开发者ID:Patapom,项目名称:GodComplex,代码行数:28,代码来源:LobeModel.cs


注:本文中的Texture2D.UnMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。