1

Does anyone know how to make a WebGL texture which is of lower precision? I want to push quite a lot of values onto the GPU (its tiled 3D data for ray tracing). The volume rendering is animated, so the data is updated each frame. This is currently a bottleneck in the performance.

I'd like to reduce the precision of each of the texel values as much as possible, as I don't think it will affect the visualisation too much. What is the default precision of a texel a value? How can I specify it to be lower? I'd be happy with 4 bit precision if it helped with performance.

When I google I seem to find lots of stuff about setting the precision of variables once they are on the shader, but I want to do it to the texture before it gets sent to the GPU.

Thanks everyone. Code is here if you want a look - or if you need to know something specific about the code then let me know

Thanks

nrob
  • 861
  • 1
  • 8
  • 22
  • 1
    from the texture constructor `Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy )` you can use the `format` and `type` to modify the texture. – gaitat May 29 '15 at 14:54
  • so if I've got an 8bit per channel RGB image, and I construct it with a format of RGB and a type of THREE.UnsignedShort565Type does that reduce the precision to 5, 6, 5 bits? – nrob May 29 '15 at 14:57
  • using THREE.UnsignedShort565type gives me this error `[.WebGLRenderingContext-0x7fa83294fe10]RENDER WARNING: texture bound to texture unit 1 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering.` – nrob May 29 '15 at 15:03
  • I think you commented instead of answering, gaitat, but that seems to run, so I guess you should get a green tick! unfortunately it hasn't sped the code up any... – nrob May 29 '15 at 15:22
  • 1
    you need to convert your texture first (http://stackoverflow.com/questions/26225594/php-convert-24-bit-colors-to-4-bit) and then use the texture format and type to tell webgl. – gaitat May 29 '15 at 15:31
  • 2
    Encode information into a texture. Let each texel channel represent several information (4x 2bits or so...). – Dragan Okanovic May 29 '15 at 20:34
  • @AbstractAlgorithm I like the idea but it's frustrating to code without functions like `floatBitsToUint` and bitshifting ops. – jozxyqk May 30 '15 at 05:53
  • @absractalgorythm I tried that but the precision wasnt right in the minor 4 bits. Maybe we weren't setting the type properly – nrob May 30 '15 at 10:43
  • 1
    @jozxyqk you can [bitshift using multiplication](http://stackoverflow.com/questions/18453302/how-do-you-pack-one-32bit-int-into-4-8bit-ints-in-glsl-webgl/18454838#18454838), and by that easily write your own casting functions. – LJᛃ May 30 '15 at 12:43
  • i tired bitshifting with multiplication as you try but the minor bits were just noise. i wonder if its because I didn't specify the texture type was 8 bit uints. i might have another go – nrob May 31 '15 at 08:36

0 Answers0