diff --git a/Editor/src/Actions/EditorSelection.h b/Editor/src/Actions/EditorSelection.h index d055dcf9..0cdfcf69 100644 --- a/Editor/src/Actions/EditorSelection.h +++ b/Editor/src/Actions/EditorSelection.h @@ -2,6 +2,8 @@ #include "src/Core/Core.h" #include "src/Scene/Entities/Entity.h" #include "src/Resource/Resource.h" +#include "Engine.h" +#include "src/Rendering/SceneRenderer.h" enum EditorSelectionType { None, @@ -24,29 +26,37 @@ public: EditorSelection() { Type = None; + if (const auto& scene = Nuake::Engine::GetCurrentScene(); scene) + { + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0; + } } EditorSelection(const Nuake::Entity& entity) { Type = EditorSelectionType::Entity; + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = (uint32_t)entity.GetHandle(); Entity = entity; } EditorSelection(const Ref& file) { Type = EditorSelectionType::File; + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0; File = file; } EditorSelection(const Ref& dir) { Type = EditorSelectionType::Directory; + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0; Directory = dir; } EditorSelection(const Nuake::Resource& resource) { Type = EditorSelectionType::Resource; + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0; Resource = resource; } diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 1f7d980a..15173aa6 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -287,6 +287,7 @@ namespace Nuake { else { Selection = EditorSelection(); // None + } gbuffer.Unbind(); diff --git a/Nuake/src/Core/Physics/DynamicWorld.cpp b/Nuake/src/Core/Physics/DynamicWorld.cpp index 4088d927..e43e71d7 100644 --- a/Nuake/src/Core/Physics/DynamicWorld.cpp +++ b/Nuake/src/Core/Physics/DynamicWorld.cpp @@ -252,10 +252,10 @@ namespace Nuake _registeredCharacters = std::map>(); // Initialize Jolt Physics - const uint32_t MaxBodies = 2048; + const uint32_t MaxBodies = 4096; const uint32_t NumBodyMutexes = 0; - const uint32_t MaxBodyPairs = 1024; - const uint32_t MaxContactConstraints = 1024; + const uint32_t MaxBodyPairs = 2048; + const uint32_t MaxContactConstraints = 2048; _JoltPhysicsSystem = CreateRef(); _JoltPhysicsSystem->Init(MaxBodies, NumBodyMutexes, MaxBodyPairs, MaxContactConstraints, JoltBroadphaseLayerInterface, JoltObjectVSBroadphaseLayerFilter, JoltObjectVSObjectLayerFilter); @@ -344,10 +344,18 @@ namespace Nuake Logger::Log("Entity with ID 0 detected. Name: " + rb->GetEntity().GetComponent().Name, "DEBUG"); } - bodySettings.mUserData = rb->GetEntity().GetID(); + int entityId = rb->GetEntity().GetID(); + + if (entityId == 0) + { + Logger::Log("ERROR"); + } + + bodySettings.mUserData = entityId; // Create the actual rigid body JPH::BodyID body = _JoltBodyInterface->CreateAndAddBody(bodySettings, JPH::EActivation::Activate); // Note that if we run out of bodies this can return nullptr - _registeredBodies.push_back((uint32_t)body.GetIndex()); + uint32_t bodyIndex = (uint32_t)body.GetIndex(); + _registeredBodies.push_back(bodyIndex); } void DynamicWorld::AddGhostbody(Ref gb) @@ -454,12 +462,15 @@ namespace Nuake glm::decompose(transform, scale, rotation, pos, skew, pesp); auto entId = static_cast(bodyInterface.GetUserData(bodyId)); - Entity entity = Engine::GetCurrentScene()->GetEntityByID(entId); - auto& transformComponent = entity.GetComponent(); - transformComponent.SetLocalPosition(pos); - transformComponent.SetLocalRotation(Quat(bodyRotation.GetW(), bodyRotation.GetX(), bodyRotation.GetY(), bodyRotation.GetZ())); - transformComponent.SetLocalTransform(transform); - transformComponent.Dirty = true; + if (entId != 0) + { + Entity entity = Engine::GetCurrentScene()->GetEntityByID(entId); + auto& transformComponent = entity.GetComponent(); + transformComponent.SetLocalPosition(pos); + transformComponent.SetLocalRotation(Quat(bodyRotation.GetW(), bodyRotation.GetX(), bodyRotation.GetY(), bodyRotation.GetZ())); + transformComponent.SetLocalTransform(transform); + transformComponent.Dirty = true; + } } } diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 32d4af88..6110046e 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -37,6 +37,9 @@ namespace Nuake mDOFBuffer = CreateScope(false, defaultResolution); mDOFBuffer->SetTexture(CreateRef(defaultResolution, GL_RGB), GL_COLOR_ATTACHMENT0); + + mOutlineBuffer = CreateScope(false, defaultResolution); + mOutlineBuffer->SetTexture(CreateRef(defaultResolution, GL_RGB), GL_COLOR_ATTACHMENT0); } void SceneRenderer::Cleanup() @@ -287,6 +290,38 @@ namespace Nuake framebuffer.Unbind(); } + + { + mOutlineBuffer->QueueResize(framebuffer.GetSize()); + mOutlineBuffer->Bind(); + { + RenderCommand::Clear(); + Shader* shader = ShaderManager::GetShader("Resources/Shaders/outline.shader"); + shader->Bind(); + + shader->SetUniform1i("u_EntityID", mOutlineEntityID + 1); + shader->SetUniformTex("u_EntityTexture", mGBuffer->GetTexture(GL_COLOR_ATTACHMENT3).get(), 0); + shader->SetUniform4f("u_OutlineColor", 97.0f / 255.0f, 0, 1.0f, 1.0f); + Renderer::DrawQuad(); + } + mOutlineBuffer->Unbind(); + + + ImGui::Begin("outline"); + ImGui::Image((void*)mOutlineBuffer->GetTexture(GL_COLOR_ATTACHMENT0)->GetID(), ImGui::GetContentRegionAvail(), ImVec2(0, 1), ImVec2(1, 0)); + ImGui::End(); + framebuffer.Bind(); + { + RenderCommand::Clear(); + Shader* shader = ShaderManager::GetShader("Resources/Shaders/combine.shader"); + shader->Bind(); + + shader->SetUniformTex("u_Source", mVignetteBuffer->GetTexture().get(), 0); + shader->SetUniformTex("u_Source2", mOutlineBuffer->GetTexture(GL_COLOR_ATTACHMENT0).get(), 1); + Renderer::DrawQuad(); + } + framebuffer.Unbind(); + } glDepthMask(true); // Barrel distortion diff --git a/Nuake/src/Rendering/SceneRenderer.h b/Nuake/src/Rendering/SceneRenderer.h index ed6e1c6d..e7739e52 100644 --- a/Nuake/src/Rendering/SceneRenderer.h +++ b/Nuake/src/Rendering/SceneRenderer.h @@ -24,16 +24,19 @@ namespace Nuake return *mGBuffer; } + uint32_t mOutlineEntityID = 0; private: Matrix4 mProjection, mView; Vector3 mCamPos; + Scope mGBuffer; Scope mShadingBuffer; Scope mToneMapBuffer; Scope mBarrelDistortionBuffer; Scope mVignetteBuffer; Scope mDOFBuffer; + Scope mOutlineBuffer; void ShadowPass(Scene& scene); void GBufferPass(Scene& scene); diff --git a/Nuake/src/Rendering/Shaders/Shader.cpp b/Nuake/src/Rendering/Shaders/Shader.cpp index bc9a249b..8fe9d038 100644 --- a/Nuake/src/Rendering/Shaders/Shader.cpp +++ b/Nuake/src/Rendering/Shaders/Shader.cpp @@ -38,7 +38,7 @@ namespace Nuake bool Shader::Rebuild() { - if (!FileSystem::FileExists(Path)) + if (!FileSystem::FileExists(Path, true)) { Logger::Log("Failed to reload shader, file doesn't exists: " + Path, "shader", CRITICAL); return false; diff --git a/Nuake/src/Rendering/Shaders/ShaderManager.cpp b/Nuake/src/Rendering/Shaders/ShaderManager.cpp index df0545cc..25be053d 100644 --- a/Nuake/src/Rendering/Shaders/ShaderManager.cpp +++ b/Nuake/src/Rendering/Shaders/ShaderManager.cpp @@ -13,7 +13,7 @@ namespace Nuake void ShaderManager::LoadShaders() { using namespace StaticResources; - + LoadEmbeddedShader(Resources_Shaders_outline_shader); LoadEmbeddedShader(Resources_Shaders_atmospheric_sky_shader); LoadEmbeddedShader(Resources_Shaders_barrel_distortion_shader); LoadEmbeddedShader(Resources_Shaders_bloom_shader); diff --git a/Nuake/src/Resource/StaticResources.cpp b/Nuake/src/Resource/StaticResources.cpp index 176c8fe7..4f6b807b 100644 --- a/Nuake/src/Resource/StaticResources.cpp +++ b/Nuake/src/Resource/StaticResources.cpp @@ -232315,13 +232315,21 @@ const std::string Resources_Shaders_combine_shader_path = R"(Resources/Shaders/c 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x28, 0x75, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x32, 0x2c, 0x20, 0x55, 0x56, 0x29, 0x3b, 0x0d, 0x0a, 0x0d, - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, - 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x76, 0x65, - 0x63, 0x33, 0x28, 0x61, 0x2e, 0x72, 0x67, 0x62, 0x20, 0x2b, 0x20, 0x28, - 0x62, 0x2e, 0x72, 0x67, 0x62, 0x29, 0x20, 0x2f, 0x20, 0x32, 0x2e, 0x30, - 0x29, 0x2c, 0x20, 0x61, 0x2e, 0x61, 0x29, 0x3b, 0x0d, 0x0a, 0x7d + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x28, 0x62, 0x2e, 0x61, 0x20, + 0x3c, 0x20, 0x30, 0x2e, 0x31, 0x66, 0x29, 0x0d, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x7b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, + 0x61, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x0d, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0d, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x7b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, + 0x76, 0x65, 0x63, 0x34, 0x28, 0x76, 0x65, 0x63, 0x33, 0x28, 0x61, 0x2e, + 0x72, 0x67, 0x62, 0x20, 0x2b, 0x20, 0x28, 0x62, 0x2e, 0x72, 0x67, 0x62, + 0x29, 0x20, 0x2f, 0x20, 0x32, 0x2e, 0x30, 0x29, 0x2c, 0x20, 0x61, 0x2e, + 0x61, 0x29, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x0d, 0x0a, + 0x7d }; - unsigned int Resources_Shaders_combine_shader_len = 527; + unsigned int Resources_Shaders_combine_shader_len = 613; // Data for file: Resources_Shaders_copy_shader_path const std::string Resources_Shaders_copy_shader_path = R"(Resources/Shaders/copy.shader)"; @@ -235267,6 +235275,117 @@ const std::string Resources_Shaders_line_shader_path = R"(Resources/Shaders/line }; unsigned int Resources_Shaders_line_shader_len = 653; +// Data for file: Resources_Shaders_outline_shader_path +const std::string Resources_Shaders_outline_shader_path = R"(Resources/Shaders/outline.shader)"; + unsigned char Resources_Shaders_outline_shader[] = { + 0x23, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x76, 0x65, 0x72, 0x74, + 0x65, 0x78, 0x0d, 0x0a, 0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x20, 0x34, 0x34, 0x30, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x0d, 0x0a, 0x0d, + 0x0a, 0x6c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x28, 0x6c, 0x6f, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x30, 0x29, 0x20, 0x69, 0x6e, + 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, + 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0d, 0x0a, 0x6c, + 0x61, 0x79, 0x6f, 0x75, 0x74, 0x28, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x31, 0x29, 0x20, 0x69, 0x6e, 0x20, 0x76, + 0x65, 0x63, 0x32, 0x20, 0x55, 0x56, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x3b, 0x0d, 0x0a, 0x0d, 0x0a, 0x6f, 0x75, 0x74, 0x20, 0x66, + 0x6c, 0x61, 0x74, 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, 0x09, 0x61, + 0x5f, 0x55, 0x56, 0x20, 0x3d, 0x20, 0x55, 0x56, 0x50, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0d, 0x0a, 0x09, 0x67, 0x6c, 0x5f, 0x50, + 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x76, 0x65, + 0x63, 0x34, 0x28, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x50, 0x6f, 0x73, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x66, 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, 0x75, + 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x75, + 0x5f, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x49, 0x44, 0x3b, 0x0d, 0x0a, + 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x75, 0x73, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x75, 0x5f, 0x45, 0x6e, 0x74, + 0x69, 0x74, 0x79, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x3b, 0x0d, + 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, + 0x34, 0x20, 0x75, 0x5f, 0x4f, 0x75, 0x74, 0x6c, 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, 0x69, 0x6e, 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, 0x69, 0x6e, 0x74, + 0x20, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x75, 0x5f, + 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x49, 0x44, 0x3b, 0x0d, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x66, 0x6c, 0x6f, + 0x61, 0x74, 0x20, 0x54, 0x41, 0x55, 0x20, 0x3d, 0x20, 0x36, 0x2e, 0x32, + 0x38, 0x33, 0x31, 0x38, 0x35, 0x33, 0x30, 0x3b, 0x0d, 0x0a, 0x09, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x73, + 0x74, 0x65, 0x70, 0x73, 0x20, 0x3d, 0x20, 0x33, 0x32, 0x2e, 0x30, 0x3b, + 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x0d, 0x0a, 0x09, 0x66, 0x6c, 0x6f, + 0x61, 0x74, 0x20, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x20, 0x3d, 0x20, + 0x34, 0x2e, 0x66, 0x3b, 0x0d, 0x0a, 0x09, 0x76, 0x65, 0x63, 0x32, 0x20, + 0x75, 0x76, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x55, 0x56, 0x3b, 0x0d, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x2f, 0x2f, + 0x20, 0x43, 0x6f, 0x72, 0x72, 0x65, 0x63, 0x74, 0x20, 0x61, 0x73, 0x70, + 0x65, 0x63, 0x74, 0x20, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x0d, 0x0a, 0x20, + 0x20, 0x20, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, 0x73, 0x70, 0x65, + 0x63, 0x74, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x20, 0x2f, 0x20, 0x76, + 0x65, 0x63, 0x32, 0x28, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x53, + 0x69, 0x7a, 0x65, 0x28, 0x75, 0x5f, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, + 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x30, 0x29, 0x29, + 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x0d, 0x0a, 0x09, 0x76, 0x65, + 0x63, 0x34, 0x20, 0x66, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, + 0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x30, 0x2e, 0x30, 0x2c, + 0x20, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x30, + 0x2e, 0x30, 0x66, 0x29, 0x3b, 0x0d, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, + 0x28, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x30, + 0x2e, 0x30, 0x3b, 0x20, 0x69, 0x20, 0x3c, 0x20, 0x54, 0x41, 0x55, 0x3b, + 0x20, 0x69, 0x20, 0x2b, 0x3d, 0x20, 0x54, 0x41, 0x55, 0x20, 0x2f, 0x20, + 0x73, 0x74, 0x65, 0x70, 0x73, 0x29, 0x20, 0x0d, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x7b, 0x0d, 0x0a, 0x09, 0x09, 0x2f, 0x2f, 0x20, 0x53, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x20, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x20, 0x69, 0x6e, + 0x20, 0x61, 0x20, 0x63, 0x69, 0x72, 0x63, 0x75, 0x6c, 0x61, 0x72, 0x20, + 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x0d, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x6f, 0x66, + 0x66, 0x73, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, 0x32, 0x28, + 0x73, 0x69, 0x6e, 0x28, 0x69, 0x29, 0x2c, 0x20, 0x63, 0x6f, 0x73, 0x28, + 0x69, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x61, 0x73, 0x70, 0x65, 0x63, 0x74, + 0x20, 0x2a, 0x20, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x3b, 0x0d, 0x0a, + 0x09, 0x09, 0x75, 0x69, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6c, 0x20, 0x3d, + 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x28, 0x75, 0x5f, 0x45, + 0x6e, 0x74, 0x69, 0x74, 0x79, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, + 0x2c, 0x20, 0x75, 0x76, 0x20, 0x2b, 0x20, 0x6f, 0x66, 0x66, 0x73, 0x65, + 0x74, 0x29, 0x2e, 0x72, 0x3b, 0x0d, 0x0a, 0x09, 0x09, 0x0d, 0x0a, 0x09, + 0x09, 0x2f, 0x2f, 0x20, 0x4d, 0x69, 0x78, 0x20, 0x6f, 0x75, 0x74, 0x6c, + 0x69, 0x6e, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x62, 0x61, 0x63, + 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x0d, 0x0a, 0x09, 0x09, 0x66, + 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x20, 0x3d, + 0x20, 0x73, 0x6d, 0x6f, 0x6f, 0x74, 0x68, 0x73, 0x74, 0x65, 0x70, 0x28, + 0x30, 0x2e, 0x35, 0x2c, 0x20, 0x30, 0x2e, 0x37, 0x2c, 0x20, 0x69, 0x6e, + 0x74, 0x28, 0x63, 0x6f, 0x6c, 0x20, 0x21, 0x3d, 0x20, 0x74, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x29, 0x20, 0x2a, 0x20, 0x31, 0x30, 0x2e, 0x30, 0x66, + 0x29, 0x3b, 0x0d, 0x0a, 0x09, 0x09, 0x66, 0x72, 0x61, 0x67, 0x43, 0x6f, + 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x78, 0x28, 0x66, 0x72, + 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x75, 0x5f, 0x4f, + 0x75, 0x74, 0x6c, 0x69, 0x6e, 0x65, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, + 0x20, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x29, 0x3b, 0x0d, 0x0a, 0x09, 0x7d, + 0x0d, 0x0a, 0x09, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x28, + 0x66, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2e, 0x61, 0x20, + 0x3e, 0x20, 0x30, 0x2e, 0x31, 0x29, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x7b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, + 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2e, 0x61, 0x20, 0x3d, + 0x20, 0x31, 0x2e, 0x30, 0x66, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x7d, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x0d, 0x0a, 0x20, 0x20, 0x20, + 0x20, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, + 0x20, 0x6d, 0x69, 0x78, 0x28, 0x76, 0x65, 0x63, 0x34, 0x28, 0x30, 0x29, + 0x2c, 0x20, 0x66, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, + 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x28, 0x75, 0x5f, 0x45, + 0x6e, 0x74, 0x69, 0x74, 0x79, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, + 0x2c, 0x20, 0x75, 0x76, 0x29, 0x2e, 0x72, 0x20, 0x3d, 0x3d, 0x20, 0x74, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x29, 0x3b, 0x0d, 0x0a, 0x7d, 0x0d, 0x0a + }; + unsigned int Resources_Shaders_outline_shader_len = 1260; + // Data for file: Resources_Shaders_pbr_shader_path const std::string Resources_Shaders_pbr_shader_path = R"(Resources/Shaders/pbr.shader)"; unsigned char Resources_Shaders_pbr_shader[] = { diff --git a/Nuake/src/Resource/StaticResources.h b/Nuake/src/Resource/StaticResources.h index 264b5eb8..a4596ae1 100644 --- a/Nuake/src/Resource/StaticResources.h +++ b/Nuake/src/Resource/StaticResources.h @@ -129,6 +129,9 @@ extern unsigned char Resources_Shaders_gizmo_shader[]; extern const std::string Resources_Shaders_line_shader_path; extern unsigned int Resources_Shaders_line_shader_len; extern unsigned char Resources_Shaders_line_shader[]; +extern const std::string Resources_Shaders_outline_shader_path; +extern unsigned int Resources_Shaders_outline_shader_len; +extern unsigned char Resources_Shaders_outline_shader[]; extern const std::string Resources_Shaders_pbr_shader_path; extern unsigned int Resources_Shaders_pbr_shader_len; extern unsigned char Resources_Shaders_pbr_shader[]; diff --git a/Resources/Shaders/combine.shader b/Resources/Shaders/combine.shader index 632eb89c..9955063c 100644 --- a/Resources/Shaders/combine.shader +++ b/Resources/Shaders/combine.shader @@ -27,5 +27,12 @@ void main() vec4 a = texture(u_Source, UV); vec4 b = texture(u_Source2, UV); - FragColor = vec4(vec3(a.rgb + (b.rgb) / 2.0), a.a); + if(b.a < 0.1f) + { + FragColor = a; + } + else + { + FragColor = vec4(vec3(a.rgb + (b.rgb) / 2.0), a.a); + } } \ No newline at end of file diff --git a/Resources/Shaders/outline.shader b/Resources/Shaders/outline.shader new file mode 100644 index 00000000..8cc25404 --- /dev/null +++ b/Resources/Shaders/outline.shader @@ -0,0 +1,56 @@ +#shader vertex +#version 440 core + +layout(location = 0) in vec3 VertexPosition; +layout(location = 1) in vec2 UVPosition; + +out flat vec2 a_UV; + +void main() +{ + a_UV = UVPosition; + gl_Position = vec4(VertexPosition, 1.0f); +} + +#shader fragment +#version 440 core + +uniform int u_EntityID; +uniform usampler2D u_EntityTexture; +uniform vec4 u_OutlineColor; + +out vec4 FragColor; + +in vec2 a_UV; + +void main() +{ + int target = u_EntityID; + const float TAU = 6.28318530; + const float steps = 32.0; + + float radius = 4.f; + vec2 uv = a_UV; + + // Correct aspect ratio + vec2 aspect = 1.0 / vec2(textureSize(u_EntityTexture, 0)); + + vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0f); + for (float i = 0.0; i < TAU; i += TAU / steps) + { + // Sample image in a circular pattern + vec2 offset = vec2(sin(i), cos(i)) * aspect * radius; + uint col = texture(u_EntityTexture, uv + offset).r; + + // Mix outline with background + float alpha = smoothstep(0.5, 0.7, int(col != target) * 10.0f); + fragColor = mix(fragColor, u_OutlineColor, alpha); + } + + if(fragColor.a > 0.1) + { + fragColor.a = 1.0f; + } + + FragColor = mix(vec4(0), fragColor, texture(u_EntityTexture, uv).r == target); +}