This commit is contained in:
Gamemaker1998
2025-01-24 23:23:24 +01:00
9 changed files with 72 additions and 19 deletions
+1
View File
@@ -17,6 +17,7 @@
mono_crash.*
# Build results
build/
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
+2
View File
@@ -16,11 +16,13 @@ find_package(assimp CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(Ktx CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
add_executable(RayTracer "")
target_include_directories(RayTracer PUBLIC src/)
target_link_libraries(RayTracer PUBLIC assimp::assimp)
target_link_libraries(RayTracer PUBLIC glfw)
target_link_libraries(RayTracer PUBLIC imgui::imgui)
if(APPLE)
target_link_libraries(RayTracer PUBLIC GLEW::GLEW)
else()
+3 -4
View File
@@ -5,7 +5,7 @@
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\bin\\${name}",
"buildRoot": "${projectDir}\\build",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
@@ -16,14 +16,13 @@
"name": "Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\bin\\${name}",
"buildRoot": "${projectDir}\\build",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
"inheritEnvironments": [ "msvc_x64_x64" ]
}
]
}
+7 -2
View File
@@ -2,7 +2,8 @@
#include "scene/Scene.h"
#include "util/ModelLoader.h"
#include "window/Window.h"
#include "util/ModelLoader.h"
#include <iostream>
#include <imgui.h>
int main()
{
@@ -18,9 +19,13 @@ int main()
.height = 1080,
.numSamples = 10000,
});
while (true)
{
window.beginFrame();
if (ImGui::Button("Test"))
{
std::cout << "Test" << std::endl;
}
window.update(scene.getImage());
}
return 0;
+16 -9
View File
@@ -1,20 +1,27 @@
#include "BVH.h"
#include <algorithm>
#include <ranges>
#include <iostream>
void BVH::addModel(PModel model, glm::mat4 transform)
{
model->boundingBox.transform(transform);
for (auto& point : model->positions)
{
point = glm::vec3(transform * glm::vec4(point, 1));
}
models.push_back(std::move(model));
}
void BVH::addModels(std::vector<PModel> _models, glm::mat4 transform)
{
for (auto& _model : _models)
for (int i = 0; i < _models.size(); ++i)
{
_model->boundingBox.transform(transform);
models.push_back(std::move(_model));
_models[i]->boundingBox.transform(transform);
for (auto& point : _models[i]->positions)
{
point = glm::vec3(transform * glm::vec4(point, 1));
}
models.push_back(std::move(_models[i]));
}
}
@@ -61,13 +68,13 @@ std::optional<IntersectionInfo> BVH::traceRay(Ray ray)
{
auto results = generateIntersections(hierarchy, ray);
float closestT = std::numeric_limits<float>::max();
std::optional<IntersectionInfo> info = {};
for (auto& result : results)
IntersectionInfo info;
for (uint32_t i = 0; i < results.size(); ++i)
{
if (result.t < closestT)
if (results[i].t < closestT)
{
closestT = result.t;
info = result;
closestT = results[i].t;
info = results[i];
}
}
if (closestT < std::numeric_limits<float>::max())
+1 -1
View File
@@ -29,7 +29,7 @@ void Scene::render(Camera cam, RenderParameter params)
image.resize(params.width * params.height);
accumulator.resize(params.width * params.height);
worker = std::thread(
[&]()
[&, cam, params]()
{
for (int samp = 0; samp < params.numSamples; ++samp)
{
+28 -2
View File
@@ -1,5 +1,8 @@
#include "Window.h"
#include <iostream>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#define GLSL(...) "#version 400\n" #__VA_ARGS__
@@ -12,13 +15,27 @@ Window::Window(int width, int height) : width(width), height(height)
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
window = glfwCreateWindow(width, height, "RayTracer", nullptr, nullptr);
glfwMakeContextCurrent(window);
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
ImGui_ImplGlfw_InitForOpenGL(window,
true); // Second param install_callback=true will install GLFW callbacks and chain to existing ones.
ImGui_ImplOpenGL3_Init();
glewInit();
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
program = glCreateProgram();
vertShader = glCreateShader(GL_VERTEX_SHADER);
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
@@ -75,13 +92,22 @@ Window::Window(int width, int height) : width(width), height(height)
Window::~Window() {}
void Window::update(const std::vector<glm::vec3>& textureData)
void Window::beginFrame()
{
glClear(GL_COLOR_BUFFER_BIT);
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}
void Window::update(const std::vector<glm::vec3>& textureData)
{
glBindTexture(GL_TEXTURE_2D, texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_FLOAT, textureData.data());
glUseProgram(program);
glDrawArrays(GL_TRIANGLES, 0, 3);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
glfwPollEvents();
}
+1
View File
@@ -9,6 +9,7 @@ class Window
public:
Window(int width, int height);
~Window();
void beginFrame();
void update(const std::vector<glm::vec3>& textureData);
private:
+13 -1
View File
@@ -1,3 +1,15 @@
{
"dependencies": ["assimp", "ktx", "glfw3", "glew", "glm", "stb", "fmt"]
"dependencies": [
{
"name": "imgui",
"features": [ "glfw-binding", "opengl3-binding" ]
},
"assimp",
"ktx",
"glfw3",
"glew",
"glm",
"stb",
"fmt"
]
}