From 10568cb33d3c421e45955c3504371a9ec5f834e4 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Wed, 9 Dec 2020 02:45:02 +0200 Subject: [PATCH] whitted: refraction/fresnel fixed --- sdr/whitted.p.glsl | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sdr/whitted.p.glsl b/sdr/whitted.p.glsl index 72a7c75..80b6bc9 100644 --- a/sdr/whitted.p.glsl +++ b/sdr/whitted.p.glsl @@ -37,9 +37,9 @@ vec3 tex_chess(in vec3 col1, in vec3 col2, in vec2 spos); #define GREY(x) vec3(x, x, x) -const Material mtl_sph = Material(GREY(0.1), GREY(1.0), 80.0, 0.8, 0.0, 0.0); -const Material mtl_glass = Material(GREY(0.0), GREY(0.99), 80.0, 0.99, 0.99, 1.52); -const Material mtl_air = Material(GREY(0.0), GREY(0.99), 80.0, 0.99, 0.99, 1.0); +const Material mtl_sph = Material(GREY(0.05), GREY(0.8), 80.0, 0.8, 0.0, 0.0); +const Material mtl_glass = Material(GREY(0.0), GREY(0.8), 80.0, 0.99, 0.99, 1.52); +const Material mtl_air = Material(GREY(0.0), GREY(0.8), 80.0, 0.99, 0.99, 1.0); const Material mtl_floor = Material(GREY(0.5), GREY(0.0), 1.0, 0.0, 0.0, 0.0); const vec3 light_pos = vec3(-10, 50, 30); @@ -50,7 +50,7 @@ bool cast_ray(in Ray ray, inout vec3 color, out HitPoint hit) color += shade(ray.org, ray.dir, hit) * ray.energy; return true; } - color += backdrop(ray.dir); + color += backdrop(ray.dir) * ray.energy; return false; } @@ -98,7 +98,7 @@ void main() float entering = step(0.0, dot(-stack[top].ray.dir, hit.norm)); vec3 norm = faceforward(hit.norm, stack[top].ray.dir, hit.norm); - float fr = hack_fresnel(-stack[top].ray.dir, norm, vec3(5.0, 4.0, 0.01)); + float fr = hack_fresnel(-stack[top].ray.dir, norm, vec3(5.0, 2.0, 0.01)); // fr = 1 everywhere when ior < 0.5 to avoid affecting the metal sphere fr = min(1.0, (1.0 - step(0.5, hit.mtl.ior)) + fr); @@ -106,9 +106,6 @@ void main() if(op == 0) { // reflection float energy = stack[top].ray.energy * hit.mtl.refl * fr; - if(hit.mtl.refr > 1e-4) { - energy += fr * 0.01; - } if(energy > 1e-4) { int next = top + 1; stack[next].op = 0; @@ -212,7 +209,7 @@ bool isect_scene(in vec3 ro, in vec3 rd, out HitPoint hit_res) nearest.mtl.diffuse = tex_chess(vec3(1.0, 0.0, 0.0), vec3(1.0, 1.0, 0.0), hit.surfpos); } - if(nearest.dist >= 10000.0) { + if(nearest.dist >= 9999.0) { hit_res.shadow = 1.0; return false; } -- 1.7.10.4