Hey guys I'm now trying to implement some vertex clipping in my software rasterizer.
I read about how this works on hardware using guard bands that basically define a much bigger viewport around the actual viewport and only clips in the rare case of a triangle having at least one vertex inside the actual viewport and at least one outside the guard band viewport.
So my idea is to define a viewport rectangle (minX, minY, maxX, maxY) and first check if the entire triangle is inside my actual viewport (i.e. using the transformed w coordinate of all 3 vertices)...
Because I know that the following cases can happen:
- The triangle is completely inside my viewport (trivially accept),which in contrast means if this is false then the triangle is either inside the guard band or even outside of it so we can safely skip this triangle.
- The triangle is partly inside my viewport and partly inside the guard band (trivially accept) because the rasterizer will not draw the parts that are outside the viewport anyway but we still need to rasterize the parts that are inside.
- The triangle is party inside my viewport and partly outside the guard band (nontrivial case), which means that this triangle actually needs to be clipped at the guard band rectangle.
Now here's my first problem (probably more to come ): Let me first quote fabian giesen real quick: "Note that there is no need for rasterizer coordinates to agree with render-target coordinates, and if you want to maximize the utility of your guard band region, your best bet is to translate the rasterizer coordinate system such that the center (instead of the top-left or bottom-right corner) of your viewport is near (0,0). Otherwise large viewports might have a much bigger guard band on the left side than they do on the right side (and similar in the vertical direction), which is undesirable."
Maybe this is trivial but it's a little unclear to me. How exactly do I do that translation ? And where ? Directly after vertex transform ? Or just before rasterizing ?
Update: I think his sentence is a little confusing because after thinking about it the only time I need these is when actually using the guard bands, which means only for clipping after vertex transform...
Edited by lipsryme, 04 January 2014 - 06:22 AM.