Clip Planes

A clip plane fundamentally divides space into two halves: one half which is clipped (hidden from rendering), and one half which is rendered.

A common use case is when rendering reflections of flat mirror surfaces (such as water), to ensure that a camera that is rendering the reflected scene will only render the part of the scene that is above the surface of the mirror.

It is possible to have multiple clip planes enabled at the same time. This will cause multiple areas to be culled away. There is an implementation-specific limit on the number of clip planes that can be active at any one time.

A plane is defined by four coordinates. The first three represent the X, Y, Z of the plane’s surface normal. The last parameter is used to determine the origin point of the plane. You can create a plane either using three points, or by using a normal vector and an origin point:

// Create a plane going through these three points
LPlane plane((100, 0, 2), (100, 100, 2), (0, 100, 2));

// Create an identical plane pointing upward with a height of 2
LPlane plane((0, 0, 1), (0, 0, 2));

// Create the same plane by directly specifying its parameters
LPlane plane(0, 0, 1, -2);

Before we can use it as a clip plane, we need to place it in the scene graph. This is done by creating a PlaneNode:

LPlane plane(0, 0, 1, -2);
PT(PlaneNode) plane_node = new PlaneNode("plane", plane);
NodePath plane_np = render.attach_new_node(plane_node);

To see a debug representation of the plane, call show() on the resulting node path.

Finally, we can use set_clip_plane() in order to apply it to any node on which the clipping should take effect:


Internally, this will create a ClipPlaneAttrib and assign it to the node’s render state.


Clip planes work normally in the fixed-function pipeline and with the shader generator, but if you are using a custom shader, it is your responsibility to implement the effect of the clip planes. In GLSL shaders, you can use the built-in p3d_ClipPlane[] input, which contains the view-space coordinates of each active plane. One way to implement it is to put something like this in the fragment shader:

uniform vec4 p3d_ClipPlane[2];

// View-space vertex position passed in from vertex shader
in vec4 vpos;

void main() {
  if (dot(p3d_ClipPlane[0], vpos) < 0) {
  if (dot(p3d_ClipPlane[1], vpos) < 0) {

  // Rest of fragment shader