diff --git a/Step 3/.idea/codeStyles/Project.xml b/Step 3/.idea/codeStyles/Project.xml
index a7819ce..52a841b 100644
--- a/Step 3/.idea/codeStyles/Project.xml
+++ b/Step 3/.idea/codeStyles/Project.xml
@@ -14,7 +14,7 @@
-
+
diff --git a/Step 3/cmake-build-debug/build.ninja b/Step 3/cmake-build-debug/build.ninja
index ec89601..dedb0a0 100644
--- a/Step 3/cmake-build-debug/build.ninja
+++ b/Step 3/cmake-build-debug/build.ninja
@@ -265,6 +265,14 @@ build CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o: CXX_COMPILER__Step_3_Debug /hom
OBJECT_DIR = CMakeFiles/Step_3.dir
OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/opencl
+build CMakeFiles/Step_3.dir/src/opencl/open_ray_tracing.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/opencl/open_ray_tracing.cpp || cmake_object_order_depends_target_Step_3
+ DEFINES = -DCL_TARGET_OPENCL_VERSION=220
+ DEP_FILE = CMakeFiles/Step_3.dir/src/opencl/open_ray_tracing.cpp.o.d
+ FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20
+ INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include"
+ OBJECT_DIR = CMakeFiles/Step_3.dir
+ OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/opencl
+
# =============================================================================
# Link build statements for EXECUTABLE target Step_3
@@ -273,7 +281,7 @@ build CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o: CXX_COMPILER__Step_3_Debug /hom
#############################################
# Link the executable Step_3
-build Step_3: CXX_EXECUTABLE_LINKER__Step_3_Debug CMakeFiles/Step_3.dir/src/engine/globals.cpp.o CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o CMakeFiles/Step_3.dir/src/engine/main.cpp.o CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o CMakeFiles/Step_3.dir/src/engine/mpi.cpp.o CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o CMakeFiles/Step_3.dir/src/engine/util/loaders.cpp.o CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o CMakeFiles/Step_3.dir/src/engine/world.cpp.o CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o CMakeFiles/Step_3.dir/src/graphics/gl/gl.c.o CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o CMakeFiles/Step_3.dir/src/graphics/input.cpp.o CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o | /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libglfw.so.3.3 /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libOpenGL.so
+build Step_3: CXX_EXECUTABLE_LINKER__Step_3_Debug CMakeFiles/Step_3.dir/src/engine/globals.cpp.o CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o CMakeFiles/Step_3.dir/src/engine/main.cpp.o CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o CMakeFiles/Step_3.dir/src/engine/mpi.cpp.o CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o CMakeFiles/Step_3.dir/src/engine/util/loaders.cpp.o CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o CMakeFiles/Step_3.dir/src/engine/world.cpp.o CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o CMakeFiles/Step_3.dir/src/graphics/gl/gl.c.o CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o CMakeFiles/Step_3.dir/src/graphics/input.cpp.o CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o CMakeFiles/Step_3.dir/src/opencl/open_ray_tracing.cpp.o | /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libglfw.so.3.3 /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libOpenGL.so
FLAGS = -fsanitize=address -g -march=native -g
LINK_FLAGS = -fsanitize=address
LINK_LIBRARIES = -lpthread /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libglfw.so.3.3 /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libOpenGL.so
diff --git a/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/codemodel-v2-36be696f440eeb8e54fd.json b/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/codemodel-v2-73be07f725d3293e1a94.json
similarity index 93%
rename from Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/codemodel-v2-36be696f440eeb8e54fd.json
rename to Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/codemodel-v2-73be07f725d3293e1a94.json
index 26ff26e..86a4020 100644
--- a/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/codemodel-v2-36be696f440eeb8e54fd.json
+++ b/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/codemodel-v2-73be07f725d3293e1a94.json
@@ -39,7 +39,7 @@
{
"directoryIndex" : 0,
"id" : "Step_3::@6890427a1f51a3e7e1df",
- "jsonFile" : "target-Step_3-Release-c12458f55cdccc68bac1.json",
+ "jsonFile" : "target-Step_3-Release-0e16299909ee4154184a.json",
"name" : "Step_3",
"projectIndex" : 0
}
diff --git a/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/index-2022-12-03T04-29-37-0823.json b/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/index-2022-12-03T16-01-56-0331.json
similarity index 93%
rename from Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/index-2022-12-03T04-29-37-0823.json
rename to Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/index-2022-12-03T16-01-56-0331.json
index 58496ed..fb4ad6a 100644
--- a/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/index-2022-12-03T04-29-37-0823.json
+++ b/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/index-2022-12-03T16-01-56-0331.json
@@ -26,7 +26,7 @@
"objects" :
[
{
- "jsonFile" : "codemodel-v2-36be696f440eeb8e54fd.json",
+ "jsonFile" : "codemodel-v2-73be07f725d3293e1a94.json",
"kind" : "codemodel",
"version" :
{
@@ -86,7 +86,7 @@
},
"codemodel-v2" :
{
- "jsonFile" : "codemodel-v2-36be696f440eeb8e54fd.json",
+ "jsonFile" : "codemodel-v2-73be07f725d3293e1a94.json",
"kind" : "codemodel",
"version" :
{
diff --git a/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/target-Step_3-Release-c12458f55cdccc68bac1.json b/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/target-Step_3-Release-0e16299909ee4154184a.json
similarity index 96%
rename from Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/target-Step_3-Release-c12458f55cdccc68bac1.json
rename to Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/target-Step_3-Release-0e16299909ee4154184a.json
index d068300..e14b5e2 100644
--- a/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/target-Step_3-Release-c12458f55cdccc68bac1.json
+++ b/Step 3/cmake-build-release-mpi/.cmake/api/v1/reply/target-Step_3-Release-0e16299909ee4154184a.json
@@ -135,7 +135,8 @@
9,
10,
11,
- 12
+ 12,
+ 13
]
}
],
@@ -209,7 +210,8 @@
9,
10,
11,
- 12
+ 12,
+ 13
]
}
],
@@ -292,6 +294,12 @@
"compileGroupIndex" : 0,
"path" : "src/opencl/cl.cpp",
"sourceGroupIndex" : 0
+ },
+ {
+ "backtrace" : 1,
+ "compileGroupIndex" : 0,
+ "path" : "src/opencl/open_ray_tracing.cpp",
+ "sourceGroupIndex" : 0
}
],
"type" : "EXECUTABLE"
diff --git a/Step 3/cmake-build-release-mpi/build.ninja b/Step 3/cmake-build-release-mpi/build.ninja
index 633905e..69396eb 100644
--- a/Step 3/cmake-build-release-mpi/build.ninja
+++ b/Step 3/cmake-build-release-mpi/build.ninja
@@ -153,6 +153,14 @@ build CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o: CXX_COMPILER__Step_3_Release /h
OBJECT_DIR = CMakeFiles/Step_3.dir
OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/opencl
+build CMakeFiles/Step_3.dir/src/opencl/open_ray_tracing.cpp.o: CXX_COMPILER__Step_3_Release /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/opencl/open_ray_tracing.cpp || cmake_object_order_depends_target_Step_3
+ DEFINES = -DCL_TARGET_OPENCL_VERSION=220
+ DEP_FILE = CMakeFiles/Step_3.dir/src/opencl/open_ray_tracing.cpp.o.d
+ FLAGS = -march=native -O3 -DNDEBUG -std=gnu++20
+ INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-release-mpi" -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include"
+ OBJECT_DIR = CMakeFiles/Step_3.dir
+ OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/opencl
+
# =============================================================================
# Link build statements for EXECUTABLE target Step_3
@@ -161,7 +169,7 @@ build CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o: CXX_COMPILER__Step_3_Release /h
#############################################
# Link the executable Step_3
-build Step_3: CXX_EXECUTABLE_LINKER__Step_3_Release CMakeFiles/Step_3.dir/src/engine/globals.cpp.o CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o CMakeFiles/Step_3.dir/src/engine/main.cpp.o CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o CMakeFiles/Step_3.dir/src/engine/mpi.cpp.o CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o CMakeFiles/Step_3.dir/src/engine/util/loaders.cpp.o CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o CMakeFiles/Step_3.dir/src/engine/world.cpp.o CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o | /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so
+build Step_3: CXX_EXECUTABLE_LINKER__Step_3_Release CMakeFiles/Step_3.dir/src/engine/globals.cpp.o CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o CMakeFiles/Step_3.dir/src/engine/main.cpp.o CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o CMakeFiles/Step_3.dir/src/engine/mpi.cpp.o CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o CMakeFiles/Step_3.dir/src/engine/util/loaders.cpp.o CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o CMakeFiles/Step_3.dir/src/engine/world.cpp.o CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o CMakeFiles/Step_3.dir/src/opencl/open_ray_tracing.cpp.o | /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so
FLAGS = -march=native -O3 -DNDEBUG
LINK_LIBRARIES = -Wl,-rpath,/usr/lib/x86_64-linux-gnu/openmpi/lib -lpthread /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so
OBJECT_DIR = CMakeFiles/Step_3.dir
diff --git a/Step 3/include/engine/util/memory_util.h b/Step 3/include/engine/util/memory_util.h
new file mode 100644
index 0000000..2c6008d
--- /dev/null
+++ b/Step 3/include/engine/util/memory_util.h
@@ -0,0 +1,59 @@
+/*
+ * Created by Brett Terpstra 6920201 on 03/12/22.
+ * Copyright (c) 2022 Brett Terpstra. All Rights Reserved.
+ */
+
+#ifndef STEP_3_MEMORY_UTIL_H
+#define STEP_3_MEMORY_UTIL_H
+
+#include
+
+#define ENDIAN_FLIP
+
+namespace Raytracing {
+
+ class MemoryConvert {
+ private:
+ public:
+ /**
+ * returns the bytes from the double ordered based on if ENDIAN_FLIP is defined or not
+ */
+ inline static std::vector getDoubleBytes(double d) {
+ std::vector bytes;
+ auto* doubleAsBytes = reinterpret_cast(&d);
+#ifdef ENDIAN_FLIP
+ for (int i = 0; i < sizeof(double); i++)
+ bytes.push_back(doubleAsBytes[i]);
+#else
+ for (int i = 0; i < sizeof(double); i++)
+ bytes.push_back(doubleAsBytes[sizeof(double) - i]);
+#endif
+ return bytes;
+ }
+
+ /**
+ * Note: this is used for the GPU and it is assumed that you are using double precision values.
+ * Anything else is undefined. (Should be fine though since upcasting is fine)
+ * @param array array to write into
+ * @param offset offset of where to start writing into. Will update this value as it moves through the vector
+ * @param vec the vector to write
+ */
+ inline static void writeVectorBytes(unsigned char* array, size_t& offset, const Vec4& vec) {
+ auto x = getDoubleBytes(vec.x());
+ auto y = getDoubleBytes(vec.y());
+ auto z = getDoubleBytes(vec.z());
+ auto w = getDoubleBytes(vec.w());
+ // write the bytes as a packed vector.
+ for (auto b: x)
+ array[offset++] = b;
+ for (auto b: y)
+ array[offset++] = b;
+ for (auto b: z)
+ array[offset++] = b;
+ for (auto b: w)
+ array[offset++] = b;
+ }
+ };
+}
+
+#endif //STEP_3_MEMORY_UTIL_H
diff --git a/Step 3/include/engine/util/models.h b/Step 3/include/engine/util/models.h
index 8d9d2dc..1185083 100644
--- a/Step 3/include/engine/util/models.h
+++ b/Step 3/include/engine/util/models.h
@@ -18,14 +18,12 @@ namespace Raytracing {
Vec4 vertex1, vertex2, vertex3;
Vec4 normal1, normal2, normal3;
Vec4 uv1, uv2, uv3;
- bool hasNormals = false;
AABB aabb;
- Triangle(const Vec4& v1, const Vec4& v2, const Vec4& v3,
- const Vec4& uv1, const Vec4& uv2, const Vec4& uv3,
- const Vec4& n1, const Vec4& n2, const Vec4& n3): vertex1(v1), vertex2(v2), vertex3(v3),
- uv1(uv1), uv2(uv2), uv3(uv3),
- hasNormals(true), normal1(n1), normal2(n2), normal3(n3) {}
+ Triangle(
+ const Vec4& v1, const Vec4& v2, const Vec4& v3, const Vec4& uv1, const Vec4& uv2, const Vec4& uv3, const Vec4& n1, const Vec4& n2,
+ const Vec4& n3
+ ): vertex1(v1), vertex2(v2), vertex3(v3), uv1(uv1), uv2(uv2), uv3(uv3), normal1(n1), normal2(n2), normal3(n3) {}
};
// face type for model loading
@@ -34,7 +32,7 @@ namespace Raytracing {
int uv1, uv2, uv3;
int n1, n2, n3;
};
-
+
struct ModelData {
// storing all this data is memory inefficient
// since normals and vertices are only vec3s
@@ -49,10 +47,10 @@ namespace Raytracing {
struct TriangulatedModel {
std::vector> triangles;
AABB aabb;
-
+
explicit TriangulatedModel(const ModelData& data);
};
-
+
class OBJLoader {
private:
public:
diff --git a/Step 3/include/engine/world.h b/Step 3/include/engine/world.h
index a1c49cb..516c2a1 100644
--- a/Step 3/include/engine/world.h
+++ b/Step 3/include/engine/world.h
@@ -13,25 +13,28 @@
#include "types.h"
#include
+
#ifdef COMPILE_GUI
+
#include "graphics/gl/shader.h"
#include "graphics/debug_gui.h"
+
#endif
#include
namespace Raytracing {
-
+
class SphereObject : public Object {
private:
PRECISION_TYPE radius;
public:
SphereObject(const Vec4& position, PRECISION_TYPE radius, Material* material): radius(radius), Object(material, position) {}
-
+
[[nodiscard]] virtual HitData checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const;
};
-
+
class ModelObject : public Object {
private:
std::vector> triangles;
@@ -39,11 +42,11 @@ namespace Raytracing {
public:
ModelObject(const Vec4& position, ModelData& data, Material* material): Object(material, position) {
// since all of this occurs before the main ray tracing algorithm it's fine to do sequentially
- TriangulatedModel model {data};
+ TriangulatedModel model{data};
this->triangles = model.triangles;
this->aabb = std::move(model.aabb);
std::vector triangulatedObjects;
- for (const auto& tri : triangles){
+ for (const auto& tri: triangles) {
TriangleBVHObject triangleObject;
triangleObject.tri = tri;
triangleObject.aabb = tri->aabb;
@@ -51,59 +54,66 @@ namespace Raytracing {
triangulatedObjects.push_back(triangleObject);
}
triangleBVH = std::make_unique(triangulatedObjects);
- #ifdef COMPILE_GUI
- vao = new VAO(triangles);
- #endif
+#ifdef COMPILE_GUI
+ vao = new VAO(triangles);
+#endif
}
- [[nodiscard]] virtual DebugBVHData getBVHTree(){return {triangleBVH.get(), false}; }
+
+ [[nodiscard]] virtual DebugBVHData getBVHTree() { return {triangleBVH.get(), false}; }
+
+ [[nodiscard]] virtual std::vector> getTriangles() { return triangles; }
+
[[nodiscard]] virtual HitData checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const;
};
-
+
class DiffuseMaterial : public Material {
private:
public:
explicit DiffuseMaterial(const Vec4& scatterColor): Material(scatterColor) {}
-
+
[[nodiscard]] virtual ScatterResults scatter(const Ray& ray, const HitData& hitData) const override;
};
-
+
class MetalMaterial : public Material {
protected:
static inline Vec4 reflect(const Vec4& incomingVector, const Vec4& normal) {
return incomingVector - 2 * Vec4::dot(incomingVector, normal) * normal;
}
-
+
public:
explicit MetalMaterial(const Vec4& metalColor): Material(metalColor) {}
-
+
[[nodiscard]] virtual ScatterResults scatter(const Ray& ray, const HitData& hitData) const override;
};
-
+
class BrushedMetalMaterial : public MetalMaterial {
private:
PRECISION_TYPE fuzzyness;
public:
explicit BrushedMetalMaterial(const Vec4& metalColor, PRECISION_TYPE fuzzyness): MetalMaterial(metalColor), fuzzyness(fuzzyness) {}
-
+
[[nodiscard]] virtual ScatterResults scatter(const Ray& ray, const HitData& hitData) const override;
-
+
};
class LightMaterial : public Material {
public:
explicit LightMaterial(const Vec4& lightColor): Material(lightColor) {}
+
[[nodiscard]] virtual ScatterResults scatter(const Ray& ray, const HitData& hitData) const override;
+
[[nodiscard]] virtual Vec4 emission(PRECISION_TYPE u, PRECISION_TYPE v, const Vec4& hitPoint) const override;
};
-
+
class TexturedMaterial : public Material {
protected:
int width{}, height{}, channels{};
unsigned char* data;
public:
explicit TexturedMaterial(const std::string& file);
-
+
[[nodiscard]] virtual ScatterResults scatter(const Ray& ray, const HitData& hitData) const override;
+
[[nodiscard]] Vec4 getColor(PRECISION_TYPE u, PRECISION_TYPE v) const;
~TexturedMaterial();
@@ -116,9 +126,10 @@ namespace Raytracing {
Shader& worldShader;
explicit WorldConfig(Shader& shader): worldShader(shader) {}
+
#endif
};
-
+
class World {
private:
// store all the objects in the world,
@@ -128,34 +139,42 @@ namespace Raytracing {
WorldConfig m_config;
public:
explicit World(WorldConfig config): m_config(config) {};
+
World(const World& world) = delete;
+
World(const World&& world) = delete;
-
+
// Called by the raytracer class after all objects have been added to the world
// this allows us to generate a statically unchanging BVH for easy rendering
void generateBVH();
- #ifdef COMPILE_GUI
- // currently disabled. TODO: BVH renderer class
- void drawBVH(Shader& worldShader) {}
- #endif
- inline void add(Object* object) {
- objects.push_back(object);
#ifdef COMPILE_GUI
- if (object->getBVHTree().bvhTree != nullptr && !object->getBVHTree().isRegular)
- new DebugBVH{(TriangleBVHTree*) object->getBVHTree().bvhTree, m_config.worldShader};
+
+ // currently disabled. TODO: BVH renderer class
+ void drawBVH(Shader& worldShader) {}
+
#endif
- }
-
+
+ inline void add(Object* object) {
+ objects.push_back(object);
+#ifdef COMPILE_GUI
+ if (object->getBVHTree().bvhTree != nullptr && !object->getBVHTree().isRegular)
+ new DebugBVH{(TriangleBVHTree*) object->getBVHTree().bvhTree, m_config.worldShader};
+#endif
+ }
+
inline void add(const std::string& materialName, Material* mat) { materials.insert({materialName, mat}); }
-
+
inline Material* getMaterial(const std::string& materialName) { return materials.at(materialName); }
+
[[nodiscard]] inline BVHTree* getBVH() { return bvhObjects.get(); }
- [[nodiscard]] inline std::vector