Sign in to follow this  
pseudomarvin

Attribute interpolation for new vertices after clipping in homogenous clip space

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

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

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
Yes, you can linearly interpolate in homogeneous clip space since the MVP is a linear transformation in 4d. Unfortunately I can't think of a better reference than my own software rasterizer but I'm sure googling would be useful as it was for myself: https://github.com/loreStefani/SoftRP/blob/master/SoftRP/SHClipper.cpp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this