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


C# TextureFormat类代码示例

本文整理汇总了C#中TextureFormat的典型用法代码示例。如果您正苦于以下问题:C# TextureFormat类的具体用法?C# TextureFormat怎么用?C# TextureFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GenerateToTexture

        /// <summary>
        /// Generates a texture containing the given graph's noise output.
        /// If this is being called very often, create a permanent render target and material and
        ///     use the other version of this method instead for much better performance.
        /// If an error occurred, outputs to the Unity debug console and returns "null".
        /// </summary>
        /// <param name="outputComponents">
        /// The texture output.
        /// For example, pass "rgb" or "xyz" to output the noise into the red, green, and blue channels
        ///     but not the alpha channel.
        /// </param>
        /// <param name="defaultColor">
        /// The color (generally 0-1) of the color components which aren't set by the noise.
        /// </param>
        public static Texture2D GenerateToTexture(Graph g, GraphParamCollection c, int width, int height,
												  string outputComponents, float defaultColor,
												  TextureFormat format = TextureFormat.RGBAFloat)
        {
            //Generate a shader from the graph and have Unity compile it.
            string shaderPath = Path.Combine(Application.dataPath, "gpuNoiseShaderTemp.shader");
            Shader shader = SaveShader(g, shaderPath, "TempGPUNoiseShader", outputComponents, defaultColor);
            if (shader == null)
            {
                return null;
            }

            //Render the shader's output into a render texture and copy the data to a Texture2D.
            RenderTexture target = new RenderTexture(width, height, 16, RenderTextureFormat.ARGBFloat);
            target.Create();
            Texture2D resultTex = new Texture2D(width, height, format, false, true);

            //Create the material and set its parameters.
            Material mat = new Material(shader);
            c.SetParams(mat);

            GraphUtils.GenerateToTexture(target, mat, resultTex);

            //Clean up.
            target.Release();
            if (!AssetDatabase.DeleteAsset(StringUtils.GetRelativePath(shaderPath, "Assets")))
            {
                Debug.LogError("Unable to delete temp file: " + shaderPath);
            }

            return resultTex;
        }
开发者ID:heyx3,项目名称:GPUNoiseForUnity,代码行数:46,代码来源:GraphEditorUtils.cs

示例2: LoadTextureDXT

        public static Texture2D LoadTextureDXT( string path, TextureFormat format, bool mipmap = true )
        {
            var a = Path.Combine( GenFilePaths.CoreModsFolderPath, LoadedModManager.LoadedMods.ToList().Find( s => s.name == "LT_RedistHeat" ).name );
            var b = Path.Combine( a, "Textures" );
            var filePath = Path.Combine( b,  path + ".dds");
            var bytes = File.ReadAllBytes( filePath );

            if (format != TextureFormat.DXT1 && format != TextureFormat.DXT5)
                throw new Exception("Invalid TextureFormat. Only DXT1 and DXT5 formats are supported by this method.");

            var ddsSizeCheck = bytes[4];
            if (ddsSizeCheck != 124)
                throw new Exception("Invalid DDS DXT texture. Unable to read");  //this header byte should be 124 for DDS image files

            var height = bytes[13] * 256 + bytes[12];
            var width = bytes[17] * 256 + bytes[16];

            var dxtBytes = new byte[bytes.Length - DDSHeaderSize];
            Buffer.BlockCopy(bytes, DDSHeaderSize, dxtBytes, 0, bytes.Length - DDSHeaderSize);

            var texture = new Texture2D(width, height, format, mipmap);
            texture.LoadRawTextureData(dxtBytes);
            texture.Apply();

            return (texture);
        }
开发者ID:ForsakenShell,项目名称:RimWorld-RedistHeat,代码行数:26,代码来源:DXTLoader.cs

示例3: CreateClipMask

        public static Texture2D CreateClipMask(float[] heightMap, int size, float shoreLevel, TextureFormat format)
        {
            Texture2D mask = new Texture2D(size, size, format, false, true);
            mask.filterMode = FilterMode.Bilinear;

            int s2 = size * size;

            Color[] colors = new Color[s2];

            for (int i = 0; i < s2; i++)
            {
                float h = Mathf.Clamp(heightMap[i] - shoreLevel, 0.0f, 1.0f);

                if (h > 0.0f) h = 1.0f;

                colors[i].r = h;
                colors[i].g = h;
                colors[i].b = h;
                colors[i].a = h;
            }

            mask.SetPixels(colors);

            mask.Apply();

            return mask;
        }
开发者ID:BenjaminLovegrove,项目名称:ATR,代码行数:27,代码来源:ShoreMaskGenerator.cs

示例4: OpenTexture

        public void OpenTexture(Stream data, string fname, TextureFormat format)
        {
            Bitmap textureBitmap;
            Texture.Read(data, out textureBitmap, format);

            DisplayTexture(textureBitmap, fname, format);
        }
开发者ID:memerdot,项目名称:puyotools-1,代码行数:7,代码来源:TextureViewer.cs

