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/main.frag | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 resources/shaders/main.frag (limited to 'resources/shaders/main.frag') diff --git a/resources/shaders/main.frag b/resources/shaders/main.frag new file mode 100644 index 0000000..590b849 --- /dev/null +++ b/resources/shaders/main.frag @@ -0,0 +1,59 @@ +#version 330 core + +uniform vec2 resolution; +uniform float time; + +out vec3 color; + +#define MAX_STEPS 100 +#define MAX_DIST 100. +#define SURF_DIST .01 +#define NORMAL_ACCURACY 0.01 + +#include "objects/sphere.frag" +float GetDist(vec3 p) { + float sphereDist = SphereSDF(p,vec3(0, 1, 6),1); + float planeDist = p.y; + + float d = min(sphereDist, planeDist); + return d; +} + +#include "algorithms/raymarching.frag" +#include "algorithms/normal.frag" + + + +float GetLight(vec3 p) { + vec3 lightPos = vec3(0, 5, 6); + lightPos.xz += vec2(sin(time), cos(time))*2.; + vec3 l = normalize(lightPos-p); + vec3 n = GetNormal(p); + + float dif = clamp(dot(n, l), 0., 1.); + float d = RayMarch(p+n*SURF_DIST*2., l); + if(d