I’m fairly new to OpenGL and haven’t done anything with it in quite a while and never something this advanced. I need to be able to create an object essentially out of clip planes. The user will start off with a cube (or other simple starting shape) and be slicing off sections. I found a section on this site “Capping Clipped Solids with the Stencil Buffer” and that sounds just about exactly what I need but my end objects could end up having a couple of hundred planes (though more commonly 50-100). The scene itself will be very simple, this one object is it, no special textures or anything like that.
So, is that likely to work as expected? Starting with a cube and using clip planes and capping to cut it down to what I need? Will having that many clip planes be any serious performance problem? This is going to be a 3D modeling program of sorts so while performance matters, I don’t strictly need so many fps for a game.
Sounds like CSG or at least Computational Geometry.
Question: What do you want to see on the clip planes? A smooth surface? Or a voxelized step surface?
I’m going to assume the former, in which case I’d suggest that while you’d likely use OpenGL to interactively render the resulting shape, you wouldn’t use OpenGL to compute it. I mean, we’re talking about a bunch of plane-plane intersections to come up with vertices, edges, and faces.
Check out CGAL. I haven’t used it – only read some blog posts by folks that have. Hopefully others will chime in with other similar libraries.
I haven’t done much in the past so I’m not sure what a voxelized step surface even is yet. But plan flat surfaces are fine, no special effects required.
And I assume with that you’re assuming there would be significant performance problems?
I’m currently working on a proof of concept application to see how it would do but since I only worked on open GL for a few weeks about a year ago, I’ve forgotten pretty much all of it so am starting over from scratch. I won’t be able to see how or even if it’s possible for probably a couple of weeks. That’s why I’m hoping for a quick answer here that yes it most likely will or will not work.
I haven’t done much in the past so I’m not sure what a voxelized step surface even is yet. But plan flat surfaces are fine, no special effects required.[/QUOTE]
Something like this:
where you end up doing in/out tests per 3D cell (voxel) or point, yielding something like this:
or possibly even smoothed out some by applying marching cubes/tetrahedra/etc. instead of just per voxel in/out tests. Pretty sure you didn’t want this but wanted to be sure because this is something you can parallelize well on a GPU.
Sort of, yeah. It’s just not one of those things that intuitively would seem to parallelize really well. Might as well find the mesh on the CPU and then render it with the GPU. But then again, I’m not a GPGPU guy and there might be some amazing OpenCL/CUDA algorithm for this that runs circles around a CPU on the GPU.
The fact that you’re cutting with infinite planes I think implies you will end up with a convex polyhedra, which may mean there’s a pretty easy algorithm for coming up with the verts, edges, and faces. Maybe, for each plane, cull away any verts/edges/faces totally behind the plane, blast out all the intersections with all the existing edges, and retesselate affected faces.
Then again, maybe this would parallelize well on the GPU: that is, brute-force parallel-compute all the 3-plane intersection points, parallel-merge to a common point list, then brute-force parallel-cull the entire pointset against each plane. The remaining points are the verts of the convex polyhedra. Snap on a mesh (build edges/faces) and you’re done.