diff options
| author | ladevieq <qladevie@wanadev.fr> | 2021-04-01 14:33:29 +0200 |
|---|---|---|
| committer | ladevieq <qladevie@wanadev.fr> | 2021-04-01 14:33:29 +0200 |
| commit | 085d4c6dd995a4da396ddf3d51b619fafb77af7b (patch) | |
| tree | 9d02d527fe68798e1f91c3a2641ddbd7d129addd /shaders | |
| parent | b4c2ce16c660c27dbfdeef12a55a0c7d448a83d2 (diff) | |
Remove remaining pregenerated random numbers
Diffstat (limited to 'shaders')
| -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; |
