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


C# Texture2D.Map方法代码示例

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


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

示例1: Make3D

        private static Texture2D Make3D(Texture2D stereoTexture)
        {
            NvStereoImageHeader header = new NvStereoImageHeader(0x4433564e, 3840, 1080, 4, 0x00000002);

            // stereoTexture contains a stereo image with the left eye image on the left half
            // and the right eye image on the right half
            // this staging texture will have an extra row to contain the stereo signature
            Texture2DDescription stagingDesc = new Texture2DDescription()
                                                   {
                                                       ArraySize = 1,
                                                       Width = 2*size.Width,
                                                       Height = size.Height + 1,
                                                       BindFlags = BindFlags.None,
                                                       CpuAccessFlags = CpuAccessFlags.Write,
                                                       Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                       OptionFlags = ResourceOptionFlags.None,
                                                       Usage = ResourceUsage.Staging,
                                                       MipLevels = 1,
                                                       SampleDescription = new SampleDescription(1, 0)
                                                   };
            Texture2D staging = new Texture2D(device, stagingDesc);

            // Identify the source texture region to copy (all of it)
            ResourceRegion stereoSrcBox = new ResourceRegion
                                              {Front = 0, Back = 1, Top = 0, Bottom = size.Height, Left = 0, Right = 2*size.Width};
            // Copy it to the staging texture
            device.CopySubresourceRegion(stereoTexture, 0, stereoSrcBox, staging, 0, 0, 0, 0);

            // Open the staging texture for reading
            DataRectangle box = staging.Map(0, MapMode.Write, SlimDX.Direct3D10.MapFlags.None);
            // Go to the last row
            //box.Data.Seek(stereoTexture.Description.Width*stereoTexture.Description.Height*4, System.IO.SeekOrigin.Begin);
            box.Data.Seek(box.Pitch*1080, System.IO.SeekOrigin.Begin);
            // Write the NVSTEREO header
            box.Data.Write(data, 0, data.Length);
            staging.Unmap(0);

            // Create the final stereoized texture
            Texture2DDescription finalDesc = new Texture2DDescription()
                                                 {
                                                     ArraySize = 1,
                                                     Width = 2 * size.Width,
                                                     Height = size.Height + 1,
                                                     BindFlags = BindFlags.ShaderResource,
                                                     CpuAccessFlags = CpuAccessFlags.Write,
                                                     Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                     OptionFlags = ResourceOptionFlags.None,
                                                     Usage = ResourceUsage.Dynamic,
                                                     MipLevels = 1,
                                                     SampleDescription = new SampleDescription(1, 0)
                                                 };

            // Copy the staging texture on a new texture to be used as a shader resource
            Texture2D final = new Texture2D(device, finalDesc);
            device.CopyResource(staging, final);
            staging.Dispose();
            return final;
        }
开发者ID:yong-ja,项目名称:starodyssey,代码行数:58,代码来源:Program.cs

示例2: 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

示例3: LoadBitmapInTexture

 private void LoadBitmapInTexture(Bitmap bitmap, Texture2D texture)
 {
   var rect = texture.Map(0, MapMode.WriteDiscard, MapFlags.None);
   if (rect.Data.CanWrite)
   {
     for (int j = 0; j < texture.Description.Height; j++)
     {
       int rowStart = j * rect.Pitch;
       rect.Data.Seek(rowStart, SeekOrigin.Begin);
       for (int i = 0; i < texture.Description.Width; i++)
       {
         var color = bitmap.GetPixel(i, j);
         rect.Data.WriteByte((byte)color.R);
         rect.Data.WriteByte((byte)color.G);
         rect.Data.WriteByte((byte)color.B);
         rect.Data.WriteByte((byte)color.A);
       }
     }
   }
   texture.Unmap(0);
 }
开发者ID:dgopena,项目名称:Starter3D.Base,代码行数:21,代码来源:Direct3DRenderer.cs

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