clipping planes

Hi all.
I just transformed my mirror reflections to glsl, but my clipping planes are not working any more. How do you clip planes in glsl?

I have :
glEnable(GL_CLIP_PLANE0);
double eqr[]={plane[0],plane[1],plane[2],plane[3]}
glClipPlane(GL_CLIP_PLANE0,eqr);
change_shader();
render_scene();

What should I write to my vertex part to clip my scene by plane?

Thx for answers.

Clip planes should still work the same. I don’t see why GLSL should change anything. Unless of course you no longer use the modelview and projection matrix. Don’t forget that clipping is done in post-perspective space, and that these matrixes matter at plane specification time.

Finally I got it work.

I think that problem is in nvidia drivers (i’ve got FX5200)for linux. If I turn shader off it works.

Anyway I implemented checking side of plane in vertex/fragment program :

vertex:
side=plane[0]*gl_Vertex.x+plane[1]*gl_Vertex.y+plane[2]*gl_Vertex.z+plane[3];

fragment:
if (side>0)
gl_FragColor = texture2D(textura1, texture_coordinate)*texture3D(textura3d,lc).x ;
else gl_FragColor.a=0;

So here is the screenshot of my reflection :slight_smile:

http://bydgoszcz.wsinf.edu.pl/~bloto/mojedziela/blotoengine44.jpg

Best regards.

So you’re using alpha test as I understand it now to kill fragments instead of using clip planes? I wouldn’t recommend that from a performance point of view, unless you can’t get it to work with real clip planes or get an updated driver.

I know that this solution is very slow (it takes 30% performance of my little scene) but this is I think the simplest way to do this without modyfing anything and waiting for new drivers :slight_smile: I will have to make simple application and test it with Windows to make sure I am right about the drivers. Anyway thank you for your interests.

I have exactly the same result in both systems - there is no clipping. It would be nice if someone could test it. I modified 26th NeHe lesson to work with simple shader. A small ball should be clipped after reaching the surface.

Here are the links :

Linux:
http://bydgoszcz.wsinf.edu.pl/~bloto/test/lesson26.zip

Windows:
http://bydgoszcz.wsinf.edu.pl/~bloto/test/lesson26_bcb6.zip

Hope this quote from the official glSlang-Specs clears things up :

The variable gl_ClipVertex is available only in the vertex language and provides a place for vertex shaders
to write the coordinate to be used with the user clipping planes. The user must ensure the clip vertex and
user clipping planes are defined in the same coordinate space. User clip planes work properly only under
linear transform. It is undefined what happens under non-linear transform.
So for the vertices to be clipped against your clipping planes, you’ll need to write their coordinates to (if I’m not mistaken…I’ve never done anything with clipping planes AND shaders) gl_ClipVertex.

Try the following:

  gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;

Already tried but no luck :frowning:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.