GHGL clipping plane attempt

Hi all!

For a big project I’m needing fast mesh slicing … but actually only for displaying purposes!
So, by some tips I’ve received, I’m trying to do it with GHGL.


The script:
GHGL clipping plane (22.1 KB)
This is actually less than 5 rows of code of addition from a fresh GL Mesh Shader component…
took me 4 hours… OpenGL is hard! :sob:

How can I set it so it render correctly also the back faces and doesn’t mess up the preview of other GH objects?

( Also, with really smaller importance, how can I feed GHGL a material? Is this possible? )


#version 330

layout(location = 0) in vec3 _meshVertex;
layout(location = 1) in vec3 _meshNormal;

uniform mat4 _worldToClip;
out vec3 normal;
out vec3 pos;

void main() {
  normal = _meshNormal;
  pos = _meshVertex;
  gl_Position = _worldToClip * vec4(_meshVertex , 1.0);


#version 330
uniform mat3 _worldToCameraNormal;
uniform vec3 _lightDirection[4];
uniform vec3 O;
uniform vec3 N;

in vec3 normal;
in vec3 pos;
out vec4 fragment_color;

void main() {
    float dist1 = dot(N,pos);
    float dist2 = dot(N,O);
    float dist = dist1-dist2;
    float stepval = step(0,dist);
  vec3 l = normalize(_lightDirection[0]);
  vec3 camNormal = _worldToCameraNormal * normal;
  float intensity = dot(l, normalize(;
  vec4 diffuse = vec4(1.0, 1.0, 1.0, 1.0);

  vec3 ambient = vec3(0.1, 0.1, 0.1) * diffuse.rgb;
  vec3 c = ambient + diffuse.rgb * abs(intensity);
  fragment_color = vec4(c, stepval);

Even a clean GL Mesh Shader component with alpha=0.5 have a glitchy preview…


I’ve not been brave enough to dive into shaders yet. Good luck with that! I wonder why you’re not using clipping planes? There’s a bunch of c# nodes floating around for creating and orienting clipping planes. I use one of them regularly and it works pretty well.

Yes, I know, I made one of them in the past.

But any clipping plane will clip all geometries on the rhino viewport, even normal GH previews…

I need a per-object solution. A “selective” clipping.
2022-03-19 16_22_52-Window
It sort of work, but there are wrong Z depths and/or normals… I don’t really understand.

@stevebaer can I ask your opinion here?

My other solution is using actual “phisical” Mesh-Plane splitting, and for that I’m putting up a fast c# multithreaded, but it will always be slower than openGL.
I just need a quick/responsive dynamic preview while the user move the controls (sliders, etc…)

Selective clipping per object is available in Rhino 8 if that is an option. There are still a number of bugs I’m working on for this, but I’m hoping to have them fixed in the next couple weeks.

That’s a good news! I can’t wait to use them…

But my situation is with rhino 7, and my customer will use my script in many different machines with rhino 7…

I’m trying to filter also from the Vertex tab but it results in a “sawtooth” cut of the mesh, obvjously…

Any trick here?

You will want to perform your clipping side test in the fragment shader and use the discard glsl instruction to throw away pixels that are clipped

1 Like

GHGL clipping plane (32.9 KB)

That’s it!
Thank you!! :star_struck:


Very useful!

GHGL clipping planes
GHGL clipping plane (42.7 KB)

Stuff like this would be sooo handy…
Awesome rhino!


Looks great. That style of clipping (boolean combinations of multiple planes) probably won’t be supported in Rhino 8 anyways so it’s good you were able to do it yourself.

@maje90 These days I’ve been working on Clipping Plane in GH and found this threat.

Just a thought, can GHGL clipping has view assigned/specified individually? (Top/Right/Front/3D)



Hi, sorry for not replying you earlier.
I know very little about OpenGL, almost nothing.
I barely put this thing up.

Maybe @stevebaer can help you, he created GHGL.