2021-07-24 02:31:35 +02:00
|
|
|
#version 430
|
|
|
|
|
2021-08-09 16:49:05 +02:00
|
|
|
layout(local_size_x = 1, local_size_y = 1) in; // size of local work group - 1 pixel
|
|
|
|
|
2021-08-12 22:16:45 +02:00
|
|
|
// gbuffer?
|
|
|
|
layout(rgba32f, binding = 2) readonly uniform image2D _g0;
|
|
|
|
|
2021-08-10 02:11:22 +02:00
|
|
|
// final output
|
2021-08-03 00:32:47 +02:00
|
|
|
layout(rgba32f, binding = 0) uniform image2D img_output; // rgba32f defines internal format, image2d for random write to output texture
|
2021-08-07 18:50:24 +02:00
|
|
|
|
2021-08-10 02:11:22 +02:00
|
|
|
// TODO: some of these depend on each other!! need be be in this order for now c:
|
|
|
|
#include func.glsl
|
|
|
|
#include constants.glsl
|
|
|
|
#include time.glsl
|
|
|
|
#include sphere.glsl
|
|
|
|
#include ray.glsl
|
|
|
|
#include intersect.glsl
|
|
|
|
#include random.glsl
|
|
|
|
#include camera.glsl
|
|
|
|
#include image.glsl
|
|
|
|
// scene.glsl includes scene trace function
|
|
|
|
#include scene.glsl
|
|
|
|
#include lighting.glsl
|
2021-08-07 18:50:24 +02:00
|
|
|
|
|
|
|
vec3 shade(inout Ray ray, RayHit hit)
|
|
|
|
{
|
|
|
|
if (hit.distance < INF)
|
|
|
|
{
|
|
|
|
return scatterLambert(ray, hit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// sky color
|
|
|
|
return vec3(0.68,0.85,0.9);
|
|
|
|
}
|
|
|
|
|
2021-07-24 02:31:35 +02:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
// base pixel colour for the image
|
|
|
|
vec4 pixel = vec4(0.0, 0.0, 0.0, 1.0);
|
|
|
|
|
2021-08-12 22:16:45 +02:00
|
|
|
ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy);
|
|
|
|
ivec2 dims = imageSize(img_output);
|
2021-07-24 02:31:35 +02:00
|
|
|
|
2021-08-12 22:16:45 +02:00
|
|
|
vec2 uv = pixelUv(pixelCoords, dims);
|
2021-08-02 10:35:39 +02:00
|
|
|
|
2021-08-12 22:16:45 +02:00
|
|
|
for (int i = 0; i < SAMPLES; i++)
|
2021-08-06 20:25:52 +02:00
|
|
|
{
|
2021-08-07 18:50:24 +02:00
|
|
|
// create a ray from the uv
|
|
|
|
Ray ray = createCameraRay(uv);
|
|
|
|
|
|
|
|
// trace the rays path around the scene
|
2021-08-12 22:16:45 +02:00
|
|
|
for (int j = 0; j < BOUNCES; j++)
|
2021-08-07 18:50:24 +02:00
|
|
|
{
|
|
|
|
RayHit hit = trace(ray);
|
|
|
|
|
|
|
|
pixel.xyz += ray.energy * shade(ray, hit);
|
2021-08-08 17:47:25 +02:00
|
|
|
|
|
|
|
if (length(ray.energy) < 0.001) break;
|
2021-08-07 18:50:24 +02:00
|
|
|
}
|
2021-08-06 20:25:52 +02:00
|
|
|
}
|
2021-08-12 22:16:45 +02:00
|
|
|
pixel.xyz /= SAMPLES;
|
|
|
|
|
|
|
|
vec4 d = imageLoad(_g0, ivec2(gl_GlobalInvocationID.xy));
|
|
|
|
float depth = d.x;
|
|
|
|
|
|
|
|
pixel.xyz = mix(pixel.xyz, vec3(0), depth);
|
|
|
|
|
|
|
|
//pixel.a = 1.0;
|
|
|
|
|
|
|
|
//pixel.xyz = texture(_g0, uv).xyz;
|
2021-08-07 19:30:43 +02:00
|
|
|
|
2021-07-24 02:31:35 +02:00
|
|
|
// output to a specific pixel in the image
|
2021-08-10 02:11:22 +02:00
|
|
|
imageStore(img_output, ivec2(gl_GlobalInvocationID.xy), pixel);
|
2021-07-24 02:31:35 +02:00
|
|
|
}
|