Godot: is there a way for clipping planes?

Created on 28 Jan 2016  路  8Comments  路  Source: godotengine/godot

I want to create simple water but I want to cut meshes , I konw that camera can do this but it will cut(clip) in the normal of camera , but I want to clip in in another rotation, is there any way to clip meshes , you can see water shader from here.
in this blog author using these code to clip

Vector3 planeNormalDirection = new Vector3(0, 0, 1);
planeNormalDirection.Normalize();
Vector4 planeCoefficients = new Vector4(planeNormalDirection, -waterHeight);
Matrix camMatrix = reflectionViewMatrix * projectionMatrix;
Matrix invCamMatrix = Matrix.Invert(camMatrix);
invCamMatrix = Matrix.Transpose(invCamMatrix);
planeCoefficients = Vector4.Transform(planeCoefficients, invCamMatrix);
Plane refractionClipPlane = new Plane(planeCoefficients);
device.ClipPlanes[0].Plane = refractionClipPlane;
archived feature proposal rendering

Most helpful comment

It turns out that clipping planes can be emulated (with probably worse performance) using the discard keyword.

shader_type spatial;

uniform vec4 plane = vec4(1.0, 0.5, 0.0, 0.0);

bool culls(vec3 vertex, mat4 cam) {
    vec3 pos = (cam * vec4(vertex, 1.0)).xyz;
    return plane.x * pos.x
        + plane.y * pos.y
        + plane.z * pos.z
        + plane.w < 0.0;
}

void fragment() {
    if (culls(VERTEX, CAMERA_MATRIX)) {
        discard;
    }
    ALBEDO = vec3(1.0, 0.0, 0.0);
}

There's a video of this effect here: https://www.youtube.com/watch?v=9hiSy058-20

All 8 comments

no clipping planes in GLES2, and 3D engine will be rewritten this year, so not doing much more work for this

kicking to 3.1, where we might implement planar reflections

I guess it will have to wait again for the next milestone, as new rendering features are scheduled for when Vulkan support will be implemented.

Vulkan support is now planned for 4.0

It turns out that clipping planes can be emulated (with probably worse performance) using the discard keyword.

shader_type spatial;

uniform vec4 plane = vec4(1.0, 0.5, 0.0, 0.0);

bool culls(vec3 vertex, mat4 cam) {
    vec3 pos = (cam * vec4(vertex, 1.0)).xyz;
    return plane.x * pos.x
        + plane.y * pos.y
        + plane.z * pos.z
        + plane.w < 0.0;
}

void fragment() {
    if (culls(VERTEX, CAMERA_MATRIX)) {
        discard;
    }
    ALBEDO = vec3(1.0, 0.0, 0.0);
}

There's a video of this effect here: https://www.youtube.com/watch?v=9hiSy058-20

That's great but, wouldn't that mean you'd have to apply that shader to _every_ geometry instance in the scene (or a selected few)?

Yes, it's not a perfect solution

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akien-mga picture akien-mga  路  366Comments

ghost picture ghost  路  161Comments

adolson picture adolson  路  87Comments

alelepd picture alelepd  路  187Comments

nunodonato picture nunodonato  路  143Comments