Skip to content

Commit

Permalink
Add support for exr texture export in correct format
Browse files Browse the repository at this point in the history
previously it was exported with exr extension but actually encoded as PNG regardless
  • Loading branch information
marwie committed Nov 8, 2023
1 parent 7d1817e commit ccaa589
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Runtime/Scripts/SceneExporter/ExporterTextures.cs
Expand Up @@ -124,11 +124,26 @@ private void WriteRenderTextureToDiskAndRelease(RenderTexture destRenderTexture,
{
RenderTexture.active = destRenderTexture;

var exportTexture = new Texture2D(destRenderTexture.width, destRenderTexture.height, TextureFormat.ARGB32, false, linear);
TextureFormat format = TextureFormat.ARGB32;
if (outputPath.EndsWith(".exr")) format = TextureFormat.RGBAFloat;

var exportTexture = new Texture2D(destRenderTexture.width, destRenderTexture.height, format, false, linear);
exportTexture.ReadPixels(new Rect(0, 0, destRenderTexture.width, destRenderTexture.height), 0, 0);
exportTexture.Apply();

var binaryData = outputPath.EndsWith(".jpg") ? exportTexture.EncodeToJPG(settings.DefaultJpegQuality) : exportTexture.EncodeToPNG();
byte[] binaryData;
if(outputPath.EndsWith(".jpg"))
binaryData = exportTexture.EncodeToJPG(settings.DefaultJpegQuality);
else if(outputPath.EndsWith(".png"))
binaryData = exportTexture.EncodeToPNG();
else if (outputPath.EndsWith(".exr"))
binaryData = exportTexture.EncodeToEXR(Texture2D.EXRFlags.CompressZIP);
else
{
Debug.LogError("Unsupported file extension: " + outputPath, destRenderTexture);
binaryData = exportTexture.EncodeToPNG();
}

File.WriteAllBytes(outputPath, binaryData);

RenderTexture.ReleaseTemporary(destRenderTexture);
Expand Down

0 comments on commit ccaa589

Please sign in to comment.