diff --git a/assets/shaders/compute_pass.comp b/assets/shaders/compute_pass.comp index be1b23f..9f1990d 100644 --- a/assets/shaders/compute_pass.comp +++ b/assets/shaders/compute_pass.comp @@ -126,38 +126,42 @@ void main() 5: Kajiya */ - int integrator_idx = render_settings.top_left_render_mode; - vec2 pixel_split = vec2(gl_GlobalInvocationID) / dim; - if (pixel_split.y > render_settings.split_ratio.y) - { - if (pixel_split.x < render_settings.split_ratio.x) - integrator_idx = render_settings.bottom_left_render_mode; - else - integrator_idx = render_settings.bottom_right_render_mode; - } - else if (pixel_split.x > render_settings.split_ratio.x) - integrator_idx = render_settings.top_right_render_mode; - vec3 temporal_accumulation_sample = - (imageLoad(temporal_image, ivec2(gl_GlobalInvocationID.xy))).xyz * - min(render_settings.current_frame, 1); - - vec3 sampled = vec3(0); - for (int i = 0; i < render_settings.aa; i++) + if (gl_GlobalInvocationID.y < dim.y && gl_GlobalInvocationID.x < dim.x) { - vec2 coord = (vec2(gl_GlobalInvocationID.xy) + vec2(rand(), rand())) / dim; - coord.y = 1.0-coord.y; /* flip image vertically */ - - Ray ray = get_camera_ray(render_settings.camera_mode, coord.x, coord.y); - sampled += eval_integrator(integrator_idx, ray); - } - - float current_frame = float(render_settings.current_frame); - - sampled /= render_settings.aa; - sampled = temporal_accumulation_sample * current_frame / (current_frame + 1) + - sampled / (current_frame + 1); - - imageStore(temporal_image, ivec2(gl_GlobalInvocationID.xy), vec4(sampled, 0)); - imageStore(result_image, ivec2(gl_GlobalInvocationID.xy), vec4(sampled, 0)); + int integrator_idx = render_settings.top_left_render_mode; + vec2 pixel_split = vec2(gl_GlobalInvocationID) / dim; + if (pixel_split.y > render_settings.split_ratio.y) + { + if (pixel_split.x < render_settings.split_ratio.x) + integrator_idx = render_settings.bottom_left_render_mode; + else + integrator_idx = render_settings.bottom_right_render_mode; + } + else if (pixel_split.x > render_settings.split_ratio.x) + integrator_idx = render_settings.top_right_render_mode; + + vec3 temporal_accumulation_sample = + (imageLoad(temporal_image, ivec2(gl_GlobalInvocationID.xy))).xyz * + min(render_settings.current_frame, 1); + + vec3 sampled = vec3(0); + for (int i = 0; i < render_settings.aa; i++) + { + vec2 coord = (vec2(gl_GlobalInvocationID.xy) + vec2(rand(), rand())) / dim; + coord.y = 1.0-coord.y; /* flip image vertically */ + + Ray ray = get_camera_ray(render_settings.camera_mode, coord.x, coord.y); + sampled += eval_integrator(integrator_idx, ray); + } + + float current_frame = float(render_settings.current_frame); + + sampled /= render_settings.aa; + sampled = temporal_accumulation_sample * current_frame / (current_frame + 1) + + sampled / (current_frame + 1); + + imageStore(temporal_image, ivec2(gl_GlobalInvocationID.xy), vec4(sampled, 0)); + imageStore(result_image, ivec2(gl_GlobalInvocationID.xy), vec4(sampled, 0)); + } } diff --git a/assets/shaders/compute_pass.comp.spv b/assets/shaders/compute_pass.comp.spv index 460c9368..69f3aad 100644 Binary files a/assets/shaders/compute_pass.comp.spv and b/assets/shaders/compute_pass.comp.spv differ diff --git a/assets/shaders/debug_vis.frag.spv b/assets/shaders/debug_vis.frag.spv index 056dc86..050cd02 100644 Binary files a/assets/shaders/debug_vis.frag.spv and b/assets/shaders/debug_vis.frag.spv differ diff --git a/assets/shaders/debug_vis.vert.spv b/assets/shaders/debug_vis.vert.spv index e8a35e3..c9847ee 100644 Binary files a/assets/shaders/debug_vis.vert.spv and b/assets/shaders/debug_vis.vert.spv differ diff --git a/assets/shaders/fullscreen_tri.vert.spv b/assets/shaders/fullscreen_tri.vert.spv index 72f4f7f..fb6c581 100644 Binary files a/assets/shaders/fullscreen_tri.vert.spv and b/assets/shaders/fullscreen_tri.vert.spv differ diff --git a/assets/shaders/tex_sample.frag.spv b/assets/shaders/tex_sample.frag.spv index 49caa24..4abdbf2 100644 Binary files a/assets/shaders/tex_sample.frag.spv and b/assets/shaders/tex_sample.frag.spv differ diff --git a/src/rvpt/bvh_builder.h b/src/rvpt/bvh_builder.h index 1a350e2..69b356d 100644 --- a/src/rvpt/bvh_builder.h +++ b/src/rvpt/bvh_builder.h @@ -43,7 +43,7 @@ class BinnedBvhBuilder : public BvhBuilder private: // Threshold below which nodes are no longer split - static constexpr size_t min_primitives_per_leaf = 2; + static constexpr size_t min_primitives_per_leaf = 4; // Threshold above which nodes that are not split with binning are still split with the fallback strategy. static constexpr size_t max_primitives_per_leaf = 8; // Number of bins used to approximate the SAH. Higher = More accuracy, but slower. diff --git a/src/rvpt/main.cpp b/src/rvpt/main.cpp index 0c88b1f..3008d44 100644 --- a/src/rvpt/main.cpp +++ b/src/rvpt/main.cpp @@ -96,13 +96,13 @@ int main() Window::Settings settings; - settings.width = 1024; - settings.height = 512; + settings.width = 3330; + settings.height = 1340; Window window(settings); RVPT rvpt(window); - load_model(rvpt, "models/rabbit.obj", 1); + load_model(rvpt, "models/tridel-interior-test.obj", 1); // Setup Demo Scene rvpt.add_material( diff --git a/src/rvpt/rvpt.cpp b/src/rvpt/rvpt.cpp index 525a69f..46257c1 100644 --- a/src/rvpt/rvpt.cpp +++ b/src/rvpt/rvpt.cpp @@ -799,11 +799,11 @@ void RVPT::add_per_frame_data(int index) auto output_image = VK::Image(vk_device, memory_allocator, *graphics_queue, "raytrace_output_image_" + std::to_string(index), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL, - window_ref.get_settings().width, window_ref.get_settings().height, + window_ref.get_settings().width / resolution_scale, window_ref.get_settings().height / resolution_scale, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_ASPECT_COLOR_BIT, - static_cast(window_ref.get_settings().width * - window_ref.get_settings().height * 4), + static_cast((window_ref.get_settings().width * + window_ref.get_settings().height * 4) / resolution_scale), VK::MemoryUsage::gpu); auto random_buffer = VK::Buffer(vk_device, memory_allocator, "random_data_uniform_" + std::to_string(index), @@ -1028,8 +1028,8 @@ void RVPT::record_compute_command_buffer() cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, rendering_resources->raytrace_pipeline_layout, 0, 1, &per_frame_data[current_frame_index].raytracing_descriptor_sets.set, 0, 0); - vkCmdDispatch(cmd_buf, per_frame_data[current_frame_index].output_image.width / 16, - per_frame_data[current_frame_index].output_image.height / 16, 1); + vkCmdDispatch(cmd_buf, glm::ceil(per_frame_data[current_frame_index].output_image.width / 16.f), + glm::ceil(per_frame_data[current_frame_index].output_image.height / 16.f), 1); command_buffer.end(); } diff --git a/src/rvpt/rvpt.h b/src/rvpt/rvpt.h index 0376d9f..e78d8d0 100644 --- a/src/rvpt/rvpt.h +++ b/src/rvpt/rvpt.h @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -85,7 +86,6 @@ class RVPT int bottom_left_render_mode = 9; int bottom_right_render_mode = 9; glm::vec2 split_ratio = glm::vec2(0.5, 0.5); - } render_settings; private: @@ -100,6 +100,9 @@ class RVPT bool debug_bvh_enabled = false; + // Currently hardcoded, should be able to change in the future. + float resolution_scale = 3.0f; + Window& window_ref; std::string source_folder = "";