Results 1 to 2 of 2

Thread: Any examples of object picking with Vulkan

  1. #1
    Newbie
    Join Date
    Sep 2018
    Posts
    1

    Any examples of object picking with Vulkan

    Would anyone be able to point me to an object picking example with Vulkan using the render each object using a different color to a texture in a separate rendering pass and read those texture pixels to get the color value approach.

    I'm very new to Vulkan, and I'm starting to port my OpenGl apps over, and I use this technique a lot.

    In OpenGL, I just create a separate render buffer, and have the fragment shader just pass the object id over, and set the object id render buffer to that color value.

    Or, are there any examples of using multiple render targets, (the frame buffer and a texture), where you specify multiple outputs in the fragment shader?

    thanks

  2. #2
    Junior Member
    Join Date
    Oct 2018
    Posts
    13
    One approach is using different pipeline. I think someone knows how to use subpasses for this purpose.

    1) You can create different pipeline with special shaders, but use self-created images instead of swapchain images for framebuffers

    e.g.
    layout(push_constant) uniform PushConsts
    {
    uint r;
    uint g;
    uint b;
    } pushConsts;

    void main()
    {
    outColor = vec4(pushConsts.r/255.f, pushConsts.g/255.f, pushConsts.b/255.f, 1.0f);
    }

    2) push object id using pushconstants before call vkDraw for your object
    3) build command buffer and sumbit it in queue (only graphics queue, it is not necessary for present)
    4) copy self-created image from device to host
    5) get necessary position pixel in your self-created image and the color of this pixel is your object id


    You can call described above procedure on demand (e.g. per mouse button click)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean