Reputation: 21
In opengl we have glClipPlane() that takes a plane equation in the form Ax+by+Cz+D = 0. I have 6 such planes that forms a cube. But instead of showing the world inside the cube, I want to show the outside world. For example, if a sphere goes inside the cube it should clipped but when it comes out it shouldnt be. Not sure but has this something to do with drawing cube faces in clockwise direction so normal will be away from view?
Upvotes: 2
Views: 1012
Reputation: 41
I have used for clipping on original sample:GLdouble eqn1[4] = { 0.7, 0.7, 0.7, 0.0 }; and the result is:
I have used for clipping on original sample:GLdouble eqn1[4] = { -0.7,- 0.7, -0.7, 0.0 }; and the result is:
so you can use negative a,b,c,d for show each side of cube
Upvotes: 0
Reputation: 6525
This is kind of like what Bahbar suggested, but in only 3 passes. It'd still be kind of expensive, but you could:
If there were a second depth buffer, you could write the back of the cube into the second depth buffer and only render if the fragment is less than that, but greater than the first depth buffer. Then you could render the front of the cube into the depth buffer and then make a second pass over the scene to render things in front of the cube.
Upvotes: 0
Reputation: 162164
Unfortunately this is not possible the way OpenGL clip planes work. Since all clip planes are applied to vertices in your inverted cube case there'll always be at least 3 planes that clip.
This special behaviour of OpenGL clip planes thus gives you one important constraint: You can clip only into a convex region. A "inverted" cube however is not convex: In mathematical terms a convex set is a set where for any two given points of the set the (shortest) straight line between those points does not lie outside the set.
Upvotes: 3
Reputation: 18005
IvoDankolov does mention that flipping the coefficients changes the side of the clipping, but... Each additional clip plane clips more geometry, it never will allow you to limit the extent of a previous clip plane.
So in short, you can't use clip-planes to do what you're after (unless you start drawing your geometry 6 times, and use 1 clip-plane at a time, and deal with overdraw. That's darn expensive).
You can however, compute whether each fragment is inside or outside your cube directly in the fragment shader, and discard
the inside fragments accordingly. That essentially means implementing the clipping in the fragment shader.
Upvotes: 0
Reputation: 495
While I'm not familiar with the precise workings of opengl's clip planes, I assume it has to do with defining "clip" and "don't clip" half spaces - whether it is with the normal vector (A, B, C) or some similar fashion shouldn't be an issue.
Try flipping the equation on each of the planes ( -Ax -By -Cz -D = 0) . That should flip the orientation of the plane (unless opengl uses a completely different method for determining in-space and out-space).
Upvotes: 1