diff --git a/Editor/src/Actions/EditorSelection.h b/Editor/src/Actions/EditorSelection.h index ce465ccd..74798506 100644 --- a/Editor/src/Actions/EditorSelection.h +++ b/Editor/src/Actions/EditorSelection.h @@ -34,7 +34,7 @@ public: Type = None; if (const auto& scene = Nuake::Engine::GetCurrentScene(); scene) { - Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0; + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = -1; } } @@ -48,21 +48,21 @@ public: EditorSelection(const Ref& file) { Type = EditorSelectionType::File; - Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0; + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = -1; File = file; } EditorSelection(const Ref& dir) { Type = EditorSelectionType::Directory; - Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0; + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = -1; Directory = dir; } EditorSelection(const Nuake::Resource& resource) { Type = EditorSelectionType::Resource; - Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0; + Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = -1; Resource = resource; } diff --git a/Nuake/src/Rendering/SceneRenderer.h b/Nuake/src/Rendering/SceneRenderer.h index e5604da0..efbebb14 100644 --- a/Nuake/src/Rendering/SceneRenderer.h +++ b/Nuake/src/Rendering/SceneRenderer.h @@ -71,11 +71,12 @@ namespace Nuake mTempModels.clear(); } - uint32_t mOutlineEntityID = 0; + int mOutlineEntityID = 0; private: Matrix4 mProjection, mView; Vector3 mCamPos; + // GBuffer Scope mGBuffer; Scope mShadingBuffer; Scope mToneMapBuffer; diff --git a/Resources/Shaders/outline.shader b/Resources/Shaders/outline.shader index 0219f089..4f976b41 100644 --- a/Resources/Shaders/outline.shader +++ b/Resources/Shaders/outline.shader @@ -18,6 +18,7 @@ void main() uniform int u_EntityID; uniform usampler2D u_EntityTexture; uniform vec4 u_OutlineColor; +uniform sampler2D u_Depth; out vec4 FragColor; @@ -34,7 +35,8 @@ void main() // sample middle uint middleSample = texture(u_EntityTexture, uv).r; - + float depth = texture(u_Depth, uv).r; + // Correct aspect ratio vec2 aspect = 1.0 / vec2(textureSize(u_EntityTexture, 0)); @@ -44,9 +46,15 @@ void main() { // Sample image in a circular pattern vec2 offset = vec2(sin(i), cos(i)) * aspect * radius; - uint col = texture(u_EntityTexture, uv + offset).r; - if(col == target) + // We dont want to sample outside the viewport + vec2 sampleUv = uv + offset; + sampleUv.x = clamp(sampleUv.x, 0.0, 1.0); + sampleUv.y = clamp(sampleUv.y, 0.0, 1.0); + + uint col = texture(u_EntityTexture, sampleUv).r; + float depthTarget = texture(u_Depth, sampleUv).r; + if(col == target && depthTarget < depth) { hasHit = 1.0f; }