I’m attempting to modify the lightmapped terrain shader to add a specular component (using the splat textures’ alpha channel as a glossiness value, to boot).
However, any time I attempt to use the vertex normal, I get the following error message:
Shader wants normals, but the mesh doesn't have them.
I feel like I must be missing something here, because both the pixel-lit and vertex-lit terrain shaders do use the normal as part of their calculations. Is there something special I need to set to make Unity calculate those normals for a lightmapped terrain?
Here’s the relevant pieces of shader code, in case they matter:
Pass {
Tags { "LightMode" = "Pixel" }
CGPROGRAM
#pragma vertex SpecularSplatVertex
#pragma fragment SpecularSplatFragment
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#define TEXTURECOUNT 4
#include "splatting.cginc"
ENDCG
}
struct v2f_specular {
V2F_POS_FOG;
float4 uv[3] : TEXCOORD0;
float4 color : COLOR;
float3 normal;
float3 viewDir;
float3 lightDir;
};
float4 SpecularSplatFragment (v2f_specular i) : COLOR {
half4 splat;
SAMPLE_SPLAT(i, splat);
float4 spec = SpecularLight(normalize(i.lightDir), normalize(i.viewDir), i.normal, splat, splat.a, 1);
return spec;
}
v2f_specular SpecularSplatVertex (appdata_base v) {
v2f_specular o;
PositionFog( v.vertex, o.pos, o.fog);
CALC_SPLAT_UV(v.texcoord.xy);
o.normal = v.normal;
o.viewDir = ObjSpaceViewDir(v.vertex);
o.lightDir = ObjSpaceLightDir(v.vertex);
o.color = _ModelLightColor0;
return o;
}