-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathPath.cpp
77 lines (69 loc) · 2.49 KB
/
Path.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "LumenPCH.h"
#include "Path.h"
void Path::init() {
Integrator::init();
SceneDesc desc;
desc.index_addr = lumen_scene->index_buffer->get_device_address();
desc.material_addr = lumen_scene->materials_buffer->get_device_address();
desc.prim_info_addr = lumen_scene->prim_lookup_buffer->get_device_address();
desc.compact_vertices_addr = lumen_scene->compact_vertices_buffer->get_device_address();
lumen_scene->scene_desc_buffer =
prm::get_buffer({.name = "Scene Desc",
.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
.memory_type = vk::BufferType::GPU,
.size = sizeof(SceneDesc),
.data = &desc});
frame_num = 0;
assert(vk::render_graph()->settings.shader_inference == true);
// For shader resource dependency inference, use this macro to register a buffer address to the rendergraph
REGISTER_BUFFER_WITH_ADDRESS(SceneDesc, desc, prim_info_addr, lumen_scene->prim_lookup_buffer, vk::render_graph());
path_length = config->path_length;
}
void Path::render() {
pc_ray.size_x = Window::width();
pc_ray.size_y = Window::height();
pc_ray.num_lights = (int)lumen_scene->gpu_lights.size();
pc_ray.time = rand() % UINT_MAX;
pc_ray.max_depth = path_length;
pc_ray.sky_col = config->sky_col;
pc_ray.total_light_area = lumen_scene->total_light_area;
pc_ray.light_triangle_count = lumen_scene->total_light_triangle_cnt;
pc_ray.dir_light_idx = lumen_scene->dir_light_idx;
pc_ray.frame_num = frame_num;
pc_ray.direct_lighting = direct_lighting;
vk::render_graph()
->add_rt("Path",
{
.shaders = {{"src/shaders/integrators/path/path.rgen"},
{"src/shaders/ray.rmiss"},
{"src/shaders/ray_shadow.rmiss"},
{"src/shaders/ray.rchit"},
{"src/shaders/ray.rahit"}},
.dims = {Window::width(), Window::height()},
})
.push_constants(&pc_ray)
.bind({
output_tex,
scene_ubo_buffer,
lumen_scene->scene_desc_buffer,
})
.bind(lumen_scene->mesh_lights_buffer)
.bind_texture_array(lumen_scene->scene_textures)
//.write(output_tex) // Needed if the automatic shader inference is disabled
.bind_tlas(tlas);
}
bool Path::update() {
frame_num++;
bool updated = Integrator::update();
if (updated) {
frame_num = 0;
}
return updated;
}
void Path::destroy() { Integrator::destroy(); }
bool Path::gui() {
bool result = Integrator::gui();
result |= ImGui::SliderInt("Path length", (int*)&path_length, 0, 12);
result |= ImGui::Checkbox("Direct lighting", &direct_lighting);
return result;
}