1
\$\begingroup\$

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?

PS. Error in the last sentence - they add it to the light vector.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

It is view direction, last row of inverted View matrix is simply camera position.

\$\endgroup\$
2
  • \$\begingroup\$ Ok, so what do I get when I add view direction to the light direction? And why do they dot it with normal afterwards? \$\endgroup\$
    – cubrman
    Commented Nov 1, 2013 at 17:34
  • \$\begingroup\$ Damn I got it those are the components of the standard light equation. \$\endgroup\$
    – cubrman
    Commented Nov 1, 2013 at 17:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .