glsl raymarching code example
Example: glsl raymarching
float rayMarch(vec3 rayOrigin, vec3 rayDirection) {
float dist = 0.;
for (int i = 0; i < MAX_STEPS; i++) {
// map(vec3 point) return the min. dist from the scene
float step = map(rayDirection * step + rayOrigin);
d += step;
// collision check || no-collision check
if (step < .01 || dist > 100.)
break;
}
return dist;
}