Slicing an object relative to it's position

Hi I have a 3D irregular shaped object rendering using the model view projection method and I’m having trouble figuring out how to make it so that a percentage of the object is sliced below a certain y threshold regardless of it’s orientation.
I’ve tried two methods, one being passing the position data from vertex → fragment and checking if the y is less than 0.5f then discard but this doesn’t translate well when rotating the object. I tried getting the dot product of the model and position and then passing that but that didn’t really change much either.
If anyone could help out or point me in the right direction it would be greatly appreciated!

You can either do this in the fragment shader by discarding fragments based upon Y coordinate, or you can use clipping planes (glEnablei(GL_CLIP_DISTANCE, n) and set gl_ClipDistance[n] in the vertex shader.

Either way, you need to use the correct coordinate system. If you’re trying to slice in object space, the clip distance needs to be calculated using object-space coordinates and an object-space plane; a fragment shader would need to have object-space coordinates passed in.

Yeah so I’m having trouble figuring out the correct coordinate system to perform the Y check, I’ve tried simply passing the vertex position to the fragment but that cuts the object in half statically but I want it to change based on the models rotation/orientation. (i.e if its 90 degrees rotated to the right then I want the model to be cut 50% horizontally as apposed to vertically)

If you want the cutting plane fixed relative to the object, use object-space coordinates; i.e. those passed into the vertex shader from the attribute arrays, without any transformation.

If you want the cutting plane fixed relative to the viewpoint, use eye-space coordinates; i.e. after transformation by the model-view matrix, before transformation by the projection matrix.

If you want the cutting plane fixed in world space, you need to split the model-view matrix into model and view matrices and use the coordinates after transformation by the model matrix, before transformation by the view matrix.

Either way, using a clip plane is likely to be more efficient than discarding individual fragments in the fragment shader.