Question

I'm wondering if drawing of a triangle with dimensions partially out of the frustum will take longer than when I would calculate where the triangle is bound by the frustum and make a (probably two) new triangle to draw that one instead of the bigger triangle resulting in the same pixels getting changed.

So the question is are there fragment shaders run for positions that don't even exist on your screen? Or is the rasterization phase optimized for this issue.

Was it helpful?

Solution 2

This is entirely a driver thing. Any triangle that goes outside of the range is automatically handled by your driver, in theory by subdividing the triangle into two smaller ones; I doubt you will be able to do it faster than your GPU.

There are techniques used to optimize the triangles outside the drawing range without subdivision, though; you might specify a zone that won't need subdivision (sort of a border), and if the point happens to lie inside, special processing is issued, but in general it skips the unnecessary fragment computations.

TL;DR: trust your GPU on that.

OTHER TIPS

Modern GL hardware is really, really good at clipping triangles against the viewport.

The fragment shader will only run on pixels that survive the viewport clipping.

Don't try to do frustum culling at the triangle level, do it at the object/tile level. Your CPU and vertex shader units will thank you :)

Short answer:
No, the fragment shader won't run for pixels outside the frustum.
But what you should really worry about is the vertex shader. It will run even if the whole triangle is outside the frustum because the GPU can't predict (not that I know of a way) if the triangle will end up on the screen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top