Jump to content

  • Log In with Google      Sign In   
  • Create Account

[Software Rasterizer] Vertex Clipping & Guard Bands


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 lipsryme   Members   -  Reputation: 1052

Like
0Likes
Like

Posted 03 January 2014 - 06:06 AM

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 tongue.png ): 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.


Sponsor:

#2 Tim J   Members   -  Reputation: 261

Like
1Likes
Like

Posted 04 January 2014 - 09:41 AM

I never got round to implementing this properly. My software rasterizer is floating-point, so I can get away with an essentially infinite guard band. If a triangle overlaps the viewport at all, then I rasterize the whole thing. However, because I'm using barycentric rasterization, when I create the screen-space bounds of the triangle, I simply clip the triangle bounds to the viewport bounds. So there's not a lot of extra overhead - obviously, there's a lot of overhead in using floating-point, not fixed-point, in the first place :)

 

To your question - I think Fabian Giesen meant that it could be done as an internal implementation detail in the rasterizer stage. Maybe when you're going from clip space to screen space - instead of using actual screen space, use the offset screen space that Giesen suggests. Then before generating the fragment / pixel coordinates, map back to real screen space. Possibly :)



#3 lipsryme   Members   -  Reputation: 1052

Like
2Likes
Like

Posted 04 January 2014 - 04:06 PM

@Tim: I actually do something similar with the clipping to viewport bounds and stuff but I was trying to implement actual vertex clipping if a vertex is outside the guard bands.

 

Anyhow I've managed to get it working (at least flawlessly with a single triangle smile.png ).

For those who might wanna know and/or found this years after tongue.png, this is how I do it :

 

I'm now translating my post transform coordinates to basically get [-1,1] coordinates and then check these with the guard band boundaries.

Then I count how many vertices are outside the guard band. If there's two vertices outside then it's an easy case where I just use the cohen-sutherland algorithm to find the two intersection points with the guard band boundary and just change the original position with the intersection point.

If there's just one vertex outside it gets a little trickier, because you now have to basically generate an additional triangle and "reconnect" the original vertices with the new ones from the intersections.


Edited by lipsryme, 04 January 2014 - 04:07 PM.


#4 Krypt0n   Crossbones+   -  Reputation: 2686

Like
1Likes
Like

Posted 04 January 2014 - 06:04 PM

the only moment you really need triangle clipping is before you do the perspective divide.

Once you are in the post-projective space, it's simpler to divide you triangle into 3 lines. 

then you can clip those lines if needed, afterwards just convert them into the fix-point format edge functions (as you did with triangles so far), this way you have less special cases -> it's nice and easy to pipeline/multithread.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS