3

I have a simple test scene setup in a toy software rasterizer. I have a plane facing the +Z axis at the origin and the camera is facing -Z at Z=2. Everything works fine and looks good at that orientation but if I turn the camera to face -X it renders a distorted triangle long after the plane has left the view of the camera. I have been trying to debug this for weeks and can't find the problem. I assume I am missing somthing silly, maths are not my strong suit. I have check my matrix/vector math and it seems good to me.

Here is the realevent code: NOTE it's emited from the "ReadableC backend" of a toy language so the formating is a little strange. Also I am fully aware there are important parts of software rasterization that are missing i the implementation. It has been simplified to isolate the bug.

Relevant Source Code

  • 1
    It sounds like your triangles are being transformed so they can have Z < 0 when rotated into eye space. Usually you need to clip the triangle against a near plane to avoid this. – PaulHK Jun 27 '17 at 12:28
  • 2
    @PaulHK You should post that as an answer. – Dan Hulme Jun 27 '17 at 12:47
  • @PaulHK that should indeed be right. The clipping should happen before the perspective divide and after the projection transformation. So, I would indeed post that as an answer as Dan said. – bram0101 Jun 27 '17 at 16:24

0 Answers0