From 9b61093de417a01ec298ba239d1d7b72920619af Mon Sep 17 00:00:00 2001 From: ktyl Date: Fri, 13 Aug 2021 19:12:39 +0100 Subject: [PATCH] use first pass depth and normal data --- shader/include/constants.glsl | 4 ++-- shader/root/rt.glsl | 40 ++++++++++++++++++++--------------- shader/root/rtpre.glsl | 2 +- src/main.c | 1 - src/sphere.c | 2 +- todo.md | 8 +++---- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/shader/include/constants.glsl b/shader/include/constants.glsl index bcba6b7..774a06e 100644 --- a/shader/include/constants.glsl +++ b/shader/include/constants.glsl @@ -1,5 +1,5 @@ -const float INF = 100.0; +const float INF = 17.0; const float PI = 3.14159; const float E = 2.71828; const int SAMPLES = 1; -const int BOUNCES = 4; +const int BOUNCES = 8; diff --git a/shader/root/rt.glsl b/shader/root/rt.glsl index e778f86..f84c496 100644 --- a/shader/root/rt.glsl +++ b/shader/root/rt.glsl @@ -43,27 +43,33 @@ void main() vec2 uv = pixelUv(pixelCoords, dims); - for (int i = 0; i < SAMPLES; i++) - { - // create a ray from the uv - Ray ray = createCameraRay(uv); - - // trace the rays path around the scene - for (int j = 0; j < BOUNCES; j++) - { - RayHit hit = trace(ray); - - pixel.xyz += ray.energy * shade(ray, hit); - - if (length(ray.energy) < 0.001) break; - } - } - pixel.xyz /= SAMPLES; - + // load data from first pass vec4 d = imageLoad(_g0, ivec2(gl_GlobalInvocationID.xy)); float depth = d.w; vec3 normal = d.xyz*2.0-1.0; // unpack normal packaged into texture + // create a ray from the uv + Ray ray = createCameraRay(uv); + RayHit firstHit; + firstHit.position = ray.origin+ray.direction*depth; + firstHit.distance = depth; + firstHit.normal = normal; + firstHit.albedo = vec3(1.0,1.0,1.0); + + // do a trace using precomputed depth and surface normal values + //RayHit hit = trace(ray); + + // trace the rays path around the scene + for (int j = 1; j < BOUNCES; j++) + { + RayHit hit = trace(ray); + + pixel.xyz += ray.energy * shade(ray, hit); + + if (length(ray.energy) < 0.001) break; + } + + //pixel.xyz = mix(pixel.xyz, normal, 1.0-depth); pixel.xyz = mix(pixel.xyz, vec3(1.0), depth); diff --git a/shader/root/rtpre.glsl b/shader/root/rtpre.glsl index 793fc89..dd003f9 100644 --- a/shader/root/rtpre.glsl +++ b/shader/root/rtpre.glsl @@ -35,7 +35,7 @@ void main() // n roughly correlates to steepness of log curve // TODO: what does this mean in mathematical terms?? - float n = 3; + float n = 1.0; float f = INF; float z = hit.distance; diff --git a/src/main.c b/src/main.c index ad29035..948666a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,3 @@ - #include "main.h" #include "gfx.h" #include "clock.h" diff --git a/src/sphere.c b/src/sphere.c index c2fd193..4503168 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -26,7 +26,7 @@ void makeSpheres(struct Sphere *spheres, int count) { x = 2.0*CGLM_PI * (float)i/(float)count; sc[0] = sin(x)*d; - sc[1] = sin(x*3.0-t); + sc[1] = sin(x*3.0-5.0*sin(t)); sc[2] = cos(x)*d; float ic = i/(float)count*CGLM_PI*2.0; diff --git a/todo.md b/todo.md index 124baf3..6bb1bd2 100644 --- a/todo.md +++ b/todo.md @@ -14,10 +14,10 @@ * [ ] do a 'fract * [-] depth * [x] acquire value - * [ ] acquire randomness - * [ ] acceleration time ! - * [ ] auxiliary textures - * [ ] depth buffer + * [x] acquire randomness + * [-] acceleration time ! + * [-] auxiliary textures + * [x] depth buffer * [ ] frame blending * [ ] maybe do some fractals * [ ] mandelbrot