When writing our own custom Lighting functions in Cg, we define a function that receives: in float3 lightDir and in float3 viewDir. I cannot work out from the docs whether those vectors are passed in normalized form or not. I need to have them in normalized form which I can do myself in Cg but I wouldn’t want the resulting built output shader to do the same “2x normalize()” work twice per pixel…
Yes, both are normalized per-pixel. Here’s a relevant bit from the generated code of a surface shader:
// call surface function
surf (surfIN, o);
#ifndef USING_DIRECTIONAL_LIGHT
fixed3 lightDir = normalize(IN.lightDir);
#else
fixed3 lightDir = IN.lightDir;
#endif
fixed4 c = LightingBlinnPhong (o, lightDir, normalize(half3(IN.viewDir)), LIGHT_ATTENUATION(IN));
Muchos gracias! I guess you did “open compiled shader” to check? Did the same meanwhile too at my end IN.viewDir is always passed normalized too, BUT unlike your setup, in my version IN.lightDir is never normalized (checked all permutations in the compiled-shader file) strangely. Well it probably is already normalized pre-shading at the CPU side (I’m not doing anything crazy with the dir light). Anyway, good to know… cheers