示例5: GetDXT

        public static void GetDXT(Texture2D texture, int i, byte[] bytes, TextureFormat format)
        {
            Color32[] colors = texture.GetPixels32(i);
            uint w = (uint) texture.width>>i;
            uint h = (uint) texture.height>>i;

            ColorBlock rgba = new ColorBlock();
            BlockDXT1 block1 = new BlockDXT1();
            BlockDXT5 block5 = new BlockDXT5();

            int blocksize = format == TextureFormat.DXT1 ? 8 : 16;
            int index = 0;
            for (uint y = 0; y < h; y += 4) {
                for (uint x = 0; x < w; x += 4) {
                    rgba.init(w, h, colors, x, y);

                    if (format == TextureFormat.DXT1)
                    {
                        QuickCompress.compressDXT1(rgba, block1);
                        block1.WriteBytes(bytes, index);
                    }
                    else
                    {
                        QuickCompress.compressDXT5(rgba, block5, 0);
                        block5.WriteBytes(bytes, index);
                    }

                    index += blocksize;
                }
            }
        }
开发者ID:rbray89,项目名称:ActiveTextureManagement,代码行数:31,代码来源:TextureTools.cs

示例6: GetPixelSize

 public static uint GetPixelSize(TextureFormat textureFormat, int width, int height)
 {
     switch (textureFormat)
     {
         case TextureFormat.Rgba8:
             return (uint)(4 * width * height);
         case TextureFormat.Rgb8:
             return (uint)(3 * width * height);
         case TextureFormat.Rgb5551:
         case TextureFormat.Rgb565:
         case TextureFormat.Rgba4:
         case TextureFormat.La8:
         case TextureFormat.Hilo8:
             return (uint)(2 * width * height);
         case TextureFormat.L8:
         case TextureFormat.A8:
         case TextureFormat.La4:
             return (uint)(1 * width * height);
         case TextureFormat.L4: //TODO: Verify this is correct
         case TextureFormat.A4:
             return (uint)((1 * width * height) / 2);
         case TextureFormat.Etc1:
             return (uint)Etc.GetEtc1Length(new Size(width, height), false);
         case TextureFormat.Etc1A4:
             return (uint)Etc.GetEtc1Length(new Size(width, height), true);
         default:
             throw new Exception("Unsupported Texture Format " + (int)textureFormat);
     }
 }
开发者ID:SciresM,项目名称:FEAT,代码行数:29,代码来源:Texture.cs

示例7: CreateBitmapFromTexture

        /// <summary>
        /// Creates a bitmap from the currently bound texture
        /// </summary>
        public static unsafe Bitmap CreateBitmapFromTexture( int target, int level, TextureFormat format )
        {
            int width = GetTextureLevelParameterInt32( target, level, Gl.GL_TEXTURE_WIDTH );
            int height = GetTextureLevelParameterInt32( target, level, Gl.GL_TEXTURE_HEIGHT );

            GraphicsLog.Verbose( "Creating bitmap from level {0} in {1}x{2} {3} texture", level, width, height, format );

            if ( ( format == TextureFormat.Depth16 ) || ( format == TextureFormat.Depth24 ) || ( format == TextureFormat.Depth32 ) )
            {
                return CreateBitmapFromDepthTexture( target, level, width, height );
            }

            //	Handle colour textures

            //	Get texture memory
            int bytesPerPixel = TextureFormatInfo.GetSizeInBytes( format );
            TextureInfo info = CheckTextureFormat( format );
            byte[] textureMemory = new byte[ width * height * bytesPerPixel ];
            Gl.glGetTexImage( Gl.GL_TEXTURE_2D, level, info.GlFormat, info.GlType, textureMemory );

            //	TODO: Same problem as above...

            //	Create a Bitmap object from image memory
            fixed ( byte* textureMemoryPtr = textureMemory )
            {
                //	TODO: Add per-case check of Format - in cases with no mapping (see TextureFormatToPixelFormat()), do a manual conversion
                return new Bitmap( width, height, width * bytesPerPixel, TextureFormatInfo.ToPixelFormat( format ), ( IntPtr )textureMemoryPtr );
            }
        }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:32,代码来源:OpenGlTexture2dBuilder.cs

示例8: LoadVolumeFromFile

    public static Texture3D LoadVolumeFromFile(string fileName, TextureFormat format, int elementSize ,int width, int height, int depth)
    {
        BinaryReader br = new BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read));
        Texture3D noiseTex = new Texture3D(width, height, depth, TextureFormat.RGBA32, false);
        noiseTex.filterMode = FilterMode.Bilinear;
        noiseTex.wrapMode = TextureWrapMode.Repeat;

        int numElements = width * height * depth;
        List<Color> colors = new List<Color>(numElements);


        // Get pixels from 2d texture for each slize in z direction
        for (int z = 0; z < depth; z++)
        {
            Texture2D tex2d = LoadTexture2DRaw(br, width, height, format, elementSize);
            colors.AddRange(tex2d.GetPixels());
        }
        //colors should now be filled with all pixels
        noiseTex.SetPixels(colors.ToArray());
        noiseTex.Apply(false);

        br.Close();
        return noiseTex;
   
    }
