- Home /
Specular bug on iOS/Android using Standard shader
I am experiencing some strange artifacts when I use the Standard shader (specular or metallic workflow, doesn't matter) on mobiles. It happens on both metal and gles3 renderers and I think that it's relevant to this post: http://forum.unity3d.com/threads/bug-specular-highlights-on-mobile.296914/
Here is what it looks like on device:
This is what it looks in the editor as a comparison: I did a framegrab when using the gles3 renderer and the fragment shader is the following:
void main()
{
t16_0.x = dot(vs_TEXCOORD1.xyz, vs_TEXCOORD1.xyz);
t16_0.x = inversesqrt(t16_0.x);
t16_9.xyz = (-vs_TEXCOORD1.xyz) * t16_0.xxx + _WorldSpaceLightPos0.xyz;
t16_1.xyz = t16_0.xxx * vs_TEXCOORD1.xyz;
t16_0.x = dot(t16_9.xyz, t16_9.xyz);
t16_2 = max(t16_0.x, 0.00100000005);
t16_0.x = inversesqrt(t16_2);
t16_0.xyz = t16_0.xxx * t16_9.xyz;
t16_27 = dot(_WorldSpaceLightPos0.xyz, t16_0.xyz);
t16_2 = max(t16_27, 0.0);
t16_27 = t16_2 * t16_2;
t10_11.xy = texture(_MetallicGlossMap, vs_TEXCOORD0.xy).xw;
t16_28 = (-t10_11.y) + 1.0;
t16_3.x = t16_28 * t16_28;
t16_27 = t16_27 * t10_11.y + t16_3.x;
t16_27 = t16_27 * unity_LightGammaCorrectionConsts.z;
t16_2 = t16_27 * t16_2 + 9.99999975e-05;
t16_27 = dot(vs_TEXCOORD4.xyz, vs_TEXCOORD4.xyz);
t16_27 = inversesqrt(t16_27);
t16_3.xyz = vec3(t16_27) * vs_TEXCOORD4.xyz;
t16_0.x = dot(t16_3.xyz, t16_0.xyz);
t16_29 = max(t16_0.x, 0.0);
t16_0.x = log2(t16_29);
t16_9.x = (-t16_28) + 1.0;
t16_18 = log2(t16_28);
t16_18 = t16_18 * 0.75;
t16_18 = exp2(t16_18);
t16_18 = t16_18 * 7.0;
t16_9.x = t16_9.x * 0.967999995 + 0.0299999993;
t16_9.x = log2(t16_9.x);
t16_9.x = 10.0 / t16_9.x;
t16_9.x = max(t16_9.x, -255.936996);
t16_27 = t16_9.x * t16_9.x;
t16_9.x = t16_9.x * t16_9.x + 1.0;
t16_0.x = t16_0.x * t16_27;
t16_0.x = exp2(t16_0.x);
t16_0.x = t16_0.x * t16_9.x;
t16_2 = t16_0.x / t16_2;
t16_0.x = max(t16_2, 0.0);
t16_0.x = min(t16_0.x, 100.0);
t10_4.xyz = texture(_DetailAlbedoMap, vs_TEXCOORD0.zw).xyz;
t16_5.xyz = t10_4.xyz * unity_ColorSpaceDouble.xyz;
t10_2.x = texture(_DetailMask, vs_TEXCOORD0.xy).w;
t16_9.x = (-t10_2.x) + 1.0;
t16_5.xyz = t16_5.xyz * t10_2.xxx + t16_9.xxx;
t10_4.xyz = texture(_MainTex, vs_TEXCOORD0.xy).xyz;
t16_4.xyz = t10_4.xyz * _Color.xyz;
t16_6.xyz = t16_5.xyz * t16_4.xyz;
t16_5.xyz = t16_4.xyz * t16_5.xyz + (-unity_ColorSpaceDielectricSpec.xyz);
t16_5.xyz = t10_11.xxx * t16_5.xyz + unity_ColorSpaceDielectricSpec.xyz;
t16_9.x = (-t10_11.x) * unity_ColorSpaceDielectricSpec.w + unity_ColorSpaceDielectricSpec.w;
t16_6.xyz = t16_9.xxx * t16_6.xyz;
t16_9.x = (-t16_9.x) + 1.0;
t16_9.x = t16_9.x + t10_11.y;
t16_9.x = clamp(t16_9.x, 0.0, 1.0);
t16_7.xyz = (-t16_5.xyz) + t16_9.xxx;
t16_0.xyw = t16_0.xxx * t16_5.xyz + t16_6.xyz;
t16_0.xyw = t16_0.xyw * _LightColor0.xyz;
t16_3.w = 1.0;
t16_8.x = dot(unity_SHAr, t16_3);
t16_8.y = dot(unity_SHAg, t16_3);
t16_8.z = dot(unity_SHAb, t16_3);
t16_8.xyz = t16_8.xyz + vs_TEXCOORD5.xyz;
t10_2.x = texture(_OcclusionMap, vs_TEXCOORD0.xy).y;
t16_28 = (-_OcclusionStrength) + 1.0;
t16_28 = t10_2.x * _OcclusionStrength + t16_28;
t16_8.xyz = vec3(t16_28) * t16_8.xyz;
t16_6.xyz = t16_6.xyz * t16_8.xyz;
t16_30 = dot(t16_3.xyz, _WorldSpaceLightPos0.xyz);
t16_2 = max(t16_30, 0.0);
t16_0.xyw = t16_0.xyw * vec3(t16_2) + t16_6.xyz;
t16_30 = dot(t16_3.xyz, (-t16_1.xyz));
t16_2 = max(t16_30, 0.0);
t16_30 = (-t16_2) + 1.0;
t16_30 = t16_30 * t16_30;
t16_30 = t16_30 * t16_30;
t16_5.xyz = vec3(t16_30) * t16_7.xyz + t16_5.xyz;
t16_30 = dot(t16_1.xyz, t16_3.xyz);
t16_30 = t16_30 + t16_30;
t16_1.xyz = t16_3.xyz * (-vec3(t16_30)) + t16_1.xyz;
t10_2 = textureLod(unity_SpecCube0, t16_1.xyz, t16_18);
t16_18 = t10_2.w * unity_SpecCube0_HDR.x;
t16_1.xyz = t10_2.xyz * vec3(t16_18);
t16_1.xyz = vec3(t16_28) * t16_1.xyz;
SV_Target0.xyz = t16_1.xyz * t16_5.xyz + t16_0.xyw;
SV_Target0.w = 1.0;
return;
}
It looks like an exp2(log(a)) optimisation is applied instead of a pow(nh, specularPower), could that be an issue? Has anyone else been experiencing these issues?
Many thanks and sorry for the low-res screenshots, I hope they illustrate the issue correctly.
Answer by JelmerV · Aug 24, 2017 at 09:13 AM
Do you think this is the same bug/problem? Any updates btw? I am considering disabling specular highlights and creating a plane based sunflare to imitate specular highlights.... I am using a reflection probe anyway...
https://forum.unity3d.com/threads/standard-shaders-specular-on-ios-has-artifacts.489816/