So, I have a shader which does parallax/normalmap blends in a snow texture on up-pointing normals.
I got this working fine with this shader:
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float3 viewDir;
//float3 worldNormal;
INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutput o)
{
half h = tex2D (_ParallaxMap, IN.uv_BumpMap).w;
float2 offset = ParallaxOffset (h, _Parallax, IN.viewDir);
IN.uv_MainTex += offset;
IN.uv_BumpMap += offset;
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
fixed3 snow = tex2D(_SnowMap, IN.uv_MainTex).rgb;
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
float snowFactor = saturate(dot(WorldNormalVector(IN, o.Normal)-_Adjust, _Direction.xyz));
snowFactor = pow (snowFactor, _Fresnel) ;
o.Albedo.rgb = lerp(o.Albedo.rgb, snow.rgb, snowFactor);
}
However when I came home to my slightly older macbook pro (nvidia 9600), then the normals seemed to be in “texture space”.
I had to uncomment worldNormal in the input struct.
This led to unity giving a warning about having too many interpolators. I removed the parallax part (and the viewDir inside the input struct). The shader compiles, but I don’t get the parallax then. The worldnormals seemed correct at least.
So, I have two questions:
-
Why is “worldNormal” required on one machine (my macbook pro) but not on my compute at work (2011 imac).
The shader compiles and runs on both, but it looks wrong on my macbook pro. -
Not being able to add two float3 values in the input structure seems rather limiting…Am I missing something, or will I have to create custom vertex/pixel shaders.
I do think it is practical using surface shaders since it works automatically with lightmaps and shadows.
Appreciate any input.
I attached a picture showing the shader on my work computer, and how it looked when I loaded it up on my home computer.