aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/aabb.hpp13
-rw-r--r--shaders/compute.comp28
-rw-r--r--src/main.cpp37
3 files changed, 59 insertions, 19 deletions
diff --git a/include/aabb.hpp b/include/aabb.hpp
new file mode 100644
index 0000000..9ec1f3f
--- /dev/null
+++ b/include/aabb.hpp
@@ -0,0 +1,13 @@
+#ifndef __AABB_HPP_
+#define __AABB_HPP_
+
+#include "vec3.hpp"
+
+class AABB {
+ AABB(vec3 min_point, vec3 max_point): minimum(min_point), maximum(max_point) {}
+
+ vec3 minimum;
+ vec3 maximum;
+};
+
+#endif // !__AABB_HPP_
diff --git a/shaders/compute.comp b/shaders/compute.comp
index b70b021..3510d52 100644
--- a/shaders/compute.comp
+++ b/shaders/compute.comp
@@ -34,6 +34,11 @@ struct sphere {
float[3] padding;
};
+struct aabb {
+ vec4 min;
+ vec4 max;
+};
+
struct camera {
vec4 position;
@@ -88,6 +93,29 @@ float rand(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
+bool hit_aabb(aabb b, ray r, float min_t, float max_t) {
+ for (int axis_index = 0; axis_index < 3; axis_index++) {
+ float inv_dir = 1.f / r.direction[axis_index];
+ float t0 = (b.min[axis_index] - r.origin[axis_index]) * inv_dir;
+ float t1 = (b.max[axis_index] - r.origin[axis_index]) * inv_dir;
+
+ if (inv_dir < 0.f) {
+ float temp = t0;
+ t0 = t1;
+ t1 = t0;
+ }
+
+ min_t = max(t0, min_t);
+ max_t = min(t1, max_t);
+
+ if (max_t < min_t) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
bool hit_sphere(sphere s, ray r, float min_t, float max_t, out hit_info info) {
vec3 origin_center = r.origin - s.position.xyz;
diff --git a/src/main.cpp b/src/main.cpp
index 56e924d..553191a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,24 +19,6 @@
#include <Windows.h>
#endif
-void gui(input_data* mapped_input_data, bool &reset_accumulation) {
- ImGui::NewFrame();
-
- ImGui::SetNextWindowPos({ 0.f, 0.f });
- ImGui::SetNextWindowSize({ 0.f, 0.f });
- ImGui::Begin("Debug", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar);
-
- if (ImGui::SliderInt("samples per pixel", (int32_t*)&mapped_input_data->samples_per_pixel, 1, 1000)) {
- reset_accumulation = true;
- }
-
- ImGui::SliderInt("bounces", (int32_t*)&mapped_input_data->max_bounce, 2, 250);
-
- ImGui::End();
-
- ImGui::EndFrame();
-}
-
int main() {
RENDERDOC_API_1_1_2 *rdoc_api = NULL;
@@ -185,7 +167,24 @@ int main() {
wnd.events.clear();
- gui((input_data*)renderer.compute_shader_buffer.alloc_info.pMappedData, reset_accumulation);
+ // GUI
+ ImGui::NewFrame();
+
+ ImGui::SetNextWindowPos({ 0.f, 0.f });
+ ImGui::SetNextWindowSize({ 0.f, 0.f });
+ ImGui::Begin("Debug", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar);
+
+ ImGui::Text("frame time %f ms\n", delta_time);
+
+ if (ImGui::SliderInt("samples per pixel", (int32_t*)&((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->samples_per_pixel, 1, 1000)) {
+ reset_accumulation = true;
+ }
+
+ ImGui::SliderInt("bounces", (int32_t*)&((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->max_bounce, 2, 250);
+
+ ImGui::End();
+
+ ImGui::EndFrame();
// To start a frame capture, call StartFrameCapture.
// You can specify NULL, NULL for the device to capture on if you have only one device and