Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resolution scaling #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions assets/shaders/compute_pass.comp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Binary file modified assets/shaders/compute_pass.comp.spv
Binary file not shown.
Binary file modified assets/shaders/debug_vis.frag.spv
Binary file not shown.
Binary file modified assets/shaders/debug_vis.vert.spv
Binary file not shown.
Binary file modified assets/shaders/fullscreen_tri.vert.spv
Binary file not shown.
Binary file modified assets/shaders/tex_sample.frag.spv
Binary file not shown.
2 changes: 1 addition & 1 deletion src/rvpt/bvh_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/rvpt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/rvpt/rvpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkDeviceSize>(window_ref.get_settings().width *
window_ref.get_settings().height * 4),
static_cast<VkDeviceSize>((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),
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion src/rvpt/rvpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>
#include <optional>
#include <random>
#include <atomic>

#include <vulkan/vulkan.h>

Expand Down Expand Up @@ -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:
Expand All @@ -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 = "";

Expand Down