User Clipping planes on GF4

Ti 4600.

I’ve trying to render my scene to a texture for a water effect. It works well, but i need one user-defined clipping plane to avoid drawing pixels over the water plane, when drawing the reflection.

I thought that clipping planes were hardware accelerated at the expense of 1 TMU for 2 clip planes. I only use TMU0 for diffuse texture maps, and it’s slow as hell. We’re speaking of a framerate drop from 100 fps to 5 fps here, with standard opengl calls or with VAR, no matter.

I could use pixel shaders and the texkill instruction to do that, but i want to know if there’s a work around first. It just seems overkill to use pixel shaders for that SIMPLE effect! Maybe a ZBuffer trick? Any idea?


On Geforce3/4, geometry-based clip planes are slow. It sucks. If you want to clip geometry, it’s better to do it yourself before sending it to the card.

If you want to use texture units and auto texcoord generation to clip geometry, you have to set it up explicitly, not through the glClipPlane mechanism.

– Zeno

I found that you can use the near clip pane as an arbitrary plane by modifying your projection matrix like this:

p[0][2] = plane.x
p[1][2] = plane.y
p[2][2] = plane.z + 1
p[3][2] = -plane.w

This is for an infinite projection matrix (no far clip pane).
As you would expect, z precision suffers at grazing angles and if you work it out you’ll see that this matrix doesn’t always use the full upper NDC range for depth, I have come up with a way to improve this but it’s kind of messy. I know it’s not a very complete answer but it works. I wanted to research it more but I haven’t had the time. I have done some research and I do use it so I suppose I could tell you a little more if you want.
I also have a ti 4600 but I’m quite confident it’ll work on any card (it’s just a matrix).

P.S. forget user clip planes on consumer hardware, the terrible performance is the least of it, try doing some multipass…

I’m pretty certain slow performance on user clip planes is a nVidia thing only. Several ATi demos use it and it seams to be fast enough.

Thanks for the answers. I have no speed loss on ATI cards, only NVidia. Madoc, i tried your projection matrix trick, and it works to some extent… but there’s some horrible kind of popping ( i suppose Z-Fighting ) in the reflection, and i haven’t find any good set of parameters to lessen it. It’s just not usable as it is now :frowning: Zeno, i can’t do the clipping myself, it would just be too slow (the scene is non-trivial). How do you set up explicitly a clip plane ( i just need one ) ?


I use stencil buffer when I draw the water plane …

Did anyone get user defined clipping planes to even work with ARB_vertex_program (with position invariant option) on nVidia HW?

Gdo, i also use the stencil buffer, but that is not the problem. You need to clip the geometry that is under the water level (or upper the water level when it’s reflected) to get correct reflections.


Can’t you just use an 1d-texture and alpha test to do the clipping? You know, like what you would do to eliminate backprojection with projected shadow textures.

Basically use eye-linear texGen and an 1d-texture with nearest filtering to give zero alpha to fragments below the water level.


I used a user clipping plane in this demo: – runs at 140 fps on my GF4…

– Tom

Ahah! Interesting. Indeed your demo runs at 140 fps. What’s even more interesting is that using VAR kills the framerate. I tried to use a display list as you, and the framerate is sensibly better, but there’s still a pretty big slowdown when you’ve got user clipping planes enabled.

I don’t have Delphi, but can you try that: increase the density of your mesh (my scene is 16k; i doubt your terrain is more than 4k, right? If as i’m guessing clipping planes are supported in software, you won’t see such a slowdown with a simple scene), and try to comment out the glClipPlane call. Obviously you won’t see the correct results, but can you tell what the speed difference is ?


over 350fps here with fsaa and all and stuff.
but the texture is applied wrong, the reflection is not where it should be…

Looks fine for me on my 9700. 350 fps too.

The clipping texture + alpha test does the trick pretty well, at no loss of speed, with VAR. Thanks everybody!


Software emulation indeed. I tried with a 50K-triangle terrain and got a huge speed difference when enabling/disabling the clipping plane. Your using VAR obviously made things even worse because it has to read the vertices from video memory before it can do clipping on the CPU.

So why is it that back in the days of the original GeForce, NVIDIA claimed you could get HW clipping planes at the cost of a texture unit? Was this supported for the NV10 family of chips but not for the NV20s?

– Tom