HLSL What you get when you subtract world position from InvertViewProjection.Transform?
Posted
by
cubrman
on Game Development
See other posts from Game Development
or by cubrman
Published on 2013-11-01T13:23:30Z
Indexed on
2013/11/01
16:23 UTC
Read the original article
Hit count: 259
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?
© Game Development or respective owner