Sign in to follow this  
d000hg

Possible to fake simple boolean geometry operations using shaders?

Recommended Posts

d000hg    1199
In 3D modelling programs, you can have solid objects, rather than hollow polygon shells. You can cut them in two, or subtract a sphere, etc, and new surfaces are generated to fill the gaps. Is it possible to do this using a shader in real-time? I really would only need to do this with a plane - so imagine simply slicing a model and throwing one half away. It's easy to have a shader to only draw the pixels in the model on one side of the plane, but the tricky part is filling in the big gap. The idea in my head is to render the slicing plane first, and then render the rest of the model, somehow leaving the slice-plane only where it is needed. Can someone comment on this idea, is it viable? If so, any thoughts on a more detailed algorithm would be appreciated, since shaders are not my strongest area.

Share this post


Link to post
Share on other sites
WarAmp    750
Draw your object, discarding pixels that would be cut by the plane. Write to the stencil/alpha buffer where this occurs.

Draw the slicing plane, but only draw where the stencil/alpha buffer is set to the value you chose above.

Share this post


Link to post
Share on other sites
SaltyGoodness    128
The technique you're after is image space CSG, there's a few papers on the internets that should be enough to get you started. This one seems to have some easy to follow (pseudo)code.

I'm pretty sure that you have to use manifold geometry for them to work, so you'd have to render a large enough box instead of a plane.

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