Last active
May 23, 2025 17:01
-
-
Save partybusiness/9ccd1e7624960be3f14ea4d3f3e1d81d to your computer and use it in GitHub Desktop.
cuts off part of the mesh above a y threshold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type spatial; | |
render_mode cull_disabled; | |
uniform float threshold = 0.0; | |
uniform vec3 direction = vec3(0.0, 1.0, 0.0); | |
// normal of dividing plane in model space | |
varying vec3 local_plane_normal; | |
// position in model space | |
varying vec3 local_pos; | |
// position of the dividing plane in view space | |
varying vec3 plane_pos; | |
// normal of the dividing plane in view space | |
varying vec3 plane_normal; | |
void vertex() { | |
local_plane_normal = normalize(direction); | |
local_pos = VERTEX; | |
// converts position of plane from model space to view space | |
plane_pos = (VIEW_MATRIX * MODEL_MATRIX * vec4(local_plane_normal * threshold, 1.0)).xyz; | |
// converts normal of plane from model space to view space | |
plane_normal = (VIEW_MATRIX * MODEL_MATRIX * vec4(local_plane_normal, 0.0)).xyz; | |
} | |
void fragment() { | |
if (dot(local_plane_normal, local_pos) > threshold) | |
discard; | |
if (!FRONT_FACING) { | |
NORMAL = plane_normal; | |
// finds intersection of line and plane | |
// where plane is dividing plane and line is view direction | |
float light_offset = dot((plane_pos - LIGHT_VERTEX), plane_normal) / dot(-VIEW, plane_normal); | |
LIGHT_VERTEX = LIGHT_VERTEX - VIEW * light_offset; | |
} | |
ALBEDO = vec3(0.2, 0.52, 0.8); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment