diff --git a/include/App.h b/include/App.h index 75467fa2b3286fe0e8193a89aa4c40e18224e21e..f88f6de6ca0b93e579aa3a393aa3988939f24be2 100644 --- a/include/App.h +++ b/include/App.h @@ -44,6 +44,8 @@ private: Viewport *v; + float frametime; + bool ShouldClose; public: diff --git a/resources/shaders/basicFragment.glsl b/resources/shaders/basicFragment.glsl index d79dcdc0cb345644b5e19bd7caafb5578ff65460..bcf25188f3a18b3d5a8f4960aaf9df88ae59e946 100644 --- a/resources/shaders/basicFragment.glsl +++ b/resources/shaders/basicFragment.glsl @@ -10,10 +10,10 @@ in vec3 pos; void main(){ vec3 lightColor = vec3(1.0, 1.0, 1.0); - vec3 objectColor = vec3(0.9); + vec3 objectColor = vec3(1.0); // ambient - float ambientStrength = 0.2; + float ambientStrength = 0.1; vec3 ambient = ambientStrength * lightColor; // diffuse @@ -23,13 +23,10 @@ void main(){ vec3 diffuse = diff * lightColor; // specular - float specularStrength = 0.7; + float specularStrength = 0.5; vec3 viewDir = normalize(cameraPos - pos); - vec3 reflectDir = reflect(-lightDir, norm); + vec3 reflectDir = reflect(-lightDir, norm); float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32); - vec3 specular = specularStrength * spec * lightColor; - - vec3 result = diffuse * objectColor; - //result = vec3(normal.x, normal.y, normal.z); - outColor = vec4(result, 1.0); + vec3 specular = specularStrength * spec * lightColor; + outColor = vec4((ambient + diffuse + specular) * objectColor, 1.0); } \ No newline at end of file diff --git a/src/App.cpp b/src/App.cpp index aa313359f6975642d65b8876beaf43edbf6c5175..085bcf37473a0f935c4272c80388f267f8d98797 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -181,7 +181,7 @@ void App::MoveCamera() } if (mouseScrollEvent) { - c.zoom(mouseScrollOffset.y * 0.2, normalizedmouse[0], normalizedmouse[1]); + c.zoom(mouseScrollOffset.y * 0.8, normalizedmouse[0], normalizedmouse[1]); mouseScrollEvent = false; } } @@ -191,18 +191,19 @@ void App::MoveCamera() void App::Render() { - // std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); GetInput(); MoveCamera(); v->SetCameraTransform(c.transform()); v->Render(); RenderUI(v->GetTexture()); - // std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); - // std::this_thread::sleep_for(std::chrono::microseconds(17 * 1000) - std::chrono::microseconds(std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count())); glfwSwapBuffers(window); glfwPollEvents(); if (/*glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS || */ glfwWindowShouldClose(window)) ShouldClose = true; + std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); + frametime = std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count(); + std::this_thread::sleep_for(std::chrono::microseconds(17 * 1000) - std::chrono::microseconds(std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count())); } void App::RenderUI(unsigned int FBOtexture) @@ -215,7 +216,7 @@ void App::RenderUI(unsigned int FBOtexture) ImGui::NewFrame(); ImGui::DockSpaceOverViewport(); - //ImGui::ShowDemoWindow(); + // ImGui::ShowDemoWindow(); { static int counter = 0; @@ -243,7 +244,7 @@ void App::RenderUI(unsigned int FBOtexture) v->SetLightPos(lightPos); ImGui::Text("Ctrl + click on the sliders for text input"); - ImGui::Text("Grid unit: %fmm", scale); + ImGui::Text("Grid unit: %.2fmm", scale); ImGui::SliderFloat("Scale", &scale, 0.0f, 10.0f); ImGui::SliderFloat("Model x", &x, -10.0f, 10.0f); ImGui::SliderFloat("Model y", &y, -10.0f, 10.0f); @@ -259,21 +260,15 @@ void App::RenderUI(unsigned int FBOtexture) if (ImGui::Button("Toggle wireframe mode")) v->ToggleWireframe(); } - - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::Text("Application average %.3f ms/frame", frametime / 1000.0f); ImGui::End(); } { ImGui::Begin("Viewport"); mouseIsOverViewport = ImGui::IsWindowHovered(); - v->SetSize(ImGui::GetWindowSize()); v->SetPos(ImGui::GetWindowPos()); - v->SetSize({v->GetSize().x - 16, v->GetSize().y - (ImGui::GetFontSize() + 22)}); - /* - 22 = 3 * 2 Title bar FramePadding (+ font size to get title bar height) https://github.com/ocornut/imgui/issues/1539 - + 8 * 2 Top and bottom internal window padding - */ + v->SetSize(ImGui::GetContentRegionAvail()); ImGui::GetWindowDrawList()->AddImage( (void *)(intptr_t)FBOtexture, ImVec2(ImGui::GetCursorScreenPos()),