Jump to content
  • Advertisement
Sign in to follow this  
pseudomarvin

Attribute interpolation for new vertices after clipping in homogenous clip space

This topic is 654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am implementing SW rasterization. I want to clip triangles against the z = -near (so that strange things don't happen after the perspective divide). I would like to do the clipping right after the vertex shader - that is right after the vertices are multiplied by the MVP matrix and before they are divided by the w coordinate (they are in homogenous clip space), so I would really clip against the z = -w plane. However, after clipping the triangles, new vertices have to be created replacing the clipped ones. Attribute values for these new vertices have to be interpolated based on the distance of the clipped vertex to the z = -w plane relative to the total length of the edge that was clipped.

 

I know that if I clipped in view space I could get away with simple linear interpolation of the vertex attributes. Is this still true in homogenous clip space (since we have not done perspective division yet)?

Share this post


Link to post
Share on other sites
Advertisement

You can't use linear interpolation in screen space for attributes which aren't linear in screen space (e.g. UV, position, normal etc.).

 

BTW you need also some guard-bard (clipping against offseted frustum sides). Without guard-band you will have precision issues when interpolating attributes.

Edited by Krzysztof Narkowicz

Share this post


Link to post
Share on other sites

Yeah, thanks. I guess I use a guard band (clamp the raster space coordinates to 0, width -1 or height - 1) and use Floating Point arithmetic so actually an infinite guard band.

Share this post


Link to post
Share on other sites

Guard-band's idea is that you reduce amount of clipping to minimum. You clip only if a triangle intersects near plane or intersects massively offseted frustum sides. In your case it look like you will be clipping more triangles, as you clip with non-offseted frustum sides.

 

This is just an explanation what's is guard band. It's not crucial for a fast rasterizer, as clipping is a relatively rare operation. The crucial part is to do some clipping with (offseted or not) frustum sides, so your interpolation math won't explode.

Share this post


Link to post
Share on other sites

@IoreStefani you are 100% correct, sorry pseudomarvin for the misinformation. I just checked my own clipper and I'm also doing linear interpolation in homogeneous space.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!