From 846efdd5c67be7a755f0e2a8fd820e81373c46c9 Mon Sep 17 00:00:00 2001 From: TheRedShip Date: Sun, 5 Jan 2025 14:45:52 +0100 Subject: [PATCH] * | Going to make big changes, saving --- scenes/cornell.rt | 4 ++-- shaders/compute.glsl | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scenes/cornell.rt b/scenes/cornell.rt index 34db2e7..cf4232a 100644 --- a/scenes/cornell.rt +++ b/scenes/cornell.rt @@ -4,9 +4,9 @@ MAT 255 255 255 3.0 0.0 0.0 MAT 255 100 100 0.0 0.0 0.0 MAT 100 100 255 0.0 0.0 0.0 -MAT 100 255 100 0.0 0.5 0.0 +MAT 100 255 100 0.0 1.0 1.0 -MAT 255 255 255 0.0 1.0 0.0 +MAT 255 255 255 0.0 1.0 1.0 sp 0 -1 0 1 5 diff --git a/shaders/compute.glsl b/shaders/compute.glsl index 1b68180..82f3074 100644 --- a/shaders/compute.glsl +++ b/shaders/compute.glsl @@ -73,7 +73,7 @@ hitInfo traceRay(Ray ray) return (hit); } -Ray newRay(hitInfo hit, Ray ray, bool is_specular, inout uint rng_state) +Ray newRay(hitInfo hit, Ray ray, inout uint rng_state) { GPUObject obj; Ray new_ray; @@ -83,6 +83,8 @@ Ray newRay(hitInfo hit, Ray ray, bool is_specular, inout uint rng_state) vec3 diffuse_dir = normalize(hit.normal + randomDirection(rng_state)); vec3 specular_dir = reflect(ray.direction, hit.normal); + bool is_specular = (obj.metallic >= randomValue(rng_state)); + new_ray.origin = hit.position + hit.normal * 0.001; new_ray.direction = mix(diffuse_dir, specular_dir, obj.roughness * float(is_specular)); @@ -107,14 +109,13 @@ vec3 pathtrace(Ray ray, inout uint rng_state) GPUObject obj = objects[hit.obj_index]; - bool is_specular = (obj.metallic >= randomValue(rng_state)); - color *= mix(obj.color, vec3(1.0, 1.0, 1.0), is_specular); + color *= obj.color; light += obj.emission * obj.color; if (obj.emission > 0.0) break; - ray = newRay(hit, ray, is_specular, rng_state); + ray = newRay(hit, ray, rng_state); } return (color * light); }