diff --git a/.gitignore b/.gitignore index 9491a2f..ed98b68 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ mono_crash.* # Build results +build/ [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 3365fdf..7c1ed07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/CMakeSettings.json b/CMakeSettings.json index 7a02fa3..58d73dd 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -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" ] } ] } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 88dfbe4..fb9bb1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,8 @@ #include "scene/Scene.h" #include "util/ModelLoader.h" #include "window/Window.h" +#include +#include int main() { @@ -19,6 +21,11 @@ int main() }); while (true) { + window.beginFrame(); + if (ImGui::Button("Test")) + { + std::cout << "Test" << std::endl; + } window.update(scene.getImage()); } return 0; diff --git a/src/scene/BVH.cpp b/src/scene/BVH.cpp index e754f9c..82e7ca3 100644 --- a/src/scene/BVH.cpp +++ b/src/scene/BVH.cpp @@ -5,6 +5,10 @@ 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)); } @@ -13,6 +17,10 @@ void BVH::addModels(std::vector _models, glm::mat4 transform) for (int i = 0; i < _models.size(); ++i) { _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])); } } diff --git a/src/scene/Scene.cpp b/src/scene/Scene.cpp index 93d0efc..cf28ee5 100644 --- a/src/scene/Scene.cpp +++ b/src/scene/Scene.cpp @@ -21,7 +21,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) { diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 96a2877..d242e2f 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -1,5 +1,8 @@ #include "Window.h" #include +#include +#include +#include #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& textureData) +void Window::beginFrame() { glClear(GL_COLOR_BUFFER_BIT); + glfwPollEvents(); + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); +} + +void Window::update(const std::vector& 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(); } diff --git a/src/window/Window.h b/src/window/Window.h index c5bc3fa..5c1a4be 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -9,6 +9,7 @@ class Window public: Window(int width, int height); ~Window(); + void beginFrame(); void update(const std::vector& textureData); private: diff --git a/vcpkg.json b/vcpkg.json index 08cd872..7e3fffa 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -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" + ] } \ No newline at end of file