From aac94e911b0bab8db5cdb5efb8d4d8f2d4072610 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 7 Jul 2020 06:40:50 +0200 Subject: Add code --- resources/fonts/arial.ttf | Bin 0 -> 296712 bytes resources/shaders/algorithms/ray_marching.glsl | 5 ++ resources/shaders/main.glsl | 77 +++++++++++++++++++++++-- resources/shaders/objects/sphere.glsl | 4 ++ 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 resources/fonts/arial.ttf create mode 100644 resources/shaders/algorithms/ray_marching.glsl create mode 100644 resources/shaders/objects/sphere.glsl (limited to 'resources') diff --git a/resources/fonts/arial.ttf b/resources/fonts/arial.ttf new file mode 100644 index 0000000..12cc15c Binary files /dev/null and b/resources/fonts/arial.ttf differ diff --git a/resources/shaders/algorithms/ray_marching.glsl b/resources/shaders/algorithms/ray_marching.glsl new file mode 100644 index 0000000..d984c0e --- /dev/null +++ b/resources/shaders/algorithms/ray_marching.glsl @@ -0,0 +1,5 @@ + + +RayMarching(vec3 ro, vec3 rd){ + +} \ No newline at end of file diff --git a/resources/shaders/main.glsl b/resources/shaders/main.glsl index 7d4067a..2888d56 100644 --- a/resources/shaders/main.glsl +++ b/resources/shaders/main.glsl @@ -18,9 +18,76 @@ uniform float time; out vec3 color; -void main(){ - vec2 coord=gl_FragCoord.xy/resolution; - coord-=0.5; - float d=length(coord); - color=vec3(d,1,1); + +#define MAX_STEPS 100 +#define MAX_DIST 100. +#define SURF_DIST .01 + +float GetDist(vec3 p) { + vec4 s = vec4(0, 1, 6, 1); + + float sphereDist = length(p-s.xyz)-s.w; + float planeDist = p.y; + + float d = min(sphereDist, planeDist); + return d; +} + +float RayMarch(vec3 ro, vec3 rd) { + float dO=0.; + + for(int i=0; iMAX_DIST || dS