Skip to content

Commit

Permalink
Set linear export setting before accessing texture exporter settings …
Browse files Browse the repository at this point in the history
…for unknown textures

fixing colorspace for custom unknown shader texture properties
  • Loading branch information
marwie committed Oct 21, 2022
1 parent faa3e9f commit 0fb8d7f
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ private ImageId ExportImageInternalBuffer(UniqueTexture uniqueTexture, string te

if (!wasAbleToExport)
{
var sRGB = true;
var sRGB = !exportSettings.linear;

#if UNITY_EDITOR
if (textureSlot == TextureMapType.Custom_Unknown)
Expand All @@ -532,11 +532,10 @@ private ImageId ExportImageInternalBuffer(UniqueTexture uniqueTexture, string te
var height = uniqueTexture.GetHeight();

// TODO we could make sure texture size is power-of-two here
var destRenderTexture = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32, format);
GL.sRGBWrite = sRGB;

if (exportSettings.linear)
GL.sRGBWrite = false;
var destRenderTexture = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.Default, format);
var previousSRGBState = GL.sRGBWrite;
GL.sRGBWrite = sRGB;

var shader = GetConversionMaterial(exportSettings);
if (shader && shader.HasProperty("_SmoothnessMultiplier"))
Expand Down Expand Up @@ -575,7 +574,7 @@ private ImageId ExportImageInternalBuffer(UniqueTexture uniqueTexture, string te

RenderTexture.ReleaseTemporary(destRenderTexture);

GL.sRGBWrite = false;
GL.sRGBWrite = previousSRGBState;
if (Application.isEditor)
{
UnityEngine.Object.DestroyImmediate(exportTexture);
Expand Down

0 comments on commit 0fb8d7f

Please sign in to comment.