Skip to content

Commit f323622

Browse files
committed
Setting up Acceleration Structures and correcting Problems
1 parent b83979c commit f323622

File tree

26 files changed

+840
-448
lines changed

26 files changed

+840
-448
lines changed

examples/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ file(GLOB APPL_SOURCES
2121
)
2222
add_executable(LightingTest ${APPL_SOURCES})
2323

24+
#DEMO 4
25+
# --- Raytracing Example ---
26+
file(GLOB APPRT_SOURCES
27+
"raytracing/*.cpp"
28+
"raytracing/*.h"
29+
)
30+
add_executable(RaytracingApp ${APPRT_SOURCES})
31+
2432
# Link projects against Engine lib
2533
target_link_libraries(RendererApp PRIVATE VulkanEngine)
2634
target_link_libraries(RotatingKabuto PRIVATE VulkanEngine)
2735
target_link_libraries(LightingTest PRIVATE VulkanEngine)
36+
target_link_libraries(RaytracingApp PRIVATE VulkanEngine)
2837

2938
target_compile_definitions(VulkanEngine PUBLIC EXAMPLES_RESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/")
3039

31-
set_property(TARGET RendererApp RotatingKabuto LightingTest PROPERTY FOLDER "examples")
40+
set_property(TARGET RendererApp RotatingKabuto LightingTest RaytracingApp PROPERTY FOLDER "examples")

examples/lighting-test/application.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#include "application.h"
22
#include <filesystem>
33

4-
void VulkanRenderer::init(Systems::RendererSettings settings)
4+
void Application::init(Systems::RendererSettings settings)
55
{
66
m_window = new WindowGLFW("Lighting Test", 1280, 1024);
77

88
m_window->init();
99

1010
m_window->set_window_size_callback(
11-
std::bind(&VulkanRenderer::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
11+
std::bind(&Application::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
1212
m_window->set_mouse_callback(
13-
std::bind(&VulkanRenderer::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
14-
m_window->set_key_callback(std::bind(&VulkanRenderer::keyboard_callback, this, std::placeholders::_1,
13+
std::bind(&Application::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
14+
m_window->set_key_callback(std::bind(&Application::keyboard_callback, this, std::placeholders::_1,
1515
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
1616

1717
m_renderer = new Systems::ForwardRenderer(m_window, settings, {LOW,true});
@@ -21,7 +21,7 @@ void VulkanRenderer::init(Systems::RendererSettings settings)
2121
setup_gui();
2222
}
2323

24-
void VulkanRenderer::run(int argc, char *argv[])
24+
void Application::run(int argc, char *argv[])
2525
{
2626

2727
Systems::RendererSettings settings{};
@@ -121,7 +121,7 @@ void VulkanRenderer::run(int argc, char *argv[])
121121
m_renderer->shutdown(m_scene);
122122
}
123123

124-
void VulkanRenderer::setup()
124+
void Application::setup()
125125
{
126126
const std::string MESH_PATH(EXAMPLES_RESOURCES_PATH "meshes/");
127127
const std::string TEXTURE_PATH(EXAMPLES_RESOURCES_PATH "textures/");
@@ -234,7 +234,7 @@ void VulkanRenderer::setup()
234234
m_controller = new Tools::Controller(camera, m_window);
235235
}
236236

237-
void VulkanRenderer::setup_gui()
237+
void Application::setup_gui()
238238
{
239239
m_interface.overlay = new Tools::GUIOverlay((float)m_window->get_extent().width,
240240
(float)m_window->get_extent().height, GuiColorProfileType::DARK);
@@ -280,15 +280,15 @@ void VulkanRenderer::setup_gui()
280280
m_interface.properties = propertiesPanel;
281281
}
282282

283-
void VulkanRenderer::update()
283+
void Application::update()
284284
{
285285
if (!m_interface.overlay->wants_to_handle_input())
286286
m_controller->handle_keyboard(0, 0, m_time.delta);
287287

288288
m_interface.object->set_object(m_interface.scene->get_selected_object());
289289
}
290290

291-
void VulkanRenderer::tick()
291+
void Application::tick()
292292
{
293293
float currentTime = (float)m_window->get_time_elapsed();
294294
m_time.delta = currentTime - m_time.last;

examples/lighting-test/application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
USING_VULKAN_ENGINE_NAMESPACE
1818
using namespace Core;
19-
class VulkanRenderer
19+
class Application
2020
{
2121
struct UserInterface
2222
{

examples/lighting-test/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int main(int argc, char* argv[])
55
{
6-
VulkanRenderer app;
6+
Application app;
77
try
88
{
99
app.run(argc,argv);
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#include "application.h"
2+
#include <filesystem>
3+
4+
void Application::init(Systems::RendererSettings settings, Systems::ForwardRendererSettings settings2) {
5+
m_window = new WindowGLFW("Raytracing Example", 1280, 1024);
6+
7+
m_window->init();
8+
9+
m_window->set_window_size_callback(
10+
std::bind(&Application::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
11+
m_window->set_mouse_callback(
12+
std::bind(&Application::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
13+
m_window->set_key_callback(std::bind(&Application::keyboard_callback,
14+
this,
15+
std::placeholders::_1,
16+
std::placeholders::_2,
17+
std::placeholders::_3,
18+
std::placeholders::_4));
19+
20+
m_renderer = new Systems::ForwardRenderer(m_window, settings, settings2);
21+
22+
setup();
23+
setup_gui();
24+
}
25+
26+
void Application::run(int argc, char* argv[]) {
27+
28+
Systems::RendererSettings settings{};
29+
settings.samplesMSAA = MSAASamples::_NONE;
30+
settings.clearColor = Vec4(0.02, 0.02, 0.02, 1.0);
31+
settings.enableUI = true;
32+
settings.enableRaytracing = true;
33+
Systems::ForwardRendererSettings settings2{};
34+
settings2.shadowQuality = ShadowResolution::MEDIUM;
35+
settings2.fxaa = true;
36+
37+
init(settings, settings2);
38+
while (!m_window->get_window_should_close())
39+
{
40+
41+
// I-O
42+
m_window->poll_events();
43+
44+
tick();
45+
}
46+
m_renderer->shutdown(m_scene);
47+
}
48+
49+
void Application::setup() {
50+
const std::string MESH_PATH(EXAMPLES_RESOURCES_PATH "meshes/");
51+
const std::string TEXTURE_PATH(EXAMPLES_RESOURCES_PATH "textures/");
52+
const std::string ENGINE_MESH_PATH(ENGINE_RESOURCES_PATH "meshes/");
53+
54+
camera = new Camera();
55+
camera->set_position(Vec3(0.0f, 0.0f, -5.0f));
56+
camera->set_far(100.0f);
57+
camera->set_near(0.1f);
58+
camera->set_field_of_view(70.0f);
59+
60+
m_scene = new Scene(camera);
61+
62+
Mesh* lightDummy = new Mesh();
63+
Tools::Loaders::load_3D_file(lightDummy, ENGINE_MESH_PATH + "sphere.obj");
64+
lightDummy->push_material(new UnlitMaterial());
65+
lightDummy->set_scale(0.5f);
66+
lightDummy->set_name("Gizmo");
67+
68+
PointLight* light = new PointLight();
69+
light->set_position({-3.0f, 3.0f, 0.0f});
70+
light->set_area_of_effect(20.0f);
71+
light->set_shadow_fov(115.0f);
72+
light->add_child(lightDummy);
73+
light->set_name("Light");
74+
75+
m_scene->add(light);
76+
77+
Mesh* toriiMesh = new Mesh();
78+
auto toriiMat = new PhysicallyBasedMaterial();
79+
80+
Texture* toriiT = new Texture();
81+
Tools::Loaders::load_texture(toriiT, TEXTURE_PATH + "torii_color.png");
82+
toriiMat->set_albedo_texture(toriiT);
83+
84+
Texture* toriiN = new Texture();
85+
Tools::Loaders::load_texture(toriiN, TEXTURE_PATH + "torii_normal.png", TextureFormatType::NORMAL_FORMAT);
86+
toriiMat->set_normal_texture(toriiN);
87+
88+
Texture* toriiM = new Texture();
89+
// Tools::Loaders::load_texture(toriiM, TEXTURE_PATH + "torii_mask.png");
90+
// toriiMat->set_mask_texture(toriiM, UNREAL_ENGINE);
91+
toriiMat->set_metalness(0.05);
92+
toriiMat->set_roughness(0.5);
93+
toriiMesh->push_material(toriiMat);
94+
95+
Tools::Loaders::load_3D_file(toriiMesh, MESH_PATH + "torii.obj", false);
96+
toriiMesh->set_name("Torii");
97+
toriiMesh->set_scale(0.2f);
98+
toriiMesh->set_position({0.0, -2.3, 0.0});
99+
toriiMesh->set_rotation({0.0, 28.0f, 0.0f});
100+
m_scene->add(toriiMesh);
101+
102+
Mesh* plane = new Mesh();
103+
plane->push_geometry(Geometry::create_quad());
104+
auto terrainMat = new PhysicallyBasedMaterial();
105+
Texture* floorText = new Texture();
106+
Tools::Loaders::load_texture(floorText, TEXTURE_PATH + "floor_diffuse.jpg");
107+
Texture* floorNormalText = new Texture();
108+
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg", TextureFormatType::NORMAL_FORMAT);
109+
Texture* floorRoughText = new Texture();
110+
Tools::Loaders::load_texture(floorRoughText, TEXTURE_PATH + "floor_roughness.jpg");
111+
terrainMat->set_albedo({0.43f, 0.28f, 0.23f});
112+
terrainMat->set_albedo_texture(floorText);
113+
terrainMat->set_normal_texture(floorNormalText);
114+
terrainMat->set_roughness_texture(floorRoughText);
115+
terrainMat->set_tile({3.0f, 3.0f});
116+
plane->push_material(terrainMat);
117+
plane->set_name("Floor");
118+
plane->set_position({0.0, -2.3, 0.0});
119+
plane->set_rotation({-90.0f, 0.0f, 0.0f});
120+
plane->set_scale(5.0f);
121+
122+
m_scene->add(plane);
123+
124+
m_scene->set_ambient_color({0.2, 0.25, 0.61});
125+
126+
TextureHDR* envMap = new TextureHDR();
127+
Tools::Loaders::load_texture(envMap, TEXTURE_PATH + "cloudy.hdr");
128+
Skybox* sky = new Skybox(envMap);
129+
sky->set_color_intensity(0.25f);
130+
m_scene->set_skybox(sky);
131+
132+
m_controller = new Tools::Controller(camera, m_window);
133+
}
134+
135+
void Application::setup_gui() {
136+
m_interface.overlay = new Tools::GUIOverlay(
137+
(float)m_window->get_extent().width, (float)m_window->get_extent().height, GuiColorProfileType::DARK);
138+
139+
Tools::Panel* tutorialPanel =
140+
new Tools::Panel("TUTORIAL", 0, 0.8f, 0.2f, 0.2f, PanelWidgetFlags::NoMove, false, true);
141+
142+
tutorialPanel->add_child(new Tools::Space());
143+
tutorialPanel->add_child(new Tools::Separator("CONTROLS"));
144+
tutorialPanel->add_child(new Tools::Separator());
145+
tutorialPanel->add_child(new Tools::TextLine("WASD: move camera.", TextWidgetType::BULLET));
146+
tutorialPanel->add_child(new Tools::TextLine("QE: camera down/up.", TextWidgetType::BULLET));
147+
tutorialPanel->add_child(new Tools::TextLine("Mouse + Left: rotate camera.", TextWidgetType::BULLET));
148+
tutorialPanel->add_child(new Tools::TextLine("L: toggle light animation", TextWidgetType::BULLET));
149+
tutorialPanel->add_child(new Tools::TextLine("F11: toggle fullscreen/windowed mode.", TextWidgetType::BULLET));
150+
tutorialPanel->add_child(new Tools::TextLine("Esc: exit application.", TextWidgetType::BULLET));
151+
tutorialPanel->add_child(new Tools::Space());
152+
tutorialPanel->add_child(new Tools::Separator());
153+
tutorialPanel->add_child(new Tools::TextLine("Enjoy changing the parameters!"));
154+
155+
m_interface.overlay->add_panel(tutorialPanel);
156+
m_interface.tutorial = tutorialPanel;
157+
158+
Tools::Panel* explorerPanel = new Tools::Panel("EXPLORER", 0, 0, 0.2f, 0.7f, PanelWidgetFlags::NoMove, false);
159+
m_interface.scene = new Tools::SceneExplorerWidget(m_scene);
160+
explorerPanel->add_child(m_interface.scene);
161+
explorerPanel->add_child(new Tools::Space());
162+
explorerPanel->add_child(new Tools::RendererSettingsWidget(m_renderer));
163+
explorerPanel->add_child(new Tools::Separator());
164+
explorerPanel->add_child(new Tools::TextLine(" Application average"));
165+
explorerPanel->add_child(new Tools::Profiler());
166+
explorerPanel->add_child(new Tools::Space());
167+
168+
m_interface.overlay->add_panel(explorerPanel);
169+
m_interface.explorer = explorerPanel;
170+
171+
Tools::Panel* propertiesPanel =
172+
new Tools::Panel("OBJECT PROPERTIES", 0.75f, 0, 0.25f, 0.8f, PanelWidgetFlags::NoMove, true);
173+
m_interface.object = new Tools::ObjectExplorerWidget();
174+
propertiesPanel->add_child(m_interface.object);
175+
176+
m_interface.overlay->add_panel(propertiesPanel);
177+
m_interface.properties = propertiesPanel;
178+
179+
// m_renderer->set_gui_overlay(m_interface.overlay);
180+
}
181+
182+
void Application::update() {
183+
if (!m_interface.overlay->wants_to_handle_input())
184+
m_controller->handle_keyboard(0, 0, m_time.delta);
185+
186+
// Rotate the vector around the ZX plane
187+
auto light = m_scene->get_lights()[0];
188+
if (animateLight)
189+
{
190+
float rotationAngle = glm::radians(10.0f * m_time.delta);
191+
float _x = light->get_position().x * cos(rotationAngle) - light->get_position().z * sin(rotationAngle);
192+
float _z = light->get_position().x * sin(rotationAngle) + light->get_position().z * cos(rotationAngle);
193+
194+
light->set_position({_x, light->get_position().y, _z});
195+
}
196+
197+
m_interface.object->set_object(m_interface.scene->get_selected_object());
198+
}
199+
200+
void Application::tick() {
201+
float currentTime = (float)m_window->get_time_elapsed();
202+
m_time.delta = currentTime - m_time.last;
203+
m_time.last = currentTime;
204+
m_time.framesPerSecond = 1.0f / m_time.delta;
205+
206+
update();
207+
208+
m_interface.overlay->render();
209+
m_renderer->render(m_scene);
210+
}

0 commit comments

Comments
 (0)