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 | |
| parent | b4c2ce16c660c27dbfdeef12a55a0c7d448a83d2 (diff) | |
Remove remaining pregenerated random numbers
| -rw-r--r-- | include/utils.hpp | 2 | ||||
| -rw-r--r-- | shaders/compute.comp | 15 | ||||
| -rw-r--r-- | src/main.cpp | 3 | ||||
| -rw-r--r-- | src/utils.cpp | 6 |
4 files changed, 14 insertions, 12 deletions
diff --git a/include/utils.hpp b/include/utils.hpp index a196a73..11d377a 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -16,8 +16,6 @@ struct input_data { camera cam; - float random_disk[2000]; - sphere spheres[512]; bvh_node nodes[1024]; 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; diff --git a/src/main.cpp b/src/main.cpp index 968027a..0e2911c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,9 @@ int main() { auto can_render = true; vkrenderer renderer { wnd, inputs }; + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize.x = (float)width; + io.DisplaySize.y = (float)height; while(wnd.isOpen) { auto reset_accumulation = false; diff --git a/src/utils.cpp b/src/utils.cpp index eb119e8..d4419b0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -136,12 +136,6 @@ struct input_data create_inputs(uint32_t width, uint32_t height, uint32_t sample .sample_index = 0, }; - for (size_t rand_number_index = 0; rand_number_index < 1000; rand_number_index += 2) { - vec3 random_unit_disk = random_in_unit_disk(); - inputs.random_disk[rand_number_index] = random_unit_disk.x; - inputs.random_disk[rand_number_index + 1] = random_unit_disk.y; - } - // World hittable objects uint32_t spheres_count = random_scene(inputs.spheres); |
