diff --git a/imgui.ini b/imgui.ini index 8d9b717..ed64e33 100644 --- a/imgui.ini +++ b/imgui.ini @@ -3,6 +3,6 @@ Pos=60,60 Size=400,400 [Window][Settings] -Pos=1508,73 +Pos=1511,75 Size=368,276 diff --git a/includes/RT/Camera.hpp b/includes/RT/Camera.hpp index b6b5c1c..32886fb 100644 --- a/includes/RT/Camera.hpp +++ b/includes/RT/Camera.hpp @@ -42,14 +42,14 @@ class Camera glm::vec3 getPosition(); glm::vec2 getDirection(); - glm::vec3 getViewSetting(); glm::mat4 getViewMatrix(); - int getBounce(); - - float getFov(); float getVelocity(); + float &getFov(); + float &getAperture(); + float &getFocus(); + int &getBounce(); GPUCamera getGPUData(); diff --git a/includes/RT/Window.hpp b/includes/RT/Window.hpp index d6392e1..803f58f 100644 --- a/includes/RT/Window.hpp +++ b/includes/RT/Window.hpp @@ -33,6 +33,9 @@ class Window static void mouseMoveCallback(GLFWwindow *window, double xpos, double ypos); static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods); + void imGuiNewFrame(); + void imGuiRender(); + GLFWwindow *getWindow(void) const; float getFps(void) const; int getFrameCount(void) const; diff --git a/scenes/pillard.rt b/scenes/pillard.rt index 5bcce62..5cb9db8 100644 --- a/scenes/pillard.rt +++ b/scenes/pillard.rt @@ -1,4 +1,4 @@ -CAM 18.2756 8.40071 48.9905 -0.2 -470.601 0.1 23.9 45 10 +CAM 18.2756 8.40071 48.9905 -0.4 -466.401 0.249 23.227 45 10 MAT 255 050 050 1.0 0.0 0.0 // 0 red MAT 050 255 050 1.0 0.0 0.0 // 1 green diff --git a/srcs/RT.cpp b/srcs/RT.cpp index 735965c..91c6d38 100644 --- a/srcs/RT.cpp +++ b/srcs/RT.cpp @@ -22,13 +22,6 @@ int main(int argc, char **argv) Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0); Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl"); - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO &io = ImGui::GetIO(); (void)io; - ImGui::StyleColorsDark(); - ImGui_ImplGlfw_InitForOpenGL(window.getWindow(), true); - ImGui_ImplOpenGL3_Init("#version 430"); - GLint max_gpu_size; glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size); @@ -88,20 +81,12 @@ int main(int argc, char **argv) glClear(GL_COLOR_BUFFER_BIT); - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + window.imGuiNewFrame(); glUseProgram(shader.getProgram()); shader.drawTriangles(size); - ImGui::Begin("Settings"); - ImGui::Text("Fps: %d", int(window.getFps())); - ImGui::Checkbox("Accumulate", &window.getAccumulate()); - ImGui::End(); - - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + window.imGuiRender(); window.display(); window.pollEvents(); diff --git a/srcs/class/Camera.cpp b/srcs/class/Camera.cpp index 6e2ae36..f032560 100644 --- a/srcs/class/Camera.cpp +++ b/srcs/class/Camera.cpp @@ -100,11 +100,6 @@ glm::vec2 Camera::getDirection() return (glm::vec2(_pitch, _yaw)); } -glm::vec3 Camera::getViewSetting() -{ - return (glm::vec3(_aperture_size, _focus_distance, _fov)); -} - GPUCamera Camera::getGPUData() { GPUCamera data; @@ -126,11 +121,26 @@ float Camera::getVelocity() return (glm::length(_velocity)); } -int Camera::getBounce() +int &Camera::getBounce() { return (_bounce); } +float &Camera::getFov() +{ + return (_fov); +} + +float &Camera::getAperture() +{ + return (_aperture_size); +} + +float &Camera::getFocus() +{ + return (_focus_distance); +} + void Camera::setPosition(glm::vec3 position) { _position = position; diff --git a/srcs/class/Window.cpp b/srcs/class/Window.cpp index 345feae..04aef6b 100644 --- a/srcs/class/Window.cpp +++ b/srcs/class/Window.cpp @@ -45,6 +45,13 @@ Window::Window(Scene *scene, int width, int height, const char *title, int sleep gladLoadGL(glfwGetProcAddress); glfwSwapInterval(sleep); + + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO &io = ImGui::GetIO(); (void)io; + ImGui::StyleColorsDark(); + ImGui_ImplGlfw_InitForOpenGL(_window, true); + ImGui_ImplOpenGL3_Init("#version 430"); } Window::~Window(void) @@ -111,12 +118,14 @@ void Window::keyCallback(GLFWwindow *window, int key, int scancode, int action, { glm::vec3 pos = win->_scene->getCamera()->getPosition(); glm::vec2 dir = win->_scene->getCamera()->getDirection(); - glm::vec3 settings = win->_scene->getCamera()->getViewSetting(); + float aperture = win->_scene->getCamera()->getAperture(); + float focus = win->_scene->getCamera()->getFocus(); + float fov = win->_scene->getCamera()->getFov(); int bounce = win->_scene->getCamera()->getBounce(); std::cout << "\nCAM\t" << pos.x << " " << pos.y << " " << pos.z << "\t" << dir.x << " " << dir.y << " " << "\t" - << settings.x << " " << settings.y << " " << settings.z << "\t" << bounce + << aperture << " " << focus << " " << fov << "\t" << bounce << std::endl; } } @@ -151,6 +160,42 @@ bool Window::shouldClose() return glfwWindowShouldClose(_window); } +void Window::imGuiNewFrame() +{ + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); +} + +void Window::imGuiRender() +{ + bool has_changed = false; + + ImGui::Begin("Settings"); + + ImGui::Text("Fps: %d", int(_fps)); + ImGui::Text("Frame: %d", _frameCount); + + if (ImGui::CollapsingHeader("Camera")) + { + if (ImGui::Checkbox("Accumulate", &accumulate)) + _frameCount = 0; + + has_changed |= ImGui::SliderInt("Bounce", &_scene->getCamera()->getBounce(), 0, 20); + has_changed |= ImGui::SliderFloat("FOV", &_scene->getCamera()->getFov(), 1.0f, 180.0f); + has_changed |= ImGui::SliderFloat("Aperture", &_scene->getCamera()->getAperture(), 0.0f, 1.0f); + has_changed |= ImGui::SliderFloat("Focus", &_scene->getCamera()->getFocus(), 0.0f, 150.0f); + } + + ImGui::End(); + + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + if (has_changed) + _frameCount = -1; +} + GLFWwindow *Window::getWindow(void) const { return (_window);