From ddf36431f5e4b31acaaa58ebf80f44c3e3c5b660 Mon Sep 17 00:00:00 2001 From: LegendWasTaken Date: Mon, 10 May 2021 01:12:30 +0800 Subject: [PATCH] Add resolution scaling --- assets/shaders/compute_pass.comp | 68 +++++++++++++------------ assets/shaders/compute_pass.comp.spv | Bin 65264 -> 65612 bytes assets/shaders/debug_vis.frag.spv | Bin 556 -> 556 bytes assets/shaders/debug_vis.vert.spv | Bin 1340 -> 1340 bytes assets/shaders/fullscreen_tri.vert.spv | Bin 1312 -> 1312 bytes assets/shaders/tex_sample.frag.spv | Bin 656 -> 656 bytes src/rvpt/bvh_builder.h | 2 +- src/rvpt/main.cpp | 6 +-- src/rvpt/rvpt.cpp | 10 ++-- src/rvpt/rvpt.h | 5 +- 10 files changed, 49 insertions(+), 42 deletions(-) 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 460c936872ad5fdbab846bc4308ffa7ed6990717..69f3aadae6e3323813299b2cfc034112981e4ff7 100644 GIT binary patch delta 3751 zcmZve$#Ydz5XMgihC~qX2@wTkP|*ZLP!WV6!2!epqN0KWK9Y!0Nx}n^(HnH*$|~#q z1+H8wMM+ug+`Dn-gg7Cfs0<>54E}yEx8p0yn>uyA@9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{#41e8RQYL{@VQ6l6O$_mU1WfFuh~6 zIYxaE*izn`mHc9`8va|;KpGV-UCY=)vyTZa0b9Cz2w;Mbg4H&#wI-rXEq^yGSa<3i z{!6{3^OmX5;!S)EtY(BRdbuNfpO>eX<8hSbG=J|bgB4)4xUg=px%XrnuoA3KY}TL~ zunJ9I?at;HwHW6Ku=if>JgdQElw5x#o}ulwab5ze`9qA2g$FZ wAFk#XSFttI@~haEX|5tJ;#D-q>#sd7!i1ez`&H6eNNeZFYs2vARhtg{52m|%5C8xG diff --git a/assets/shaders/debug_vis.frag.spv b/assets/shaders/debug_vis.frag.spv index 056dc866bc2d7f48a975acedb3a654e48d2ad1d7..050cd02d9d038162cfaf3754fa3a10b5a13acc9c 100644 GIT binary patch delta 18 ZcmZ3(vWA6|nMs+Qfq{{MYa^#J6964f0)qem delta 18 ZcmZ3(vWA6|nMs+Qfq{{MVS_Q delta 18 ZcmdnPwTFw7nMs+Qfq{{MVA(O diff --git a/assets/shaders/fullscreen_tri.vert.spv b/assets/shaders/fullscreen_tri.vert.spv index 72f4f7f569aaef1d93d3ec380913744f228101b0..fb6c58167750317b5c3455297a50e275e0893f75 100644 GIT binary patch delta 18 ZcmZ3$wSbG0nMs+Qfq{{MYa^#PD*zl}0&V~R delta 18 ZcmZ3$wSbG0nMs+Qfq{{MV(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 = "";