diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 7bece5e2..bbb1db06 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -19,11 +19,12 @@ #include #include "src/UI/UserInterface.h" #include "src/NewEditor.h" +#include void OpenProject() { // Parse the project and load it. - std::string projectPath = Nuake::FileDialog::OpenFile(".project"); + std::string projectPath = Nuake::FileDialog::OpenFile("Project file|*.project;"); Nuake::FileSystem::SetRootDirectory(projectPath + "/../"); Ref project = Nuake::Project::New(); @@ -55,9 +56,11 @@ int main() Ref lightTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Light.png"); Ref camTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Camera.png"); Ref GuizmoShader = Nuake::ShaderManager::GetShader("resources/Shaders/gizmo.shader"); + Ref ditherShader = Nuake::ShaderManager::GetShader("resources/Shaders/dither.shader"); - Nuake::NewEditor newEditor = Nuake::NewEditor(); + //Nuake::NewEditor newEditor = Nuake::NewEditor(); + // Register shaders while (!Nuake::Engine::GetCurrentWindow()->ShouldClose()) { Nuake::RenderCommand::Clear(); @@ -115,8 +118,23 @@ int main() } glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); + GuizmoShader->Unbind(); + + ditherShader->Bind(); + ditherShader->SetUniformMat4f("u_View", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetTransform()); + ditherShader->SetUniformMat4f("u_Projection", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetPerspective()); + ditherShader->SetUniform1f("u_Time", Nuake::Engine::GetTime()); + ditherShader->SetUniform4f("u_Color", 252.0 / 255.0, 3.0 / 255.0, 65.0 / 255.0, 1.0); + + if (editor.m_IsEntitySelected && editor.m_SelectedEntity.HasComponent()) + { + for (auto& m : editor.m_SelectedEntity.GetComponent().Meshes) + Nuake::Renderer::SubmitMesh(m, editor.m_SelectedEntity.GetComponent().GetTransform()); + + Nuake::Renderer::Flush(ditherShader, true); + } + glEnable(GL_DEPTH_TEST); } sceneFramebuffer->Unbind(); diff --git a/Editor/resources/Shaders/dither.shader b/Editor/resources/Shaders/dither.shader new file mode 100644 index 00000000..689e7055 --- /dev/null +++ b/Editor/resources/Shaders/dither.shader @@ -0,0 +1,32 @@ +#shader vertex +#version 460 core + + +layout(location = 0) in vec3 VertexPosition; + +uniform mat4 u_Projection; +uniform mat4 u_View; +uniform mat4 u_Model; + +void main() +{ + gl_Position = u_Projection * u_View * u_Model * vec4(VertexPosition, 1.0f); +} + +#shader fragment +#version 460 core + +uniform vec4 u_Color; +uniform float u_Time; +out vec4 FragColor; + +void main() +{ + if (mod(gl_FragCoord.x + gl_FragCoord.y, 4.0) < 2.0) + discard; + + vec4 finalColor = u_Color; + finalColor.a = (sin(u_Time * 4.0) + 1.0) / 4.0 + 0.1; + FragColor = finalColor; + +} \ No newline at end of file diff --git a/Editor/resources/Shaders/flat.shader b/Editor/resources/Shaders/flat.shader index 9c28bf52..1b580760 100644 --- a/Editor/resources/Shaders/flat.shader +++ b/Editor/resources/Shaders/flat.shader @@ -7,6 +7,7 @@ layout(location = 0) in vec3 VertexPosition; uniform mat4 u_Projection; uniform mat4 u_View; uniform mat4 u_Model; + void main() { gl_Position = u_Projection * u_View * u_Model * vec4(VertexPosition, 1.0f); @@ -16,9 +17,13 @@ void main() #version 460 core uniform vec4 u_Color; + out vec4 FragColor; void main() { + if(mod(gl_FragCoord.x / 4.0 + gl_FragCoord.y / 4.0, 4.0) < 2.0) + discard; + FragColor = u_Color; } \ No newline at end of file diff --git a/Editor/resources/Shaders/pbr.shader b/Editor/resources/Shaders/pbr.shader index b32724dd..422fd570 100644 --- a/Editor/resources/Shaders/pbr.shader +++ b/Editor/resources/Shaders/pbr.shader @@ -213,7 +213,7 @@ float ShadowCalculation(Light light, vec3 FragPos, vec3 normal) int shadowmap = -1; // Get CSM depth - for (int i = 0; i < 2; i++) + for (int i = 0; i < 4; i++) { float CSMDepth = light.CascadeDepth[i] ; diff --git a/Editor/src/EditorInterface.cpp b/Editor/src/EditorInterface.cpp index 207520b9..c0ac864f 100644 --- a/Editor/src/EditorInterface.cpp +++ b/Editor/src/EditorInterface.cpp @@ -31,6 +31,8 @@ #include "UIComponents/Viewport.h" #include #include +#include +#include "src/Rendering/Renderer.h" namespace Nuake { Ref userInterface; @@ -224,7 +226,6 @@ namespace Nuake { if (ImGui::Selectable("Remove")) { QueueDeletion = e; - open = false; } if (ImGui::Selectable("Move to root")) @@ -359,7 +360,7 @@ namespace Nuake { m_SelectedEntity = scene->GetAllEntities().at(0); QueueDeletion = Entity{ (entt::entity)0, scene.get() }; - ImGui::TreePop(); + //ImGui::TreePop(); } } @@ -453,7 +454,8 @@ namespace Nuake { ImGui::Separator(); } - if (m_SelectedEntity.HasComponent()) { + if (m_SelectedEntity.HasComponent()) + { std::string icon = ICON_FA_MALE; if (ImGui::CollapsingHeader((icon + " " + "Mesh").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) { @@ -623,6 +625,7 @@ namespace Nuake { } if (m_SelectedEntity.HasComponent()) { + std::string icon = ICON_FA_BROOM; if (ImGui::CollapsingHeader((icon + " " + "Quake map").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) { @@ -1110,7 +1113,7 @@ namespace Nuake { void OpenProject() { // Parse the project and load it. - std::string projectPath = FileDialog::OpenFile(".project"); + std::string projectPath = FileDialog::OpenFile("Project file\0*.project"); FileSystem::SetRootDirectory(projectPath + "/../"); Ref project = Project::New(); @@ -1124,12 +1127,6 @@ namespace Nuake { Engine::LoadProject(project); pInterface.m_CurrentProject = project; - // Create new interface named test. - //userInterface = UI::UserInterface::New("test"); - - - // Set current interface running. - //Engine::GetCurrentScene()->AddInterface(userInterface); } void OpenScene() @@ -1138,7 +1135,8 @@ namespace Nuake { std::string projectPath = FileDialog::OpenFile(".scene"); Ref scene = Scene::New(); - if (!scene->Deserialize(FileSystem::ReadFile(projectPath, true))) { + if (!scene->Deserialize(FileSystem::ReadFile(projectPath, true))) + { Logger::Log("Error failed loading scene: " + projectPath, CRITICAL); return; } @@ -1159,15 +1157,16 @@ namespace Nuake { if (ImGui::BeginPopupModal("Welcome", NULL, flags)) { - ImGui::Text("Welcome to"); - ImGui::Text("Nuake engine"); + ImGui::Text("Welcome to Nuake Engine"); + ImGui::Text("Developement build"); - ImGui::Text("Would you like to"); - if (ImGui::Button("Start a new project")) + ImGui::Text("This project is still very early in developement and is not stable!"); + if (ImGui::Button("New Project")) NewProject(); ImGui::SameLine(); - if (ImGui::Button("Open a project")) { + if (ImGui::Button("Open Project")) + { OpenProject(); filesystem.m_CurrentDirectory = FileSystem::RootDirectory; } @@ -1175,10 +1174,10 @@ namespace Nuake { ImGui::EndPopup(); } + if (!Engine::GetProject()) { ImGui::OpenPopup("Welcome"); - return; } diff --git a/Editor/src/EditorInterface.h b/Editor/src/EditorInterface.h index ab9a48bd..722bf00d 100644 --- a/Editor/src/EditorInterface.h +++ b/Editor/src/EditorInterface.h @@ -13,8 +13,8 @@ namespace Nuake { { private: FileSystemUI filesystem = FileSystemUI(); - Entity m_SelectedEntity; - bool m_IsEntitySelected = false; + + bool m_DrawGrid = false; bool m_ShowImGuiDemo = false; bool m_DebugCollisions = false; @@ -27,6 +27,8 @@ namespace Nuake { bool m_IsMaterialSelected = false; public: + bool m_IsEntitySelected = false; + Entity m_SelectedEntity; static ImFont* bigIconFont; void BuildFonts(); void Init(); diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index c88ba895..c8d3604c 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -20,6 +20,8 @@ namespace Nuake float Engine::m_LastFrameTime = 0.0f; float Engine::m_FixedUpdateRate = 1.0 / 144.0f; float Engine::m_FixedUpdateDifference = 0.f; + float Engine::m_Time = 0.f; + bool Engine::IsPlayMode = false; void Engine::Init() @@ -41,9 +43,9 @@ namespace Nuake void Engine::Tick() { - float time = (float)glfwGetTime(); - Timestep timestep = time - m_LastFrameTime; - m_LastFrameTime = time; + m_Time = (float)glfwGetTime(); + Timestep timestep = m_Time - m_LastFrameTime; + m_LastFrameTime = m_Time; // Dont update if no scene is loaded. if (CurrentWindow->GetScene()) @@ -85,7 +87,8 @@ namespace Nuake void Engine::ExitPlayMode() { // Dont trigger exit if already not in play mode. - if (IsPlayMode) { + if (IsPlayMode) + { GetCurrentScene()->OnExit(); Input::ShowMouse(); } diff --git a/Nuake/Engine.h b/Nuake/Engine.h index a4710c06..6f635179 100644 --- a/Nuake/Engine.h +++ b/Nuake/Engine.h @@ -25,6 +25,7 @@ namespace Nuake static float m_LastFrameTime; static float m_FixedUpdateRate; static float m_FixedUpdateDifference; + static float m_Time; public: static bool IsPlayMode; // Is currently in runtime.. @@ -38,7 +39,7 @@ namespace Nuake // Custom drawing should happen in between these two static void Draw(); // Start new frame static void EndDraw(); // Swap buffer - + static inline float GetTime() { return m_Time; } static Ref GetCurrentWindow(); static bool LoadScene(Ref scene); diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 64ca4c60..fd771dfe 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -260,7 +260,6 @@ namespace Nuake { env->Push(); glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT); glEnable(GL_DEPTH_TEST); // Register the lights @@ -421,10 +420,7 @@ namespace Nuake { for (auto& b : model.Meshes) { - AABB aabb = b->GetAABB(); - aabb.Transform(transform.GetTransform()); - if (m_EditorCamera->BoxFrustumCheck(aabb)) - Renderer::SubmitMesh(b, transform.GetTransform()); + Renderer::SubmitMesh(b, transform.GetTransform()); } } diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 1a626936..492e819e 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -93,10 +93,12 @@ namespace Nuake PhysicsManager::Get()->Step(ts); auto brushes = m_Scene->m_Registry.view(); - for (auto e : brushes) { + for (auto e : brushes) + { auto [transform, brush] = brushes.get(e); - for (auto& r : brush.Rigidbody) { + for (auto& r : brush.Rigidbody) + { r->m_Transform->setOrigin(btVector3(transform.GlobalTranslation.x, transform.GlobalTranslation.y, transform.GlobalTranslation.z)); r->UpdateTransform(*r->m_Transform); } diff --git a/Nuake/src/Scene/Systems/TransformSystem.cpp b/Nuake/src/Scene/Systems/TransformSystem.cpp index 11ab3049..83dcd6f8 100644 --- a/Nuake/src/Scene/Systems/TransformSystem.cpp +++ b/Nuake/src/Scene/Systems/TransformSystem.cpp @@ -54,7 +54,7 @@ namespace Nuake { Vector3 globalScale = Vector3(); if (parent.HasParent) { - ParentComponent& parentComponent = currentParent.GetComponent(); + ParentComponent parentComponent = currentParent.GetComponent(); while (parentComponent.HasParent) { TransformComponent& transformComponent = parentComponent.Parent.GetComponent(); @@ -68,6 +68,7 @@ namespace Nuake { transform.GlobalTranslation = globalPosition + transform.Translation; transform.GlobalRotation = globalRotation + transform.Rotation; transform.GlobalScale = globalScale * transform.Scale; + } else {