dymokomi/luce-render
Source of release 0.1.1
#version 450
// Start one path per pixel of the band: a jittered primary ray (through a thin
// lens when the camera has an aperture), four wavelengths
// (spectral), unit throughput, no radiance, queued for the first closest hit.
// Pixels adaptive sampling has found converged start none (pixel NONE).
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_buffer_reference : require
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require
layout(local_size_x = 64) in;
#include "common.glsl"
#include "sampler.glsl"
#include "spectrum.glsl"
void work() {
uint path = gl_GlobalInvocationID.x;
if (path >= params.band_count) return;
uint pixel = params.band_start + path;
if (film_at(FILM_HALF, pixel).w > 0.5) {
set_u(SU_PIXEL, path, NONE);
return;
}
uint width = uint(params.du.w);
vec4 u = sample4(pixel, params.sample_index, GROUP_CAMERA);
vec2 film_at = vec2(float(pixel % width) + u.x, float(pixel / width) + u.y);
vec3 film = params.corner.xyz + film_at.x * params.du.xyz + film_at.y * params.dv.xyz;
bool orthographic = params.position.w > 0.5;
vec3 origin = orthographic ? params.position.xyz + film : params.position.xyz;
vec3 direction = normalize(orthographic ? cross(params.du.xyz, params.dv.xyz) : film);
// A thin lens: from a point on the lens toward where the pinhole ray
// meets the focus plane.
if (!orthographic && constants[K_CAMERA].z > 0.0) {
vec3 focused = params.position.xyz + direction * (constants[K_CAMERA].w / dot(direction, constants[K_VIEW].xyz));
origin = lens_point(u.zw);
direction = normalize(focused - origin);
}
set_u(SU_PIXEL, path, pixel);
set_u(SU_BOUNCE, path, 0u);
set_v(SV_ORIGIN, path, vec4(origin, 0.0));
set_v(SV_DIRECTION, path, vec4(direction, 0.0));
set_v(SV_THROUGHPUT, path, vec4(1.0));
set_v(SV_RADIANCE, path, vec4(0.0));
set_v(SV_VERTEX, path, vec4(origin, 1.0));
// Light tracing's MIS: the light paths a sample, and the camera's pdf.
if (light_tracing()) set_v(SV_MIS, path, vec4(light_paths(), 0.0, 0.0, camera_pdf(direction)));
for (uint k = 0u; k < 3u; k++) set_u(SU_GUIDE_CELL(k), path, NONE);
#if SPECTRAL
set_v(SV_LAMBDA, path, sample_wavelengths(sample4(pixel, params.sample_index, GROUP_WAVELENGTH).x));
#endif
queue_push(Q_CLOSEST, path);
}
void main() {
work();
if (last_group((params.band_count + 63u) / 64u)) {
arguments(Q_CLOSEST);
}
}