6
$\begingroup$

I'm currently writing a software rasterizer and I'm at the point where I can draw arbitrary triangles with vertex colors and perspective correct texture mapping. I do point and directional lighting by linearly interpolating the vertex normals and it works fine, only on big triangles you can notice that the lighting is somehow distorted when viewed from a very flat angle. However, this is only visible when you're particularly looking for it but I was wondering if there is a way to have perspective correction on the normals too.

For the texture coordinates and other stuff this is being done by dividing the value by W or Z. But if you divide a vector by a single number you only change its magnitude, which is useless, as I'm normalizing the vector in the end for the lighting computation. So, is there a way to do it perspective correct?

$\endgroup$
1
  • 7
    $\begingroup$ Dividing normals by w is not useless, because it affects the interpolation. The values are weighed differently. Even if you normalize after the interpolation, it gives different results than if you didn't divide by w. Perspective correct interpolation for normals is the same as for any other surface attribute. $\endgroup$ Jun 14, 2016 at 17:48

1 Answer 1

2
$\begingroup$

Perspective correct interpolation of normals works just as it does any color or coordinate or other linearly varying attribute. Each component of each varying vector is interpolated independently as if they were scalars, using exactly the same equation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.