Outline renderer can now depth test

This commit is contained in:
Antoine Pilote
2024-08-16 17:57:10 -04:00
parent e0ebf9dbdb
commit c996b9b114
3 changed files with 17 additions and 8 deletions

View File

@@ -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<Nuake::File>& file)
{
Type = EditorSelectionType::File;
Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = 0;
Nuake::Engine::GetCurrentScene()->m_SceneRenderer->mOutlineEntityID = -1;
File = file;
}
EditorSelection(const Ref<Nuake::Directory>& 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;
}

View File

@@ -71,11 +71,12 @@ namespace Nuake
mTempModels.clear();
}
uint32_t mOutlineEntityID = 0;
int mOutlineEntityID = 0;
private:
Matrix4 mProjection, mView;
Vector3 mCamPos;
// GBuffer
Scope<FrameBuffer> mGBuffer;
Scope<FrameBuffer> mShadingBuffer;
Scope<FrameBuffer> mToneMapBuffer;

View File

@@ -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;
}