From 12829892b262a0c7fcccba9198e5b6b31b2a8015 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 9 Jul 2020 13:02:31 +0200 Subject: Cleaning code --- resources/shaders/algorithms/raymarching.frag | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 resources/shaders/algorithms/raymarching.frag (limited to 'resources/shaders/algorithms/raymarching.frag') diff --git a/resources/shaders/algorithms/raymarching.frag b/resources/shaders/algorithms/raymarching.frag new file mode 100644 index 0000000..b8de515 --- /dev/null +++ b/resources/shaders/algorithms/raymarching.frag @@ -0,0 +1,26 @@ +// Requirements: +// #define MAX_STEPS 100 +// #define MAX_DIST 100. +// GetDist: (vec3 position) => float +// GetDist should return the closest object point distance from position (in the whole scene) + +/** + * Ray Marching algorithm + * Please take a look at: https://www.youtube.com/watch?v=PGtv-dBi2wE&t=1367s + * This function return the distance reached by the ray: + * - If dist=MAX_STEPS) + // We move the ray: + vec3 ray_position = ray_origin + ray_direction*dist_origin; + // We find the next closest point: + float closest_point = GetDist(ray_position); + // Increase the ray distance + dist_origin += closest_point; + // Check if we went to far or we are too close from a point (we hit a surface) + if(dist_origin>MAX_DIST || closest_point