How to read custom data from framebuffer

Viewed 21

for the past few days I've been trying to implement mouse picking in my vulkan game engine and part of that is reading data from framebuffers. Now I can successfully read RGBA data. But what I need is to read specific attachment containing id of the entity.

Here is what my fragment shader looks like:

#version 450 core

struct VertexInput
{
    vec4 Color;
    vec2 TexCoord;
    float TilingFactor;
};

// Inputs
layout(location = 0) in VertexInput Input;
layout(location = 3) in flat uint in_TexIndex;
layout(location = 4) in flat int in_EntityID;

layout(binding = 1) uniform sampler2D u_Samplers[10];

// Outputs
layout(location = 0) out vec4 o_Color;
layout(location = 1) out int o_EntityID; //  <-- This is what I need

void main()
{
    o_EntityID = in_EntityID;
    o_Color = Input.Color * texture(u_Samplers[in_TexIndex], Input.TexCoord * Input.TilingFactor);
} 

And get this warning

Validation layer: Validation Warning: [ UNASSIGNED-CoreValidation-Shader-OutputNotConsumed ] Object 0: handle = 0x5dbcf90000000065, type = VK_OBJECT_TYPE_SHADER_MODULE; | MessageID = 0x609a13b | fragment shader writes to output location 1 with no matching attachment

which is understandable.

I know I need to add attachment into my framebuffer object but I am not sure which one or how should I approach this problem. Any ideas? Thanks :)

0 Answers
Related