Graphics - Clipped triangles go all over the screen, and ones behind the camera show up like they were in front

StackOverflow https://stackoverflow.com/questions/22338779

  •  13-06-2023
  •  | 
  •  

Question

I'm trying to pass matrices from our game engine to a software rasterizer library. Our matrices are structured in the same way D3D expects them, if that matters.

The software rasterizer comes with example integration which works, but when we pass our matrices (which we transpose first, or nothing shows up at all) clipping stops working; triangles stretch over the screen as soon as one is clipped at the edge, and triangles behind the camera show up inverted as if they were in front of you.

The only matrix we don't pass in ourselves is the viewport matrix; we use the one created by the rasterizer which looks like this:

HALF SCREEN WIDTH,  0.0,                  0.0, 0.0, 
0.0,                -HALF SCREEN HEIGHT,  0.0, 0.0,
0.0,                0.0,                  1.0, 0.0,
HALF SCREEN WIDTH,  HALF SCREEN HEIGHT,   0.0, 1.0);

I tried transposing it (since that's what we had to do with all our other matrices) but then nothing shows up.

I'm a little bit confused because the clipper does (I checked) discard any vertex that has a negative W value. Are our problems due to the clipper not being able to handle all cases, or due to the way I pass my matrices?

Was it helpful?

Solution

I was wrong and the clipper indeed wasn't checking for negative W values. Why it worked with the example integration is beyond me, but at least it works for us now!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top