3/30/2007

Problems solved.

Dr.Zovil made some stupid mistakes in vector & matrix math. Let's take a look at what went wrong.

normalizing vectors in 'vertex shader' >> Gouraud shading

float3 worldVertPos = mul(float4(IN.position,1.0f), world).xyz ;
//it's OK.
float3 lightVector = normalize(float4(lightPos - worldVertPos, 1.0f)) ;
//lightPos is float4-type and worldVertPos is float3-type. One of them shoud be matched to
//the other like this.
//float3 lightVector = normalize(lightPos.xyz - worldVertPos) ;
float3 worldNormal = normalize(mul(IN.normal, worldInverseTranspose));
// IN.normal is float3-type and worldInverseTranspose is a 4X4 matrix. IN.normal should be changed
//to float4-type, lke this.
// float3 worldNormal = normalize((mul(float4(IN.normal, 1.0), worldInverseTranspose)).xyz);

In the case of 'phong shading', the same mstakes are repeated.
When every errors seemed to be corrected, they worked as expected.
Here are the corrected version of two shaders,

vectors normalized in vertexShader.

vectors normalized in pixelShader.

and rendered images. Polygon edges are more visible in the former case.
Aren't they traces of interpolation between per-vertex illuminated values?




No comments:

Tag