I’m working on a surface shader right now that uses the object’s world normal to calculate whether or not it should be covered by snow:
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = tex2D(_MetallicGlossMap, IN.uv_MainTex).r * _Metallic;
o.Smoothness = tex2D(_MetallicGlossMap, IN.uv_MainTex).a *_Glossiness;
if (dot(o.Normal, _SnowAngle.xyz) >= _SnowSize - 0.4) { // if dot product result is higher than snow amount, we turn it into snow
float snowAmount = saturate((dot(o.Normal, _SnowAngle.xyz) - (_SnowSize - 0.4))/_SnowTimes);
float4 snowColor = (lerp(_SnowColor, _TColor, snowAmount)); // blend base snow with top snow based on position
o.Albedo = (snowColor * snowAmount + c.rgb * (1 - snowAmount))*tex2D(_SnowTex, IN.uv_MainTex);
o.Metallic = _SnowGloss;
o.Smoothness = _SnowMetallic;
}
//o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Alpha = c.a;
}
This works fine, but if I un-comment the line setting the normal, the shader uses the normal map instead of the mesh’s world normals even though that code happens after the snow calculation.
I’m wondering if there’s a way to access the mesh’s world normals in a surface shader so I can use it independently from the final, rendered normals that use the normal map.
Thanks!