Results 1 to 2 of 2

Thread: Any examples of object picking with Vulkan

  1. #1
    Newbie Newbie
    Join Date
    Sep 2018

    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?


  2. #2
    Junior Member Newbie
    Join Date
    Oct 2018
    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

    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)

Similar Threads

  1. Replies: 2
    Last Post: 10-19-2017, 08:06 AM
  2. Any simple examples of Vulkan layers?
    By glokta in forum Vulkan
    Replies: 3
    Last Post: 10-06-2016, 10:33 AM
  3. Replies: 0
    Last Post: 05-23-2016, 02:59 AM
  4. zooming, picking examples
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-03-2004, 10:11 PM
  5. Object Picking
    By Montoya in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-22-2003, 12:12 AM

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