Reputation: 563
I am using instancing to draw a large set of billboards.
I need to sort these instances by distance to camera to fix transparency artifacts.
Ideally I would like to sort the instance buffer on the GPU using shaders.
The articles I've read use textures to sort items. But is it possible to directly sort the instance buffer? Or quickly transfer the data from the texture to the instance buffer?
Upvotes: 2
Views: 458
Reputation: 563
Ok, I just found the bit I was missing. (sorry I've been reading articles for days without finding how).
I must store instance data in a Buffer Texture. https://www.opengl.org/wiki/Buffer_Texture
It's a buffer that can also be accessed as a texture.
It can therefore be used as texture by the fragment shader when sorting. And it should be accessible as an attribute in the vertex shader when drawing the instances.
Upvotes: 2