diff options
Diffstat (limited to 'shaders/compute.comp')
| -rw-r--r-- | shaders/compute.comp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/shaders/compute.comp b/shaders/compute.comp index d0de07c..11256ad 100644 --- a/shaders/compute.comp +++ b/shaders/compute.comp @@ -69,8 +69,6 @@ layout(set = 0, binding = 0) buffer Inputs { vec4 ground_color; camera cam; - vec2[1000] random_disk; - sphere[512] spheres; bvh_node[1024] nodes; @@ -116,6 +114,14 @@ vec3 unit_vec(inout uint seed) { return vec3(cos(a) * r, sin(a) * r, z); } +vec2 disk_vec(inout uint seed) { + float z = rand(seed) * 2.0 - 1.0; + float a = 2.0 * PI * rand(seed); + float r = sqrt(1.0 - z * z); + + return vec2(cos(a) * r, sin(a) * r); +} + bool hit_aabb(aabb b, ray r, float min_t, float max_t) { for (int axis_index = 0; axis_index < 3; axis_index++) { float inv_dir = 1.f / r.direction[axis_index]; @@ -305,8 +311,9 @@ void main() { vec2 uv = vec2(float(x) / (width - 1), 1.0 - (float(y) / (height - 1))); uint seed = (y * width + x) * 100 + sample_index; - vec2 jittered_uvs = uv + vec2(random_disk[sample_index].x / (width - 1), random_disk[sample_index].y / (height - 1)); - vec2 lens_disk = random_disk[sample_index] * cam.lens_radius; + vec2 rand_disk = disk_vec(seed); + vec2 jittered_uvs = uv + vec2(rand_disk.x / (width - 1), rand_disk.y / (height - 1)); + vec2 lens_disk = rand_disk * cam.lens_radius; vec3 offset = lens_disk.x * cam.right.xyz + lens_disk.y * cam.up.xyz; vec4 proj_plane_pos = cam.first_pixel + jittered_uvs.x * cam.horizontal + jittered_uvs.y * cam.vertical; |
