Skip to content

Instantly share code, notes, and snippets.

@partybusiness
Created August 13, 2024 18:50
Show Gist options
  • Save partybusiness/33a0c9f4d508d12127d1bf2c954fe9ba to your computer and use it in GitHub Desktop.
Save partybusiness/33a0c9f4d508d12127d1bf2c954fe9ba to your computer and use it in GitHub Desktop.
Godot shader that displays a white circle based on a formula for distance between a line and a point
shader_type spatial;
render_mode unshaded;
uniform float _Radius = 1.;
//https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
float distance_between_point_and_line(vec3 ls, vec3 le, vec3 point) {
//ls = line start
//le = line end
//point = posiiton of point
float dis = length(cross((le-ls),(ls-point)))/length(le-ls);
return dis;
}
void fragment() {
ALBEDO.rgb = vec3(distance_between_point_and_line(EYE_OFFSET,EYE_OFFSET+VIEW,NODE_POSITION_VIEW)>_Radius?0.0:1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment