HLSL What you get when you subtract world position from InvertViewProjection.Transform?
- by cubrman
In one of NVIDIA's Vertex shaders (the metal one) I found the following code:
// transform object normals, tangents, & binormals to world-space:
float4x4 WorldITXf : WorldInverseTranspose < string UIWidget="None"; >;
// provide tranform from "view" or "eye" coords back to world-space:
float4x4 ViewIXf : ViewInverse < string UIWidget="None"; >;
...
float4 Po = float4(IN.Position.xyz,1); // homogeneous location coordinates
float4 Pw = mul(Po,WorldXf); // convert to "world" space
OUT.WorldView = normalize(ViewIXf[3].xyz - Pw.xyz);
The term OUT.WorldView is subsequently used in a Pixel Shader to compute lighting:
float3 Ln = normalize(IN.LightVec.xyz);
float3 Nn = normalize(IN.WorldNormal);
float3 Vn = normalize(IN.WorldView);
float3 Hn = normalize(Vn + Ln);
float4 litV = lit(dot(Ln,Nn),dot(Hn,Nn),SpecExpon);
DiffuseContrib = litV.y * Kd * LightColor + AmbiColor;
SpecularContrib = litV.z * LightColor;
Can anyone tell me what exactly is WorldView here? And why do they add it to the normal?