3

how can I send recursive data structure, like octree, to OpenGL GLSL shader? I think, I can send it as array of nodes and use indexes instead of pointers, is it a good idea? Are there other options to do it?

Nyan Cat
  • 303
  • 1
  • 5
  • 14
  • 3
    What do you want to do with it? The context of what purpose you'd put it to once you have it available in the shader is critical to the approach to take or avoid. – Will May 14 '13 at 10:09
  • Normally the data show itself how to be ordered once you work on what do you want to do with it. – Trax May 14 '13 at 10:10

2 Answers2

2

GPU ray tracing often uses recursive data structures such as triangles in kd-trees or sparse voxel octrees.

In a shader you can use a 1D texture sampler as though it was an array, making it easy to jump around.

However, performance suffers. All shaders in the batch (warp or whatever your card terms it) usually work in lock-step, so if one fragment requires recursing ten steps in the tree the other fragments in the batch have to wait for that fragment to do its ten random-memory-accesses before they can proceed.

GPUs work best when given a list of triangles to rasterise.

Will
  • 73,905
  • 40
  • 169
  • 246
0

checkout this question: Passing a list of values to fragment shader

and here: http://blog.icare3d.org/2010/07/opengl-40-abuffer-v20-linked-lists-of.html

Community
  • 1
  • 1
fen
  • 9,835
  • 5
  • 34
  • 57