From c5b72d81b192e934163d1bbe2344fa467aeb39a8 Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Fri, 22 Apr 2022 23:17:12 +0200 Subject: [PATCH] fix: For projects using the built-in render pipeline in gamma color space, vertex colors are now applied in the correct color space --- ChangeLog.md | 1 + .../glTFIncludes/glTFUnityStandardCore.cginc | 15 +++++++++++++++ .../glTFUnityStandardCoreForwardSimple.cginc | 5 +++++ .../glTFIncludes/glTFUnityStandardMeta.cginc | 5 +++++ Runtime/Shader/Built-In/glTFUnlit.shader | 5 +++++ 5 files changed, 31 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index c54045fe..41ee6e11 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - (Export) Removed error messages about non-matching Profiler calls (#357) - (Export) Re-encoded (blitted) textures are in correct sRGB color space, even when the project is in linear color space (#353) - (Export) Removed incorrect color space conversion on normal maps (#346) +- For projects using the built-in render pipeline in gamma color space, vertex colors are now applied in the correct color space ## [4.6.0] - 2022-02-23 ### Added diff --git a/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardCore.cginc b/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardCore.cginc index 08e04927..2268e164 100644 --- a/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardCore.cginc +++ b/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardCore.cginc @@ -508,7 +508,12 @@ VertexOutputForwardBase vertForwardBase (VertexInput v) #endif UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o,o.pos); +#ifdef UNITY_COLORSPACE_GAMMA + o.color.rgb = LinearToGammaSpace(v.color.rgb); + o.color.a = v.color.a; +#else o.color = v.color; +#endif o.pointSize = 1; return o; } @@ -637,7 +642,12 @@ VertexOutputForwardAdd vertForwardAdd (VertexInput v) #endif UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o, o.pos); +#ifdef UNITY_COLORSPACE_GAMMA + o.color.rgb = LinearToGammaSpace(v.color.rgb); + o.color.a = v.color.a; +#else o.color = v.color; +#endif o.pointSize = 1; return o; } @@ -765,7 +775,12 @@ VertexOutputDeferred vertDeferred (VertexInput v) o.tangentToWorldAndPackedData[2].w = viewDirForParallax.z; #endif +#ifdef UNITY_COLORSPACE_GAMMA + o.color.rgb = LinearToGammaSpace(v.color.rgb); + o.color.a = v.color.a; +#else o.color = v.color; +#endif o.pointSize = 1; return o; diff --git a/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardCoreForwardSimple.cginc b/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardCoreForwardSimple.cginc index b438cae4..c8a9b01f 100644 --- a/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardCoreForwardSimple.cginc +++ b/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardCoreForwardSimple.cginc @@ -110,7 +110,12 @@ VertexOutputBaseSimple vertForwardBaseSimple (VertexInput v) { UNITY_SETUP_INSTANCE_ID(v); VertexOutputBaseSimple o; +#ifdef UNITY_COLORSPACE_GAMMA + o.color.rgb = LinearToGammaSpace(v.color.rgb); + o.color.a = v.color.a; +#else o.color = v.color; +#endif UNITY_INITIALIZE_OUTPUT(VertexOutputBaseSimple, o); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); diff --git a/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardMeta.cginc b/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardMeta.cginc index aaa62bce..30a84426 100644 --- a/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardMeta.cginc +++ b/Runtime/Shader/Built-In/glTFIncludes/glTFUnityStandardMeta.cginc @@ -41,7 +41,12 @@ struct v2f_meta v2f_meta vert_meta (VertexInput v) { v2f_meta o; +#ifdef UNITY_COLORSPACE_GAMMA + o.color.rgb = LinearToGammaSpace(v.color.rgb); + o.color.a = v.color.a; +#else o.color = v.color; +#endif o.pos = UnityMetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST, unity_DynamicLightmapST); o.uv.xy = TexCoordsSingle((_MainTexUVChannel==0)?v.uv0:v.uv1,_MainTex); diff --git a/Runtime/Shader/Built-In/glTFUnlit.shader b/Runtime/Shader/Built-In/glTFUnlit.shader index 2b3bf2aa..3d3acb84 100644 --- a/Runtime/Shader/Built-In/glTFUnlit.shader +++ b/Runtime/Shader/Built-In/glTFUnlit.shader @@ -80,7 +80,12 @@ SubShader { o.texcoord = TexCoordsSingle((_MainTexUVChannel==0)?v.texcoord0:v.texcoord1, _MainTex); UNITY_TRANSFER_FOG(o,o.vertex); +#ifdef UNITY_COLORSPACE_GAMMA + o.color.rgb = LinearToGammaSpace(v.color.rgb); + o.color.a = v.color.a; +#else o.color = v.color; +#endif o.pointSize = 1; return o; }