- Home /
Question by
jatobu · Sep 21, 2012 at 04:05 AM ·
shaderlabsurfaceshader
Shader Error: multiplying worldNormal * texture.rgb
I was trying to use worldNormals and NormalMap into a surface shader, but I came into an error where I can't use in the same equation the worldNormal and the texture's rgb values (either directly or indirectly).
Here's the simplest shader I could make so you can see the error by yourselves:
Shader "MyShaders/TestShader" {
Properties {
_MainTex ("Diffuse Map", 2D) = "white" {}
_NormalMap ("Normal Map", 2D) = "bump" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Custom
half4 LightingCustom( SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
return half4(0,0,0,0);
}
struct Input
{
float2 uv_MainTex;
float2 uv_NormalMap;
float3 worldNormal;
INTERNAL_DATA
};
sampler2D _MainTex;
sampler2D _NormalMap;
void surf(Input IN, inout SurfaceOutput o)
{
half3 worldNormal = WorldNormalVector( IN, float3(0,0,1) );
half3 dN = dot( worldNormal, half3(1,0,0) );
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb * dN; // ERROR HERE: sends error when multiplied * dN, otherwise it doesn't
o.Normal = UnpackNormal( tex2D(_NormalMap, IN.uv_NormalMap) );
}
ENDCG
}
Fallback "Diffuse"
}
Is there a reason why if I multiply ".rgb dN" sends a compile error, and if I just use ".rgb" alone or multiply it by any constant (like ".rgb 0.5") it works ok?..
is this a bug of the compiler? or am I doing something wrong?
Thanks!
Comment
Your answer
