Search code examples
openglshader

How to pass a value in shader to CPU?


I am building a point cloud viewer where I need to be able to select a point for manual point cloud registration.

I know it is possible to pass mouse location to fragment shader to select a point. But how do I send the result back to the CPU? I thought uniform is a good way to do it but google search results are showing that it is read-only on the GPU side.

Many of the box selection examples are using CPU side collision check where it is not desirable in my case due to the very high number of points to display.

One possible solution is using fast neighbour search such as octree. But I am not considering this option at this stage.


Solution

  • You can use an SSBO or Shader Storage Buffer Object. You can perform read and write operations with it.

    References:

    1. https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object
    2. https://www.geeks3d.com/20140704/tutorial-introduction-to-opengl-4-3-shader-storage-buffers-objects-ssbo-demo/