开发者ID:Mymicky,项目名称:MarchingCubesUnity,代码行数:25,代码来源:Helper.cs

示例9: Create

 /// <summary>
 /// Creates the texture data
 /// </summary>
 public void Create( int width, int height, TextureFormat format )
 {
     m_Width = width;
     m_Height = height;
     m_Format = format;
     m_Data = new byte[ width * height * TextureFormatInfo.GetSizeInBytes( format ) ];
 }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:10,代码来源:Texture2dData.cs

示例10: ConvertDown

        public Corona.Image ConvertDown(Corona.Image sourceImage, TextureFormat toFormat)
        {
            int bits = -1;
            if (toFormat == TextureFormat.Format2_I2) bits = 2;
            if (toFormat == TextureFormat.Format3_I4) bits = 4;
            if (toFormat == TextureFormat.Format4_I8) bits = 8;
            if (toFormat == TextureFormat.Format7_16bpp) bits = 16;

            int colors = 1<<bits;

            Corona.Image ret = null;

            using (Util.TempFile tmpIn = new Util.TempFile("png"), tmpOut = new Util.TempFile("png"))
            {
                sourceImage.Save(tmpIn.Path, Corona.FileFormat.PNG);

                string output = Run("-treedepth", 4, "-colors", colors, tmpIn, tmpOut);

                if (toFormat == TextureFormat.Format7_16bpp)
                    ret = Corona.Image.Open(tmpOut.Path, Corona.PixelFormat.R8G8B8A8, Corona.FileFormat.PNG);
                else
                    ret = Corona.Image.Open(tmpOut.Path, Corona.PixelFormat.I8, Corona.FileFormat.PNG);

            }
            return ret;
        }
开发者ID:mtheall,项目名称:DS3dbugger,代码行数:26,代码来源:ImageMagick.cs

示例11: GetScreenBytes

 public static byte[] GetScreenBytes(TextureFormat textureFormat)
 {
     Texture2D screenTexture = new Texture2D(Screen.width, Screen.height,textureFormat,true);
     screenTexture.ReadPixels(new Rect(0f, 0f, Screen.width, Screen.height),0,0);
     screenTexture.Apply();
     byte[] byteArray = screenTexture.EncodeToPNG();
     return byteArray;
 }
开发者ID:shawmakesmusic,项目名称:leo,代码行数:8,代码来源:SPAndroidShare.cs

示例12: TileMeshSettings

		public TileMeshSettings (IVector2 tiles, int tileResolution, float tileSize, MeshMode meshMode, TextureFormat textureFormat)
		{
			Tiles			= tiles;
			TileResolution	= tileResolution;
			TileSize		= tileSize;
			MeshMode		= meshMode;
			TextureFormat	= textureFormat;
		}
开发者ID:DarkXenoShark,项目名称:AI-ICA2-RTS,代码行数:8,代码来源:TileMeshSettings.cs

示例13: YUVTexture

 /// <summary>
 /// Initializes a new instance of the <see cref="Tango.YUVTexture"/> class.
 /// NOTE : Texture resolutions will be reset by the API. The sizes passed
 /// into the constructor are not guaranteed to persist when running on device.
 /// </summary>
 /// <param name="width">Width.</param>
 /// <param name="height">Height.</param>
 /// <param name="format">Format.</param>
 /// <param name="mipmap">If set to <c>true</c> mipmap.</param>
 public YUVTexture(int yPlaneWidth, int yPlaneHeight,
                   int uvPlaneWidth, int uvPlaneHeight,
                   TextureFormat format, bool mipmap)
 {
     m_videoOverlayTextureY = new Texture2D(yPlaneWidth, yPlaneHeight, format, mipmap);
     m_videoOverlayTextureCb = new Texture2D(uvPlaneWidth, uvPlaneHeight, format, mipmap);
     m_videoOverlayTextureCr = new Texture2D(uvPlaneWidth, uvPlaneHeight, format, mipmap);
 }
开发者ID:nigelDaMan,项目名称:WeCanTango,代码行数:17,代码来源:VideoOverlayProvider.cs

示例14: Texture2DInfo

	public Texture2DInfo(int width, int height, TextureFormat format, bool hasMipmaps, byte[] rawData)
	{
		this.width = width;
		this.height = height;
		this.format = format;
		this.hasMipmaps = hasMipmaps;
		this.rawData = rawData;
	}
开发者ID:ozonexo3,项目名称:FAForeverMapEditor,代码行数:8,代码来源:Texture2DInfo.cs

示例15: TileMeshSettings

 public TileMeshSettings(int tilesX, int tilesY, int tileResolution, float tileSize, MeshMode meshMode, TextureFormat textureFormat)
 {
     TilesX = tilesX;
     TilesY = tilesY;
     TileResolution = tileResolution;
     TileSize = tileSize;
     MeshMode = meshMode;
     TextureFormat = textureFormat;
 }
开发者ID:ntl92bk,项目名称:UnityTileMap,代码行数:9,代码来源:TileMeshSettings.cs


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