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?
-
What do you mean by "use textures to sort items"? What were they actually doing?Nicol Bolas– Nicol Bolas2016年03月15日 22:22:26 +00:00Commented Mar 15, 2016 at 22:22
-
Yes, the keys are stored in textures. The fragment shader compare the keys and write them in sorted order in the output texture. Here is the article from GPU Gems: http.developer.nvidia.com/GPUGems2/gpugems2_chapter46.htmlOcto– Octo2016年03月15日 22:39:23 +00:00Commented Mar 15, 2016 at 22:39
1 Answer 1
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.