oglc/shader/root/rtpre.glsl

60 lines
1.3 KiB
Plaintext
Raw Normal View History

2021-08-10 02:11:22 +02:00
#version 430
// writes first hit information into buffers to accelerate later passes
// local work group
layout(local_size_x = 1, local_size_y = 1) in;
2021-08-13 21:03:19 +02:00
layout (rgba32f, binding = 2) writeonly uniform image2D g0_output;
layout (rgba32f, binding = 3) writeonly uniform image2D g1_output;
#include func.glsl
#include constants.glsl
#include time.glsl
2021-08-10 02:11:22 +02:00
#include sphere.glsl
#include ray.glsl
#include intersect.glsl
#include random.glsl
#include camera.glsl
#include image.glsl
#include scene.glsl
void main()
{
// x normal.x
// y normal.y
// z normal.z
// w depth
vec4 pixel= vec4(0);
ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy);
ivec2 dims = imageSize(g0_output);
vec2 uv = pixelUv(pixelCoords, dims);
Ray ray = createCameraRay(uv);
RayHit hit = trace(ray);
2021-08-13 14:43:54 +02:00
// n roughly correlates to steepness of log curve
// TODO: what does this mean in mathematical terms??
2021-08-13 21:03:19 +02:00
float n = 4;
float f = INF;
float z = hit.distance;
2021-08-13 14:43:54 +02:00
float depth;
// linear depth
//depth = z/f;
2021-08-13 14:43:54 +02:00
// logarithmic depth
2021-08-13 21:03:19 +02:00
depth = max(0,log(z*pow(E,n)/f)/n);
2021-08-13 14:43:54 +02:00
// pack normal into texture
pixel.xyz = hit.normal*0.5+0.5;
pixel.w = depth;
imageStore(g0_output, pixelCoords, pixel);
2021-08-13 21:03:19 +02:00
pixel.xyz = hit.albedo;
pixel.w = 0;
imageStore(g1_output, pixelCoords, pixel);
}