1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-01-09 02:43:25 +08:00

14 lines
520 B
Plaintext
Raw Normal View History

2024-03-26 10:59:07 +05:30
float ray_march(vec3 ray_origin, vec3 ray_dir, int max_steps, float max_dist, float dist_threshold, float signed_dist) {
ray_dir = normalize(ray_dir);
dist_threshold = abs(dist_threshold);
float dist_from_origin = 0.;
float dist_to_surface;
for(int i = 0; i < max_steps; i++) {
vec3 point = ray_origin + dist_from_origin * ray_dir;
dist_to_surface = signed_dist;
dist_from_origin += dist_to_surface;
if(dist_to_surface < dist_threshold || dist_to_surface > max_dist)
break;
}
return dist_from_origin;
}