feat: add click to select

This commit is contained in:
2026-10-23 20:53:56 +02:00
parent f055bdcbf1
commit f7e7c56392
20 changed files with 385 additions and 20 deletions
@@ -21,7 +21,8 @@ void MeshPipeline::init(
GfxDevice& gfxDevice,
RenderResources& resources,
VkFormat drawImageFormat,
VkFormat depthImageFormat)
VkFormat depthImageFormat,
VkFormat selectionImageFormat)
{
try
{
@@ -31,6 +32,9 @@ void MeshPipeline::init(
const auto fragShader =
AssetFS::GetInstance().GetCookedPathForFile("engine://shaders/mesh.frag");
const auto selectionShader =
AssetFS::GetInstance().GetCookedPathForFile("engine://shaders/selection.frag");
const auto bufferRange = VkPushConstantRange{
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
.offset = 0,
@@ -82,6 +86,27 @@ void MeshPipeline::init(
);
}
{
PipelineConfigInfo pipelineConfig{};
Pipeline::DefaultPipelineConfigInfo(pipelineConfig);
pipelineConfig.name = "Mesh Selection Prepass Pipeline";
pipelineConfig.pipelineLayout = m_pipelineLayout;
pipelineConfig.vertexAttributeDescriptions = {};
pipelineConfig.vertexBindingDescriptions = {};
pipelineConfig.colorAttachments = {selectionImageFormat};
pipelineConfig.depthAttachment = depthImageFormat;
m_selectionPrepassPipeline = std::make_unique<Pipeline>(
gfxDevice,
vertexShader.string(),
selectionShader.string(),
pipelineConfig
);
}
{
PipelineConfigInfo pipelineConfig{};
Pipeline::DefaultPipelineConfigInfo(pipelineConfig);
@@ -120,16 +145,18 @@ void MeshPipeline::drawDepthPrepass(
const RenderResources& resources,
const GPUBuffer& sceneDataBuffer,
const IndirectDrawList& drawList,
const IndirectDrawList::View& view)
const IndirectDrawList::View& view,
bool writeObjectIds)
{
if (!m_depthPrepassPipeline)
const auto& pipeline = writeObjectIds ? m_selectionPrepassPipeline : m_depthPrepassPipeline;
if (!pipeline)
{
return;
}
drawMeshes(
cmd,
*m_depthPrepassPipeline,
*pipeline,
renderExtent,
resources,
sceneDataBuffer,
@@ -228,6 +255,7 @@ void MeshPipeline::cleanup(VkDevice device)
{
m_pipeline.reset();
m_depthPrepassPipeline.reset();
m_selectionPrepassPipeline.reset();
if (m_pipelineLayout != VK_NULL_HANDLE && device != VK_NULL_HANDLE)
{