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?

  • 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$ – Quinchilion Jun 14 '16 at 17:48

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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