From 47bf193752f9b9655df2957ed5423f47cf770e82 Mon Sep 17 00:00:00 2001 From: RedShip Date: Fri, 7 Feb 2025 20:17:43 +0100 Subject: [PATCH] ~ | First denoising attempt --- shaders/compute.glsl | 6 +++++- shaders/frag.frag | 38 +++++++++++++++++++++++++++++++++++++- shaders/trace.glsl | 1 + srcs/class/Camera.cpp | 2 +- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/shaders/compute.glsl b/shaders/compute.glsl index 5797d84..3894ab2 100644 --- a/shaders/compute.glsl +++ b/shaders/compute.glsl @@ -238,7 +238,11 @@ void main() ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy); if (pixel_coords.x >= int(u_resolution.x) || pixel_coords.y >= int(u_resolution.y)) return; - + + // if (pixel_coords.x % 50 == 0 || pixel_coords.y % 50 == 0) + // imageStore(output_image, pixel_coords, vec4(1.,0.,0., 0.)); + // return ; + if (u_pixelisation != 1 && (uint(pixel_coords.x) % u_pixelisation != 0 || uint(pixel_coords.y) % u_pixelisation != 0)) return; diff --git a/shaders/frag.frag b/shaders/frag.frag index 017073a..05e1568 100644 --- a/shaders/frag.frag +++ b/shaders/frag.frag @@ -5,5 +5,41 @@ out vec4 FragColor; uniform sampler2D screenTexture; void main() { - FragColor = texture(screenTexture, TexCoords); + vec2 uv = TexCoords; + + float incr_x = 1.0 / 1920.0 ; + float incr_y = 1.0 / 1080.0 ; + + int iteration = 5; + + if (iteration == 0) {FragColor = texture(screenTexture, uv);return;} + + vec4 color = vec4(vec3(0.), 1.0); + float totalWeight = 0.; + + float kernel[5] = float[5](1.0/16.0, 1.0/4.0, 3.0/8.0, 1.0/4.0, 1.0/16.0); + + for (int i = 0; i < iteration; i++) + { + int holes = int(pow(2, i)); + + for (int x = -2; x <= 2; x++) + { + for (int y = -2; y <= 2; y++) + { + vec2 current_uv = uv + vec2(x * holes * incr_x, y * holes * incr_y); + // if (current_uv.x < 0. || current_uv.y < 0. || current_uv.x > 1. || current_uv.y > 1.) + // continue ; + // current_uv = clamp(current_uv, vec2(0.), vec2(1.)); + + float weight = kernel[x+2] * kernel[y+2]; + + totalWeight += weight; + color += texture(screenTexture, current_uv) * weight; + } + } + } + + + FragColor = color / totalWeight; } \ No newline at end of file diff --git a/shaders/trace.glsl b/shaders/trace.glsl index 50067f2..c23f383 100644 --- a/shaders/trace.glsl +++ b/shaders/trace.glsl @@ -16,6 +16,7 @@ Ray portalRay(Ray ray, hitInfo hit) if (dot(portal_1.normal, portal_2.normal) > 0.0) { mat3 reflection = mat3(1.0) - 2.0 * outerProduct(portal_2.normal, portal_2.normal); + reflection *= inverse(mat3(1)); rotation *= reflection; } diff --git a/srcs/class/Camera.cpp b/srcs/class/Camera.cpp index 21559cd..af49703 100644 --- a/srcs/class/Camera.cpp +++ b/srcs/class/Camera.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 14:00:38 by TheRed #+# #+# */ -/* Updated: 2025/02/06 02:07:47 by tomoron ### ########.fr */ +/* Updated: 2025/02/07 18:35:33 by ycontre ### ########.fr */ /* */ /* ************************************************************************** */