diff --git a/shaders/compute.glsl b/shaders/compute.glsl index 6ad09bc..871e59b 100644 --- a/shaders/compute.glsl +++ b/shaders/compute.glsl @@ -130,9 +130,6 @@ void main() vec2 uv = (vec2(pixel_coords) / u_resolution) * 2.0 - 1.0;; uv.x *= u_resolution.x / u_resolution.y; - - uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + pixel_coords.x; - rng_state = rng_state + u_frameCount * 719393; float fov = 90.0; float focal_length = 1.0 / tan(radians(fov) / 2.0); @@ -141,6 +138,9 @@ void main() vec3 ray_direction = normalize((inverse(u_viewMatrix) * vec4(view_space_ray, 0.0)).xyz); Ray ray = Ray(u_cameraPosition, ray_direction); + uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + pixel_coords.x; + rng_state = rng_state + u_frameCount * 719393; + vec3 color = pathtrace(ray, rng_state); float blend = 1.0 / float(u_frameCount + 1); diff --git a/shaders/intersect.glsl b/shaders/intersect.glsl index a356327..b6dc046 100644 --- a/shaders/intersect.glsl +++ b/shaders/intersect.glsl @@ -33,9 +33,12 @@ bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit) { vec3 normal = normalize(cross(obj.vertex1, obj.vertex2)); float d = dot(normal, ray.direction); + + if (d == 0.0) return (false); + float t = dot(obj.position - ray.origin, normal) / d; - if (t <= 0.0 || d == 0.0) return (false); + if (t <= 0.0) return (false); vec3 p = ray.origin + ray.direction * t - obj.position;