0

I'm looking for an efficient way to store datas in a texture instead of using uniforms. The goal is to store bones matrices in a texture. I'm currently doing like this :

- one RGBA pixel = one float
- (128, 255, 32, 14) = 0.128 255 032 014

It works and it's much faster than passing vars through uniforms. Still, I think it's a lot of calculations to do such a little thing.

So do you know a better way to construct a float from RGBA pixel? Is there a built-in way to construct a 4*4 matrix from several RGBA pixels?

Kara
  • 6,115
  • 16
  • 50
  • 57
cyrille56
  • 1
  • 2
  • "*It works and it's much faster than passing vars through uniforms.*" How do you figure that it's faster? You're not reading *equivalent* amounts of data yet. – Nicol Bolas May 30 '16 at 14:40
  • assuming you have no native floating point texture support you can still [pack your data like this](http://stackoverflow.com/questions/18453302/how-do-you-pack-one-32bit-int-into-4-8bit-ints-in-glsl-webgl/18454838#18454838). To be honest though there are very few cases where texture reads will be "*much faster than passing vars through uniforms*" ... – LJᛃ May 30 '16 at 15:10
  • Thanks for answers. I say that it's faster bescause I have one body (83 bones, 126 000 triangles) on wich I tried two methods. First method, I pass pre-calculated matrices through uniforms, and I got 340 FPS. second method, I bind a texture that stores matrices and I got 390 FPS. Thanks for the link, I'll look at this (but it will take me some time to understand properly). I think texture reading can be faster than uniforms, because texture reading only uses GPU, whereas uniforms uses CPU-GPU flows, and to my knowledge, this is the greatest 3d API's weakness today. – cyrille56 May 30 '16 at 16:18
  • Tested and it perfectly works, thanks again. To speak about perfs, the cost is almost nothing. I'm currently running my test model at 449 FPS (340 with standard uniform matrices instead of texture stored matrices). I tried to replace the matrix construction from texture by a simple identity matrix, and i gained only 3 FPS. So I think it worth it. My model has 83 bones, 126 000 triangles, and each vertex can have up to 8 bones, so i think this test is representative enough. – cyrille56 May 31 '16 at 12:42
  • What's your target openGL version ? I mean you could also just use things like float textures (GL_R32F), UBOs, SSBOs, .... so many options. – 246tNt Jun 01 '16 at 12:30
  • I use python/pyglet, so I'm not sure about openGL version. I just heard about floating points texture thanks to LJ, and I'll probably take a look at this later. buffer objects are a bit complicated to use for a beginner like me... – cyrille56 Jun 03 '16 at 06:14

1 Answers1

0

Here's the answer thanks to LJ. Didn't tried it yet, but that's the exact same problem.

Community
  • 1
  • 1
cyrille56
  • 1
  • 2