Skip to content
Snippets Groups Projects
Commit 9cf4035b authored by Dave's avatar Dave :bicyclist:
Browse files

Minor modifications

parent d3d4339e
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,8 @@ private: ...@@ -44,6 +44,8 @@ private:
Viewport *v; Viewport *v;
float frametime;
bool ShouldClose; bool ShouldClose;
public: public:
......
...@@ -10,10 +10,10 @@ in vec3 pos; ...@@ -10,10 +10,10 @@ in vec3 pos;
void main(){ void main(){
vec3 lightColor = vec3(1.0, 1.0, 1.0); vec3 lightColor = vec3(1.0, 1.0, 1.0);
vec3 objectColor = vec3(0.9); vec3 objectColor = vec3(1.0);
// ambient // ambient
float ambientStrength = 0.2; float ambientStrength = 0.1;
vec3 ambient = ambientStrength * lightColor; vec3 ambient = ambientStrength * lightColor;
// diffuse // diffuse
...@@ -23,13 +23,10 @@ void main(){ ...@@ -23,13 +23,10 @@ void main(){
vec3 diffuse = diff * lightColor; vec3 diffuse = diff * lightColor;
// specular // specular
float specularStrength = 0.7; float specularStrength = 0.5;
vec3 viewDir = normalize(cameraPos - pos); 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); float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
vec3 specular = specularStrength * spec * lightColor; vec3 specular = specularStrength * spec * lightColor;
outColor = vec4((ambient + diffuse + specular) * objectColor, 1.0);
vec3 result = diffuse * objectColor;
//result = vec3(normal.x, normal.y, normal.z);
outColor = vec4(result, 1.0);
} }
\ No newline at end of file
...@@ -181,7 +181,7 @@ void App::MoveCamera() ...@@ -181,7 +181,7 @@ void App::MoveCamera()
} }
if (mouseScrollEvent) if (mouseScrollEvent)
{ {
c.zoom(mouseScrollOffset.y * 0.2, normalizedmouse[0], normalizedmouse[1]); c.zoom(mouseScrollOffset.y * 0.8, normalizedmouse[0], normalizedmouse[1]);
mouseScrollEvent = false; mouseScrollEvent = false;
} }
} }
...@@ -191,18 +191,19 @@ void App::MoveCamera() ...@@ -191,18 +191,19 @@ void App::MoveCamera()
void App::Render() 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(); GetInput();
MoveCamera(); MoveCamera();
v->SetCameraTransform(c.transform()); v->SetCameraTransform(c.transform());
v->Render(); v->Render();
RenderUI(v->GetTexture()); 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); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();
if (/*glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS || */ glfwWindowShouldClose(window)) if (/*glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS || */ glfwWindowShouldClose(window))
ShouldClose = true; 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) void App::RenderUI(unsigned int FBOtexture)
...@@ -215,7 +216,7 @@ void App::RenderUI(unsigned int FBOtexture) ...@@ -215,7 +216,7 @@ void App::RenderUI(unsigned int FBOtexture)
ImGui::NewFrame(); ImGui::NewFrame();
ImGui::DockSpaceOverViewport(); ImGui::DockSpaceOverViewport();
//ImGui::ShowDemoWindow(); // ImGui::ShowDemoWindow();
{ {
static int counter = 0; static int counter = 0;
...@@ -243,7 +244,7 @@ void App::RenderUI(unsigned int FBOtexture) ...@@ -243,7 +244,7 @@ void App::RenderUI(unsigned int FBOtexture)
v->SetLightPos(lightPos); v->SetLightPos(lightPos);
ImGui::Text("Ctrl + click on the sliders for text input"); 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("Scale", &scale, 0.0f, 10.0f);
ImGui::SliderFloat("Model x", &x, -10.0f, 10.0f); ImGui::SliderFloat("Model x", &x, -10.0f, 10.0f);
ImGui::SliderFloat("Model y", &y, -10.0f, 10.0f); ImGui::SliderFloat("Model y", &y, -10.0f, 10.0f);
...@@ -259,21 +260,15 @@ void App::RenderUI(unsigned int FBOtexture) ...@@ -259,21 +260,15 @@ void App::RenderUI(unsigned int FBOtexture)
if (ImGui::Button("Toggle wireframe mode")) if (ImGui::Button("Toggle wireframe mode"))
v->ToggleWireframe(); v->ToggleWireframe();
} }
ImGui::Text("Application average %.3f ms/frame", frametime / 1000.0f);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End(); ImGui::End();
} }
{ {
ImGui::Begin("Viewport"); ImGui::Begin("Viewport");
mouseIsOverViewport = ImGui::IsWindowHovered(); mouseIsOverViewport = ImGui::IsWindowHovered();
v->SetSize(ImGui::GetWindowSize());
v->SetPos(ImGui::GetWindowPos()); v->SetPos(ImGui::GetWindowPos());
v->SetSize({v->GetSize().x - 16, v->GetSize().y - (ImGui::GetFontSize() + 22)}); v->SetSize(ImGui::GetContentRegionAvail());
/*
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
*/
ImGui::GetWindowDrawList()->AddImage( ImGui::GetWindowDrawList()->AddImage(
(void *)(intptr_t)FBOtexture, (void *)(intptr_t)FBOtexture,
ImVec2(ImGui::GetCursorScreenPos()), ImVec2(ImGui::GetCursorScreenPos()),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment