Merged
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
mono_crash.*
|
mono_crash.*
|
||||||
|
|
||||||
# Build results
|
# Build results
|
||||||
|
build/
|
||||||
[Dd]ebug/
|
[Dd]ebug/
|
||||||
[Dd]ebugPublic/
|
[Dd]ebugPublic/
|
||||||
[Rr]elease/
|
[Rr]elease/
|
||||||
|
|||||||
@@ -16,11 +16,13 @@ find_package(assimp CONFIG REQUIRED)
|
|||||||
find_package(glfw3 CONFIG REQUIRED)
|
find_package(glfw3 CONFIG REQUIRED)
|
||||||
find_package(glm CONFIG REQUIRED)
|
find_package(glm CONFIG REQUIRED)
|
||||||
find_package(Ktx CONFIG REQUIRED)
|
find_package(Ktx CONFIG REQUIRED)
|
||||||
|
find_package(imgui CONFIG REQUIRED)
|
||||||
|
|
||||||
add_executable(RayTracer "")
|
add_executable(RayTracer "")
|
||||||
target_include_directories(RayTracer PUBLIC src/)
|
target_include_directories(RayTracer PUBLIC src/)
|
||||||
target_link_libraries(RayTracer PUBLIC assimp::assimp)
|
target_link_libraries(RayTracer PUBLIC assimp::assimp)
|
||||||
target_link_libraries(RayTracer PUBLIC glfw)
|
target_link_libraries(RayTracer PUBLIC glfw)
|
||||||
|
target_link_libraries(RayTracer PUBLIC imgui::imgui)
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
target_link_libraries(RayTracer PUBLIC GLEW::GLEW)
|
target_link_libraries(RayTracer PUBLIC GLEW::GLEW)
|
||||||
else()
|
else()
|
||||||
|
|||||||
+3
-4
@@ -5,7 +5,7 @@
|
|||||||
"generator": "Ninja",
|
"generator": "Ninja",
|
||||||
"configurationType": "Debug",
|
"configurationType": "Debug",
|
||||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||||
"buildRoot": "${projectDir}\\bin\\${name}",
|
"buildRoot": "${projectDir}\\build",
|
||||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||||
"cmakeCommandArgs": "",
|
"cmakeCommandArgs": "",
|
||||||
"buildCommandArgs": "",
|
"buildCommandArgs": "",
|
||||||
@@ -16,14 +16,13 @@
|
|||||||
"name": "Release",
|
"name": "Release",
|
||||||
"generator": "Ninja",
|
"generator": "Ninja",
|
||||||
"configurationType": "RelWithDebInfo",
|
"configurationType": "RelWithDebInfo",
|
||||||
"buildRoot": "${projectDir}\\bin\\${name}",
|
"buildRoot": "${projectDir}\\build",
|
||||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||||
"cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe",
|
"cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe",
|
||||||
"cmakeCommandArgs": "",
|
"cmakeCommandArgs": "",
|
||||||
"buildCommandArgs": "",
|
"buildCommandArgs": "",
|
||||||
"ctestCommandArgs": "",
|
"ctestCommandArgs": "",
|
||||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
"inheritEnvironments": [ "msvc_x64_x64" ]
|
||||||
"variables": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+7
-2
@@ -2,7 +2,8 @@
|
|||||||
#include "scene/Scene.h"
|
#include "scene/Scene.h"
|
||||||
#include "util/ModelLoader.h"
|
#include "util/ModelLoader.h"
|
||||||
#include "window/Window.h"
|
#include "window/Window.h"
|
||||||
#include "util/ModelLoader.h"
|
#include <iostream>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -18,9 +19,13 @@ int main()
|
|||||||
.height = 1080,
|
.height = 1080,
|
||||||
.numSamples = 10000,
|
.numSamples = 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
window.beginFrame();
|
||||||
|
if (ImGui::Button("Test"))
|
||||||
|
{
|
||||||
|
std::cout << "Test" << std::endl;
|
||||||
|
}
|
||||||
window.update(scene.getImage());
|
window.update(scene.getImage());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+16
-9
@@ -1,20 +1,27 @@
|
|||||||
#include "BVH.h"
|
#include "BVH.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
void BVH::addModel(PModel model, glm::mat4 transform)
|
void BVH::addModel(PModel model, glm::mat4 transform)
|
||||||
{
|
{
|
||||||
model->boundingBox.transform(transform);
|
model->boundingBox.transform(transform);
|
||||||
|
for (auto& point : model->positions)
|
||||||
|
{
|
||||||
|
point = glm::vec3(transform * glm::vec4(point, 1));
|
||||||
|
}
|
||||||
models.push_back(std::move(model));
|
models.push_back(std::move(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BVH::addModels(std::vector<PModel> _models, glm::mat4 transform)
|
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[i]->boundingBox.transform(transform);
|
||||||
models.push_back(std::move(_model));
|
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);
|
auto results = generateIntersections(hierarchy, ray);
|
||||||
float closestT = std::numeric_limits<float>::max();
|
float closestT = std::numeric_limits<float>::max();
|
||||||
std::optional<IntersectionInfo> info = {};
|
IntersectionInfo info;
|
||||||
for (auto& result : results)
|
for (uint32_t i = 0; i < results.size(); ++i)
|
||||||
{
|
{
|
||||||
if (result.t < closestT)
|
if (results[i].t < closestT)
|
||||||
{
|
{
|
||||||
closestT = result.t;
|
closestT = results[i].t;
|
||||||
info = result;
|
info = results[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (closestT < std::numeric_limits<float>::max())
|
if (closestT < std::numeric_limits<float>::max())
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ void Scene::render(Camera cam, RenderParameter params)
|
|||||||
image.resize(params.width * params.height);
|
image.resize(params.width * params.height);
|
||||||
accumulator.resize(params.width * params.height);
|
accumulator.resize(params.width * params.height);
|
||||||
worker = std::thread(
|
worker = std::thread(
|
||||||
[&]()
|
[&, cam, params]()
|
||||||
{
|
{
|
||||||
for (int samp = 0; samp < params.numSamples; ++samp)
|
for (int samp = 0; samp < params.numSamples; ++samp)
|
||||||
{
|
{
|
||||||
|
|||||||
+28
-2
@@ -1,5 +1,8 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <imgui_impl_glfw.h>
|
||||||
|
#include <imgui_impl_opengl3.h>
|
||||||
|
|
||||||
#define GLSL(...) "#version 400\n" #__VA_ARGS__
|
#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
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
|
||||||
window = glfwCreateWindow(width, height, "RayTracer", nullptr, nullptr);
|
window = glfwCreateWindow(width, height, "RayTracer", nullptr, nullptr);
|
||||||
glfwMakeContextCurrent(window);
|
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();
|
glewInit();
|
||||||
|
|
||||||
glGenVertexArrays(1, &vao);
|
glGenVertexArrays(1, &vao);
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
|
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &texture);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
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);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
|
||||||
program = glCreateProgram();
|
program = glCreateProgram();
|
||||||
vertShader = glCreateShader(GL_VERTEX_SHADER);
|
vertShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
@@ -75,13 +92,22 @@ Window::Window(int width, int height) : width(width), height(height)
|
|||||||
|
|
||||||
Window::~Window() {}
|
Window::~Window() {}
|
||||||
|
|
||||||
void Window::update(const std::vector<glm::vec3>& textureData)
|
void Window::beginFrame()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
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);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_FLOAT, textureData.data());
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_FLOAT, textureData.data());
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
|
ImGui::Render();
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class Window
|
|||||||
public:
|
public:
|
||||||
Window(int width, int height);
|
Window(int width, int height);
|
||||||
~Window();
|
~Window();
|
||||||
|
void beginFrame();
|
||||||
void update(const std::vector<glm::vec3>& textureData);
|
void update(const std::vector<glm::vec3>& textureData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+13
-1
@@ -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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user