mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-01 05:48:14 +03:00
Progress towards working selection outline
This commit is contained in:
@@ -102,6 +102,13 @@ struct OutlinePushConstant
|
||||
[[vk::push_constant]]
|
||||
OutlinePushConstant pushConstants;
|
||||
|
||||
float2 GetTexelSize(Texture2D tex)
|
||||
{
|
||||
uint width, height;
|
||||
tex.GetDimensions(width, height);
|
||||
return 1.0 / float2(width, height);
|
||||
}
|
||||
|
||||
PSOutput main(PSInput input)
|
||||
{
|
||||
PSOutput output;
|
||||
@@ -116,31 +123,24 @@ PSOutput main(PSInput input)
|
||||
|
||||
float sampleValue = textures[entityIDTextureID].Sample(mySampler, uv).r;
|
||||
|
||||
if(abs(sampleValue - target) < 0.0001)
|
||||
{
|
||||
output.oColor0 = outlineColor;
|
||||
output.oColor0.a = 1.0;
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 fragColor = float4(0, 0, 0, 0);
|
||||
const float TAU = 6.28318530;
|
||||
const float steps = 32.0;
|
||||
for(float i = 0.0f; i < TAU; i += TAU / steps)
|
||||
{
|
||||
float2 uvOffset = float2(sin(i), cos(i)) * radius;
|
||||
float2 uvOffset = float2(sin(i), cos(i)) * (GetTexelSize(textures[entityIDTextureID])) * radius;
|
||||
|
||||
float2 sampleUV = uv + uvOffset;
|
||||
sampleUV.x = clamp(sampleUV.x, 0.0, 0.999);
|
||||
sampleUV.y = clamp(sampleUV.y, 0.0, 0.999);
|
||||
|
||||
int sampleValue = (int)textures[entityIDTextureID].Sample(mySampler, sampleUV).r;
|
||||
if(sampleValue == target)
|
||||
float sample = textures[entityIDTextureID].Sample(mySampler, sampleUV).r;
|
||||
if(sample == target)
|
||||
{
|
||||
hasHit = 1.0f;
|
||||
}
|
||||
|
||||
float alpha = smoothstep(0.5, 0.9, int(sampleValue != target) * hasHit * 10.0f);
|
||||
float alpha = smoothstep(0.5, 0.9, hasHit);
|
||||
float4 outputColor = float4(
|
||||
lerp(fragColor.r, outlineColor.r, alpha),
|
||||
lerp(fragColor.g, outlineColor.g, alpha),
|
||||
@@ -156,6 +156,15 @@ PSOutput main(PSInput input)
|
||||
fragColor.a = 1.0f;
|
||||
}
|
||||
|
||||
output.oColor0 = fragColor;
|
||||
float3 sourceTexture = textures[pushConstants.SourceTextureID].Sample(mySampler, uv).rgb;
|
||||
float ratio = float(sampleValue != target && hasHit > 0.0f);
|
||||
float4 finalColor = float4(
|
||||
lerp(sourceTexture.r, fragColor.r, ratio),
|
||||
lerp(sourceTexture.g, fragColor.g, ratio),
|
||||
lerp(sourceTexture.b, fragColor.b, ratio),
|
||||
lerp(1.0f, fragColor.a, ratio)
|
||||
);
|
||||
|
||||
output.oColor0 = finalColor;
|
||||
return output;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ PSOutput main(PSInput input)
|
||||
|
||||
output.oMaterial = float4(materialOuput, 1.0f);
|
||||
|
||||
output.oEntityID = float4(pushConstants.entityID, pushConstants.entityID, pushConstants.entityID, pushConstants.entityID);
|
||||
output.oEntityID = float4(pushConstants.entityID, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ SceneRenderPipeline::SceneRenderPipeline()
|
||||
TonemappedOutput = CreateRef<VulkanImage>(ImageFormat::RGBA8, defaultSize);
|
||||
TonemappedOutput->SetDebugName("TonemappedOutput");
|
||||
|
||||
GBufferEntityID = CreateRef<VulkanImage>(ImageFormat::R32F, defaultSize);
|
||||
GBufferEntityID = CreateRef<VulkanImage>(ImageFormat::RGBA8, defaultSize);
|
||||
GBufferEntityID->SetDebugName("GBufferEntityID");
|
||||
|
||||
OutlineOutput = CreateRef<VulkanImage>(ImageFormat::RGBA8, defaultSize);
|
||||
@@ -666,7 +666,7 @@ void SceneRenderPipeline::RecreatePipeline()
|
||||
auto& outlinePass = GBufferPipeline.AddPass("Outline");
|
||||
outlinePass.SetShaders(shaderMgr.GetShader("outline_vert"), shaderMgr.GetShader("outline_frag"));
|
||||
outlinePass.SetPushConstant<OutlineConstant>(outlineConstant);
|
||||
outlinePass.AddAttachment("OutlineOutput", ImageFormat::RGBA8);
|
||||
outlinePass.AddAttachment("GizmoCombineOutput", ImageFormat::RGBA8);
|
||||
outlinePass.SetDepthTest(false);
|
||||
outlinePass.AddInput("ShadingOutput");
|
||||
outlinePass.AddInput("EntityID");
|
||||
@@ -686,7 +686,7 @@ void SceneRenderPipeline::RecreatePipeline()
|
||||
});
|
||||
outlinePass.SetRender([&](PassRenderContext& ctx)
|
||||
{
|
||||
outlineConstant.SourceTextureID = GPUResources::Get().GetBindlessTextureID(ShadingOutput->GetID());
|
||||
outlineConstant.SourceTextureID = GPUResources::Get().GetBindlessTextureID(GizmoCombineOutput->GetID());
|
||||
outlineConstant.EntityIDTextureID = GPUResources::Get().GetBindlessTextureID(GBufferEntityID->GetID());
|
||||
outlineConstant.DepthTextureID = GPUResources::Get().GetBindlessTextureID(GBufferDepth->GetID());
|
||||
outlineConstant.SelectedEntityID = ctx.selectedEntity;
|
||||
@@ -706,6 +706,12 @@ void SceneRenderPipeline::RecreatePipeline()
|
||||
GBufferPipeline.Build();
|
||||
}
|
||||
|
||||
int SceneRenderPipeline::MousePick(const Vector2& coord)
|
||||
{
|
||||
GBufferEntityID->GetImage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ref<VulkanImage> SceneRenderPipeline::ResizeImage(PassRenderContext& ctx, Ref<VulkanImage> image, const Vector2& size)
|
||||
{
|
||||
if (image->GetSize() == size)
|
||||
|
||||
@@ -184,12 +184,14 @@ namespace Nuake
|
||||
|
||||
void SetCamera(UUID camera);
|
||||
void Render(PassRenderContext& ctx);
|
||||
Ref<VulkanImage> GetOutput() { return GizmoCombineOutput; }
|
||||
Ref<VulkanImage> GetOutput() { return OutlineOutput; }
|
||||
|
||||
MulticastDelegate<DebugCmd&>& OnDebugDraw() { return DebugDrawDelegate; }
|
||||
MulticastDelegate<DebugLineCmd&>& OnLineDraw() { return DebugLineDrawDelegate; }
|
||||
|
||||
void RecreatePipeline();
|
||||
|
||||
int MousePick(const Vector2& coord);
|
||||
private:
|
||||
Ref<VulkanImage> ResizeImage(PassRenderContext& ctx, Ref<VulkanImage> image, const Vector2& size);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "SceneViewport.h"
|
||||
|
||||
#include "Nuake/Rendering/Vulkan/VulkanImage/VulkanImage.h"
|
||||
#include "VulkanRenderer.h"
|
||||
|
||||
#include "SceneRenderPipeline.h"
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -13,6 +16,15 @@ Viewport::Viewport(UUID inViewId, const Vector2& inViewportSize) :
|
||||
renderTarget = CreateRef<VulkanImage>(ImageFormat::RGBA16F, viewportSize);
|
||||
}
|
||||
|
||||
int Viewport::MousePick(const Vector2& mouseCoord)
|
||||
{
|
||||
auto& sceneRenderer = VkRenderer::Get().SceneRenderers[id];
|
||||
int result = sceneRenderer->sceneRenderPipeline->MousePick(mouseCoord);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Viewport::Resize()
|
||||
{
|
||||
if (viewportSize != queuedResize)
|
||||
|
||||
@@ -45,6 +45,8 @@ namespace Nuake
|
||||
return queuedResize != viewportSize;
|
||||
}
|
||||
|
||||
int MousePick(const Vector2& mouseCoord);
|
||||
|
||||
void SetSelectedEntityID(int id) { selectedEntityID = id; }
|
||||
int GetSelectedEntityID() const { return selectedEntityID; }
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ VulkanImage::VulkanImage(ImageFormat inFormat, Vector2 inSize, ImageUsage usage)
|
||||
|
||||
if (info.pName)
|
||||
{
|
||||
Logger::Log("Deleting " + std::string(info.pName), "Vulkan", VERBOSE);
|
||||
//Logger::Log("Deleting " + std::string(info.pName), "Vulkan", VERBOSE);
|
||||
}
|
||||
|
||||
vkDestroyImageView(VkRenderer::Get().GetDevice(), dataCopy.ImageView, nullptr);
|
||||
@@ -325,7 +325,7 @@ VulkanImage::VulkanImage(void* inData, size_t inSize) :
|
||||
|
||||
VulkanImage::~VulkanImage()
|
||||
{
|
||||
Logger::Log("Deleting VulkanImage", "vulkan", VERBOSE);
|
||||
//Logger::Log("Deleting VulkanImage", "vulkan", VERBOSE);
|
||||
GPUResources::Get().QueueDeletion(GetGPUCleanUpStack());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user