2

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?

asked Mar 15, 2016 at 22:08
2
  • What do you mean by "use textures to sort items"? What were they actually doing? Commented 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.html Commented Mar 15, 2016 at 22:39

1 Answer 1

2

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.

answered Mar 15, 2016 at 22:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.