From e31d17489cc8599704418d237b381c9253cfbc6b Mon Sep 17 00:00:00 2001 From: TheRedShip Date: Wed, 8 Jan 2025 17:07:31 +0100 Subject: [PATCH] + | Anti aliasing and some sort of depth of field but need to tweaks --- scenes/portalrotation.rt | 2 +- scenes/roughness.rt | 6 +++--- shaders/compute.glsl | 29 ++++++++++++++++++++--------- shaders/random.glsl | 7 +++++++ 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/scenes/portalrotation.rt b/scenes/portalrotation.rt index a34c4be..36abe97 100644 --- a/scenes/portalrotation.rt +++ b/scenes/portalrotation.rt @@ -1,6 +1,6 @@ -MAT 255 255 255 2.0 0.0 0.0 //light +MAT 255 255 255 4.0 0.0 0.0 //light MAT 255 255 255 0.0 0.0 0.0 //white MAT 255 100 100 0.0 0.0 0.0 //red diff --git a/scenes/roughness.rt b/scenes/roughness.rt index b5c6cff..5e475c7 100644 --- a/scenes/roughness.rt +++ b/scenes/roughness.rt @@ -1,9 +1,9 @@ CAM 0 1 2 -MAT 255 255 255 7.5 0.0 0.0 // white light 0 +MAT 255 255 255 5.0 0.0 0.0 // white light 0 MAT 255 10 10 0.0 0.0 0.0 // red 1 -MAT 10 10 10 0.0 0.0 0.0 // gray 2 +MAT 30 30 30 0.0 0.0 0.0 // gray 2 MAT 10 255 10 0.0 0.0 0.0 // green 3 MAT 255 255 255 0.0 0.0 0.0 // white 4 MAT 50 50 255 0.0 0.0 0.0 // white 5 @@ -40,5 +40,5 @@ sp 2.4 1.5 -1 1.5 14 // light quad -qu -1 2.9 -1 2 0 0 0 0 2 0 +qu -1 2.999 -1 2 0 0 0 0 2 0 diff --git a/shaders/compute.glsl b/shaders/compute.glsl index c5f87c7..38d215f 100644 --- a/shaders/compute.glsl +++ b/shaders/compute.glsl @@ -144,10 +144,10 @@ vec3 pathtrace(Ray ray, inout uint rng_state) GPUMaterial mat = materials[obj.mat_index]; // RR - // float p = max(color.r, max(color.g, color.b)); - // if (randomValue(rng_state) > p && i > 1) - // break; - // color /= p; + float p = max(color.r, max(color.g, color.b)); + if (randomValue(rng_state) > p) + break; + color /= p; // color *= mat.color; @@ -167,19 +167,30 @@ void main() if (pixel_coords.x >= int(u_resolution.x) || pixel_coords.y >= int(u_resolution.y)) return; - vec2 uv = (vec2(pixel_coords) / u_resolution) * 2.0 - 1.0;; + uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + pixel_coords.x; + rng_state = rng_state + u_frameCount * 719393; + + vec2 jitter = randomPointInCircle(rng_state); + + vec2 uv = ((vec2(pixel_coords) + jitter) / u_resolution) * 2.0 - 1.0;; uv.x *= u_resolution.x / u_resolution.y; float fov = 90.0; float focal_length = 1.0 / tan(radians(fov) / 2.0); vec3 view_space_ray = normalize(vec3(uv.x, uv.y, -focal_length)); - + vec3 ray_direction = normalize((inverse(u_viewMatrix) * vec4(view_space_ray, 0.0)).xyz); - Ray ray = Ray(u_cameraPosition, ray_direction); + + float focal_distance = 0.0; + float aperture_size = 0.0; - uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + pixel_coords.x; - rng_state = rng_state + u_frameCount * 719393; + float theta = randomValue(rng_state) * 2.0 * M_PI; + float radius = sqrt(randomValue(rng_state)) * aperture_size; + vec2 aperture_point = vec2(cos(theta) * radius, sin(theta) * radius); + vec3 ray_origin = u_cameraPosition + vec3(aperture_point, 0.0); + + Ray ray = Ray(ray_origin, ray_direction); vec3 color = pathtrace(ray, rng_state); float blend = 1.0 / float(u_frameCount + 1); diff --git a/shaders/random.glsl b/shaders/random.glsl index 2fc8257..8114ab9 100644 --- a/shaders/random.glsl +++ b/shaders/random.glsl @@ -23,6 +23,13 @@ vec3 randomDirection(inout uint rng_state) return normalize(vec3(x, y, z)); } +vec2 randomPointInCircle(inout uint rng_state) +{ + float angle = randomValue(rng_state) * 2 * M_PI; + vec2 point_in_circle = vec2(cos(angle), sin(angle)); + return (point_in_circle * sqrt(randomValue(rng_state))); +} + vec3 randomHemisphereDirection(vec3 normal, inout uint rng_state) { vec3 direction = randomDirection(rng_state);