glTFast
glTFast copied to clipboard
Metallic & Specular shader color is black on mobile platform
- Unity 2021.3.1f1
- built in render pipeline
- Android platform build settings
- "ProjectSettings->Graphics->Standard Shader Quality" is set to "low".
Problem:
Metallic & Specular shader appear with a black diffuse color.
Reproduce:
- Set "ProjectSettings->Graphics->Standard Shader Quality" to "low".
- Test any 3D model which use metallic or specular setup gltf shader.
- Color is black
Technical details:
When mobile platform is set in build settings, usually "Standard Shader Quality" is set to "low".
ProjectSettings->Graphics->Standard Shader Quality
It enables UNITY_NO_FULL_STANDARD_SHADER keyword, which makes ForwardSimple shader feature to be use.
So then VertexOutputBaseSimple vertForwardBaseSimple (VertexInput v)
is used (glTFUnityStandardCoreForwardSimple.cginc)
But this function has a problem, it set the o.color BEFORE intialize o.color to zero.
Resulting on diffuse color looking black.
Solution:
in the function VertexOutputBaseSimple vertForwardBaseSimple (VertexInput v)
inside "glTFUnityStandardCoreForwardSimple.cginc".
move the following code to the end of the function after UNITY_INITIALIZE_OUTPUT(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