tex | 要转换的纹理。 |
flags | 用于控制压缩和输出格式的标志。 |
将该纹理编码为 EXR 格式。
This function returns a byte array which is the EXR file data. Write this data to disk to get the data in the EXR file format.
It is best to use this function for HDR texture formats (either 16-bit or 32-bit floats). The default output format is 16-bit float EXR. For the texture pass in, Texture.isReadable must be true
..
The encoded EXR data will always contain an alpha channel.
For single-channel red textures ( R8
, R16
, RFloat
and RHalf
), the encoded data will be in grayscale mode.
// Saves HDR RenderTexture as an EXR file. using UnityEngine; using System.Collections; using System.IO;
public class SaveRenderTextureToEXR : MonoBehaviour { RenderTexture m_InputTexture;
void SaveRenderTexture() { if (m_InputTexture != null) { int width = m_InputTexture.width; int height = m_InputTexture.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGBAFloat, false);
// Read screen contents into the texture Graphics.SetRenderTarget(m_InputTexture); tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply();
// Encode texture into the EXR byte[] bytes = tex.EncodeToEXR(Texture2D.EXRFlags.CompressZIP); File.WriteAllBytes(Application.dataPath + "/../SavedRenderTexture.exr", bytes);
Object.DestroyImmediate(tex); } } }
See Also: EncodeArrayToEXR, EncodeNativeArrayToEXR, EncodeToPNG, EncodeToJPG, EncodeToTGA.