From 2620fa548e9972d80d98afa22724746ebf421f0d Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Sun, 8 Oct 2023 13:26:41 -0400 Subject: [PATCH] Editor improvements, better cam, better gizmos, better lines --- Editor/src/Misc/GizmoDrawer.cpp | 18 ++++- Editor/src/Misc/GizmoDrawer.h | 2 +- Editor/src/Windows/EditorInterface.cpp | 11 ++- Nuake/src/Rendering/SceneRenderer.cpp | 12 +-- Nuake/src/Resource/StaticResources.cpp | 100 ++++++++++++++++--------- Nuake/src/Scene/EditorCamera.cpp | 67 +++++++++-------- Resources/Shaders/gizmo.shader | 15 +++- Resources/Shaders/line.shader | 4 +- 8 files changed, 142 insertions(+), 87 deletions(-) diff --git a/Editor/src/Misc/GizmoDrawer.cpp b/Editor/src/Misc/GizmoDrawer.cpp index 91a89673..a96bfbcb 100644 --- a/Editor/src/Misc/GizmoDrawer.cpp +++ b/Editor/src/Misc/GizmoDrawer.cpp @@ -1,4 +1,6 @@ #include "GizmoDrawer.h" + +#include #include #include @@ -21,6 +23,7 @@ #include #include + GizmoDrawer::GizmoDrawer() { mLineShader = Nuake::ShaderManager::GetShader("Resources/Shaders/line.shader"); @@ -128,17 +131,19 @@ void GizmoDrawer::GenerateSphereGizmo() mCircleBuffer->AddBuffer(*mCircleVertexBuffer, *vblayout); } -void GizmoDrawer::DrawGizmos(Ref scene) +void GizmoDrawer::DrawGizmos(Ref scene, bool occluded) { using namespace Nuake; //RenderCommand::Disable(RendererEnum::DEPTH_TEST); - //RenderCommand::Enable(RendererEnum::DEPTH_TEST); + RenderCommand::Enable(RendererEnum::DEPTH_TEST); // Draw Axis lignes. + //glDepthFunc(GL_ALWAYS); // Disable built-in depth testing + //glDepthMask(false); // Disable writing to the depth buffer { mLineShader->Bind(); mLineShader->SetUniformMat4f("u_View", scene->m_EditorCamera->GetTransform()); mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective()); - + mLineShader->SetUniform1f("u_Opacity", occluded ? 0.1f : 0.5f); mAxisLineBuffer->Bind(); Nuake::RenderCommand::DrawLines(0, 6); } @@ -304,7 +309,7 @@ void GizmoDrawer::DrawGizmos(Ref scene) gizmoShader->Bind(); gizmoShader->SetUniformMat4f("u_View", scene->m_EditorCamera->GetTransform()); gizmoShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective()); - + gizmoShader->SetUniform1f("u_Opacity", occluded ? 0.1f : 0.5f); RenderCommand::Disable(RendererEnum::FACE_CULL); // Camera @@ -413,5 +418,10 @@ void GizmoDrawer::DrawGizmos(Ref scene) renderList.Flush(gizmoShader, true); + // Revert to default depth testing + //glDepthFunc(GL_LESS); + // + //// Revert to default depth buffer writing + //glDepthMask(true); RenderCommand::Enable(RendererEnum::DEPTH_TEST); } \ No newline at end of file diff --git a/Editor/src/Misc/GizmoDrawer.h b/Editor/src/Misc/GizmoDrawer.h index e16faafa..46852211 100644 --- a/Editor/src/Misc/GizmoDrawer.h +++ b/Editor/src/Misc/GizmoDrawer.h @@ -48,5 +48,5 @@ public: GizmoDrawer(); ~GizmoDrawer() = default; - void DrawGizmos(Ref scene); + void DrawGizmos(Ref scene, bool occluded); }; \ No newline at end of file diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 8cca8793..07da7d7f 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -54,6 +54,7 @@ #include namespace Nuake { + Ref userInterface; ImFont* normalFont; ImFont* boldFont; @@ -1796,7 +1797,7 @@ namespace Nuake { Logger::Log("Failed creating project directory: " + dirPath); } - finalPath += "\\" + fileName; + finalPath += "/" + fileName; Ref project = Project::New(String::Split(fileName, '.')[0], "no description", finalPath); Engine::LoadProject(project); @@ -2105,13 +2106,11 @@ namespace Nuake { auto& editorCam = Engine::GetCurrentScene()->m_EditorCamera; - if (m_IsViewportFocused) - { - editorCam->Update(ts, m_IsHoveringViewport); - } + editorCam->Update(ts, m_IsHoveringViewport); const bool entityIsSelected = Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid(); - if (entityIsSelected && Input::IsKeyPressed(GLFW_KEY_F)) + + if (editorCam->IsFlying() && entityIsSelected && Input::IsKeyPressed(GLFW_KEY_F)) { editorCam->IsMoving = true; editorCam->TargetPos = Selection.Entity.GetComponent().GetGlobalPosition(); diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 490610da..d64ed3d7 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -97,7 +97,8 @@ namespace Nuake if (lc.Type == Directional && lc.IsVolumetric && lc.CastShadows) lightList.push_back(lc); } - + + glDepthMask(false); if (sceneEnv->VolumetricEnabled) { sceneEnv->mVolumetric->Resize(framebuffer.GetSize()); @@ -107,6 +108,7 @@ namespace Nuake //finalOutput = mVolumetric->GetFinalOutput().get(); // combine + framebuffer.Bind(); { RenderCommand::Clear(); @@ -118,6 +120,7 @@ namespace Nuake Renderer::DrawQuad(); } framebuffer.Unbind(); + } else { @@ -284,6 +287,7 @@ namespace Nuake framebuffer.Unbind(); } + glDepthMask(true); // Barrel distortion //mVignetteBuffer->Bind(); @@ -311,7 +315,7 @@ namespace Nuake Shader* shader = ShaderManager::GetShader("Resources/Shaders/shadowMap.shader"); shader->Bind(); - RenderCommand::Disable(RendererEnum::FACE_CULL); + RenderCommand::Enable(RendererEnum::FACE_CULL); glCullFace(GL_BACK); auto meshView = scene.m_Registry.view(); @@ -456,7 +460,6 @@ namespace Nuake gBufferShader->SetUniformMat4f("u_View", mView); // Models - glDisable(GL_CULL_FACE); auto view = scene.m_Registry.view(); for (auto e : view) { @@ -486,10 +489,9 @@ namespace Nuake Renderer::SubmitMesh(b, transform.GetGlobalTransform(), (uint32_t)e); } } + glCullFace(GL_FRONT); Renderer::Flush(gBufferShader, false); - RenderCommand::Disable(RendererEnum::FACE_CULL); - // Sprites auto spriteView = scene.m_Registry.view(); for (auto& e : spriteView) diff --git a/Nuake/src/Resource/StaticResources.cpp b/Nuake/src/Resource/StaticResources.cpp index c8a3279b..944a424c 100644 --- a/Nuake/src/Resource/StaticResources.cpp +++ b/Nuake/src/Resource/StaticResources.cpp @@ -185905,39 +185905,62 @@ const std::string Resources_Shaders_gizmo_shader_path = R"(Resources/Shaders/giz 0x0d, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x6f, 0x75, 0x74, 0x20, + 0x6d, 0x61, 0x74, 0x34, 0x20, 0x6f, 0x5f, 0x50, 0x72, 0x6f, 0x6a, 0x65, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0d, 0x0a, 0x6f, 0x75, 0x74, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, - 0x61, 0x5f, 0x55, 0x56, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x76, 0x6f, 0x69, - 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x0d, 0x0a, 0x7b, 0x0d, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x61, 0x5f, 0x55, 0x56, 0x20, 0x3d, 0x20, - 0x55, 0x56, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x67, 0x6c, 0x5f, - 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x75, - 0x5f, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, - 0x2a, 0x20, 0x75, 0x5f, 0x56, 0x69, 0x65, 0x77, 0x20, 0x2a, 0x20, 0x75, - 0x5f, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x20, 0x2a, 0x20, 0x76, 0x65, 0x63, - 0x34, 0x28, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, - 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0d, 0x0a, 0x7d, 0x0d, 0x0a, 0x0d, 0x0a, - 0x23, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x66, 0x72, 0x61, 0x67, - 0x6d, 0x65, 0x6e, 0x74, 0x0d, 0x0a, 0x23, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x20, 0x34, 0x34, 0x30, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x0d, - 0x0a, 0x0d, 0x0a, 0x6f, 0x75, 0x74, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, - 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0d, 0x0a, - 0x0d, 0x0a, 0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, 0x5f, - 0x55, 0x56, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, - 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, - 0x20, 0x67, 0x69, 0x7a, 0x6d, 0x6f, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, - 0x72, 0x65, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, - 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x20, 0x0d, 0x0a, 0x7b, 0x0d, 0x0a, - 0x20, 0x20, 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x70, 0x78, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, - 0x75, 0x72, 0x65, 0x28, 0x67, 0x69, 0x7a, 0x6d, 0x6f, 0x5f, 0x74, 0x65, - 0x78, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x61, 0x5f, 0x55, 0x56, 0x29, - 0x2e, 0x72, 0x67, 0x62, 0x61, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, - 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, - 0x70, 0x78, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x2a, 0x20, 0x76, - 0x65, 0x63, 0x34, 0x28, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x2c, - 0x20, 0x30, 0x2e, 0x35, 0x29, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x7d + 0x61, 0x5f, 0x55, 0x56, 0x3b, 0x0d, 0x0a, 0x6f, 0x75, 0x74, 0x20, 0x76, + 0x65, 0x63, 0x34, 0x20, 0x6f, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x50, 0x6f, + 0x73, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, + 0x61, 0x69, 0x6e, 0x28, 0x29, 0x0d, 0x0a, 0x7b, 0x0d, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x61, 0x5f, 0x55, 0x56, 0x20, 0x3d, 0x20, 0x55, 0x56, 0x3b, + 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x5f, 0x50, 0x72, 0x6f, 0x6a, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x75, 0x5f, 0x50, + 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0d, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x75, 0x5f, 0x50, 0x72, 0x6f, 0x6a, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x56, + 0x69, 0x65, 0x77, 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x4d, 0x6f, 0x64, 0x65, + 0x6c, 0x20, 0x2a, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x50, 0x6f, 0x73, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, + 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x5f, 0x46, 0x72, 0x61, 0x67, + 0x50, 0x6f, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0d, 0x0a, 0x7d, 0x0d, 0x0a, 0x0d, + 0x0a, 0x23, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x66, 0x72, 0x61, + 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x0d, 0x0a, 0x23, 0x76, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x20, 0x34, 0x34, 0x30, 0x20, 0x63, 0x6f, 0x72, 0x65, + 0x0d, 0x0a, 0x0d, 0x0a, 0x6f, 0x75, 0x74, 0x20, 0x76, 0x65, 0x63, 0x34, + 0x20, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0d, + 0x0a, 0x0d, 0x0a, 0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, + 0x5f, 0x55, 0x56, 0x3b, 0x0d, 0x0a, 0x69, 0x6e, 0x20, 0x6d, 0x61, 0x74, + 0x34, 0x20, 0x6f, 0x5f, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x3b, 0x0d, 0x0a, 0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x34, + 0x20, 0x6f, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x50, 0x6f, 0x73, 0x3b, 0x0d, + 0x0a, 0x0d, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x75, 0x5f, 0x44, + 0x65, 0x70, 0x74, 0x68, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x3b, + 0x0d, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, + 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x67, 0x69, 0x7a, 0x6d, + 0x6f, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x3b, 0x0d, 0x0a, + 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x66, 0x6c, 0x6f, 0x61, + 0x74, 0x20, 0x75, 0x5f, 0x4f, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x3b, + 0x0d, 0x0a, 0x0d, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, + 0x6e, 0x28, 0x29, 0x20, 0x0d, 0x0a, 0x7b, 0x0d, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x20, + 0x3d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x30, 0x2c, 0x20, 0x30, 0x2c, + 0x20, 0x30, 0x2c, 0x20, 0x30, 0x29, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x70, 0x78, 0x5f, 0x63, + 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, + 0x72, 0x65, 0x28, 0x67, 0x69, 0x7a, 0x6d, 0x6f, 0x5f, 0x74, 0x65, 0x78, + 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x61, 0x5f, 0x55, 0x56, 0x29, 0x2e, + 0x72, 0x67, 0x62, 0x61, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, + 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x70, 0x78, 0x5f, 0x63, 0x6f, + 0x6c, 0x6f, 0x72, 0x20, 0x2a, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x31, + 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x75, 0x5f, 0x4f, 0x70, + 0x61, 0x63, 0x69, 0x74, 0x79, 0x29, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, + 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0d, 0x0a, 0x7d }; - unsigned int Resources_Shaders_gizmo_shader_len = 599; + unsigned int Resources_Shaders_gizmo_shader_len = 876; // Data for file: Resources_Shaders_line_shader_path const std::string Resources_Shaders_line_shader_path = R"(Resources/Shaders/line.shader)"; @@ -185978,12 +186001,17 @@ const std::string Resources_Shaders_line_shader_path = R"(Resources/Shaders/line 0x69, 0x6e, 0x65, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x6f, 0x75, 0x74, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, - 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x0d, - 0x0a, 0x7b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x46, 0x72, 0x61, 0x67, - 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x4c, 0x69, 0x6e, 0x65, - 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0d, 0x0a, 0x7d + 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x66, 0x6c, 0x6f, 0x61, + 0x74, 0x20, 0x75, 0x5f, 0x4f, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x3b, + 0x0d, 0x0a, 0x0d, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, + 0x6e, 0x28, 0x29, 0x0d, 0x0a, 0x7b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, + 0x4c, 0x69, 0x6e, 0x65, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x2a, 0x20, + 0x76, 0x65, 0x63, 0x34, 0x28, 0x31, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x31, + 0x2c, 0x20, 0x75, 0x5f, 0x4f, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x29, + 0x3b, 0x0d, 0x0a, 0x7d }; - unsigned int Resources_Shaders_line_shader_len = 477; + unsigned int Resources_Shaders_line_shader_len = 532; // Data for file: Resources_Shaders_pbr_shader_path const std::string Resources_Shaders_pbr_shader_path = R"(Resources/Shaders/pbr.shader)"; diff --git a/Nuake/src/Scene/EditorCamera.cpp b/Nuake/src/Scene/EditorCamera.cpp index 68235241..6aa7eaed 100644 --- a/Nuake/src/Scene/EditorCamera.cpp +++ b/Nuake/src/Scene/EditorCamera.cpp @@ -24,8 +24,8 @@ namespace Nuake const float x = Input::GetMouseX(); const float y = Input::GetMouseY(); - const bool isFlying = Input::IsMouseButtonDown(1) || Input::IsMouseButtonDown(2); - const bool isPressingMouse = isFlying || Input::YScroll != 0.0f; + m_IsFlying = Input::IsMouseButtonDown(1) || Input::IsMouseButtonDown(2); + const bool isPressingMouse = m_IsFlying || Input::YScroll != 0.0f; if (hover) { @@ -77,10 +77,9 @@ namespace Nuake { mouseLastX = x; mouseLastY = y; - return; } - if (Input::IsMouseButtonDown(1)) + if (hover && Input::IsMouseButtonDown(1)) { // Should probably not have speed binding in here. if (Input::YScroll != 0) @@ -92,6 +91,7 @@ namespace Nuake if (Speed < 0) Speed = 0; + if (m_Type == CAMERA_TYPE::ORTHO) { if (Input::IsKeyDown(GLFW_KEY_RIGHT)) @@ -144,45 +144,48 @@ namespace Nuake TargetYaw += diffx; TargetPitch += diffy; - if (TargetPitch > 89.0f) - TargetPitch = 89.0f; + } - if (TargetPitch < -89.0f) - TargetPitch = -89.0f; + if (TargetPitch > 89.0f) + TargetPitch = 89.0f; - Direction.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch)); - Direction.y = sin(glm::radians(Pitch)); - Direction.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch)); + if (TargetPitch < -89.0f) + TargetPitch = -89.0f; - SetDirection(glm::normalize(Direction)); - Right = glm::normalize(glm::cross(Up, Direction)); - } - else if (Input::IsMouseButtonDown(2)) + Direction.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch)); + Direction.y = sin(glm::radians(Pitch)); + Direction.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch)); + + SetDirection(glm::normalize(Direction)); + Right = glm::normalize(glm::cross(Up, Direction)); + + if (hover) { - Vector3 movement = Vector3(0); - const float deltaX = x - mouseLastX; - const float deltaY = y - mouseLastY; - movement += Right * (deltaX * ts); - movement += Up * (deltaY * ts); - Translation += Vector3(movement) * 0.5f; + if (Input::IsMouseButtonDown(2)) + { + Vector3 movement = Vector3(0); + const float deltaX = x - mouseLastX; + const float deltaY = y - mouseLastY; + movement += Right * (deltaX * ts); + movement += Up * (deltaY * ts); + Translation += Vector3(movement) * 0.5f; - mouseLastX = x; - mouseLastY = y; - controlled = true; + mouseLastX = x; + mouseLastY = y; + controlled = true; - SetDirection(glm::normalize(Direction)); - } - else if (Input::YScroll != 0) - { - Translation += Vector3(Direction) * Input::YScroll; - Input::YScroll = 0.0f; + SetDirection(glm::normalize(Direction)); + } + else if (Input::YScroll != 0) + { + Translation += Vector3(Direction) * Input::YScroll; + Input::YScroll = 0.0f; + } } SetDirection(glm::normalize(Direction)); mouseLastX = x; mouseLastY = y; - - } Ref EditorCamera::Copy() diff --git a/Resources/Shaders/gizmo.shader b/Resources/Shaders/gizmo.shader index 3b5ac2ee..d568d636 100644 --- a/Resources/Shaders/gizmo.shader +++ b/Resources/Shaders/gizmo.shader @@ -8,12 +8,16 @@ uniform mat4 u_Model; uniform mat4 u_View; uniform mat4 u_Projection; +out mat4 o_Projection; out sample vec2 a_UV; +out vec4 o_FragPos; void main() { a_UV = UV; + o_Projection = u_Projection; gl_Position = u_Projection * u_View * u_Model * vec4(Position, 1.0); + o_FragPos = gl_Position; } #shader fragment @@ -22,12 +26,19 @@ void main() out vec4 FragColor; in vec2 a_UV; +in mat4 o_Projection; +in vec4 o_FragPos; +uniform sampler2D u_DepthTexture; uniform sampler2D gizmo_texture; +uniform float u_Opacity; void main() { - vec4 px_color = texture(gizmo_texture, a_UV).rgba; - FragColor = px_color * vec4(1, 1, 1, 0.5); + vec4 color = vec4(0, 0, 0, 0); + vec4 px_color = texture(gizmo_texture, a_UV).rgba; + color = px_color * vec4(1, 1, 1, u_Opacity); + + FragColor = color; } \ No newline at end of file diff --git a/Resources/Shaders/line.shader b/Resources/Shaders/line.shader index 9b49db4e..c7eb90aa 100644 --- a/Resources/Shaders/line.shader +++ b/Resources/Shaders/line.shader @@ -23,7 +23,9 @@ in vec4 LineColor; out vec4 FragColor; +uniform float u_Opacity; + void main() { - FragColor = LineColor; + FragColor = LineColor * vec4(1, 1, 1, u_Opacity); } \ No newline at end of file