# Attribute interpolation for new vertices after clipping in homogenous clip space

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

## 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 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 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 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 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 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 on other sites

Thanks for the clarification :) .

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013294
×