it's my first question on stack.
Is it possible to infer length of the half angle vector for specular lighting from N·L and N·V without the whole view and light vectors?
I may be completely off-track, but I have this gut feeling it's possible...
Why? I'm working on a skin shader and I'm already doing one texture lookup with N·L+N·E and one texture lookup for specular with N·H+N·V. The latter one can be transformed into N·L+N·E lookup if only I had the half vector length.
Doing so could simplify the shader a bit and move some operations into the pre-computed lookup texture.
It would make a huge difference since I'm trying to squeeze as much functionality as possible to a single pass mobile version so instruction count matters.
Thanks.
Edit, for clarity, I'm doing something like this:
float NdotL = dot(s.Normal, lightDir);
float NdotE = dot(s.Normal, viewDir);
fixed3 diffAndTransl = 2.0 * tex3D(_Lookup3d, half3(diffNdotL, NdotE * 0.5 + 0.5, depth)).rgb;
now we have diffuse with SSS and backscattering from lookup everything below could be just a lookup if I had length(h) information when calculating the lookup
float3 h = lightDir + viewDir;
float hLen = length(h);
//float3 H = normalize(h);
float3 H = h/hLen;
//float NdotH = dot(s.Normal, H);
float NdotH = (NdotL + NdotE)/hLen;
float EdotH = dot(viewDir, H);
fixed ph_by_fresnelReflectance = tex3D(_Lookup3d, half3(NdotH* 0.5 + 0.5, EdotH * 0.5 + 0.5, s.Gloss)).a;
half spec = saturate(NdotL) * max(ph_by_fresnelReflectance / hLensq, 0 ); // this could go into lookup as well
I was thinking I could infer length(h) from NdotL and NdotE when generating the specular lookup to reduce above code. In my mind I was imagining something like a triangle on the plane made by lightDir and viewDir vectors could be thought of in 2D space. Don't the two dot products give me the (half?) angle and since both vectors are of length one, wouldn't it be possible to infer the length of the last side? I tried some trigonometric voodoo programming but with no luck (chord of theta inferred from dot products?). Does anybody have any idea if it's at all possible? Maybe I just need to sleep more.
ps.: I know tex3D won't work well on mobile, just testing the grounds...