X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=sdr%2Fwhitted.p.glsl;h=1c40d1da28a07c074f990c28c979807773fe8afe;hb=HEAD;hp=72a7c752bb807b4aa7d7cafb96b964d11841dd66;hpb=753198324a51cb6269541cada54758771826ad25;p=demo_prior diff --git a/sdr/whitted.p.glsl b/sdr/whitted.p.glsl index 72a7c75..1c40d1d 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(vec3(0.05, 0.15, 0.08), GREY(0.8), 80.0, 0.8, 0.0, 0.0); +const Material mtl_glass = Material(GREY(0.02), 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; @@ -146,7 +143,7 @@ vec3 shade(in vec3 ro, in vec3 rd, in HitPoint hit) vec3 norm = faceforward(hit.norm, rd, hit.norm); vec3 ldir = light_pos - hit.pos; - vec3 amb = hit.mtl.diffuse * 0.02; + vec3 amb = hit.mtl.diffuse * 0.01; isect_scene(hit.pos + norm * 0.01, ldir, shadow_hit); @@ -166,12 +163,13 @@ vec3 shade(in vec3 ro, in vec3 rd, in HitPoint hit) vec3 backdrop(in vec3 dir) { - return vec3(0.1, 0.15, 1.0); + return vec3(0.02, 0.38, 0.6) * 0.9; } -#define FLOOR_OFFS vec3(3.0, 0.0, 0.0) -#define FLOOR_SIZE vec2(5.5, 15.0) +#define FLOOR_OFFS vec3(3.0, 0.0, -9.0) +#define FLOOR_SIZE vec2(5.5, 12.0) +#define REFL_POS vec3(1.36, -0.5, 0.0) #define GLASS_POS vec3(0.0, 0.2, 1.2) bool isect_scene(in vec3 ro, in vec3 rd, out HitPoint hit_res) @@ -181,7 +179,7 @@ bool isect_scene(in vec3 ro, in vec3 rd, out HitPoint hit_res) nearest.dist = 10000.0; - if(isect_sphere(ro, rd, vec3(1.5, -0.5, 0.0), 0.85, hit)) { + if(isect_sphere(ro, rd, REFL_POS, 0.85, hit)) { nearest = hit; nearest.mtl = mtl_sph; if(hit.dist < 1.0) { @@ -195,7 +193,7 @@ bool isect_scene(in vec3 ro, in vec3 rd, out HitPoint hit_res) nearest.mtl = mtl_glass; } if(hit.dist < 1.0) { - opacity *= mtl_glass.refr; + opacity *= mtl_glass.refr * 0.25; // XXX hack quarter the refr, fresnel would reduce it drastically } } @@ -209,10 +207,10 @@ bool isect_scene(in vec3 ro, in vec3 rd, out HitPoint hit_res) if(isect_floor(ro, rd, FLOOR_SIZE, hit) && hit.dist < nearest.dist) { nearest = hit; nearest.mtl = mtl_floor; - nearest.mtl.diffuse = tex_chess(vec3(1.0, 0.0, 0.0), vec3(1.0, 1.0, 0.0), hit.surfpos); + nearest.mtl.diffuse = tex_chess(vec3(0.25, 0.01, 0.01), vec3(0.3, 0.3, 0.1), hit.surfpos); } - if(nearest.dist >= 10000.0) { + if(nearest.dist >= 9999.0) { hit_res.shadow = 1.0; return false; } @@ -299,7 +297,7 @@ float hack_fresnel(vec3 i, vec3 n, vec3 fresnel_val) vec3 tex_chess(in vec3 col1, in vec3 col2, in vec2 spos) { float foo = step(0.5, mod(spos.x * 8.0, 1.0)) * 2.0 - 1.0; - float bar = step(0.5, mod(spos.y * 24.0, 1.0)) * 2.0 - 1.0; + float bar = step(0.5, mod(spos.y * 12.0, 1.0)) * 2.0 - 1.0; float xor = (foo * bar) * 0.5 + 0.5;