16 bit floating point texture

user2881543

I'm using OpenGL ES 3.0 to create a fluid dynamics effect on the GPU. Using a 16 bit floating point FBO I can make the effect work correctly.

My problem is I am targeting the GPU that does not support floating point textures. The effect crumbles under the lack of precision.

This effect is only two dimensional so I am only reading from and writing to the first 2 channels of an FBO. So, I am wondering if anyone has successfully used two channels of an unsigned int texture to add extra precision, and how this might be possible.

My current solution is as follows (GLSL fragment shader snippet) , and it doesn't work well at all:

#define read(vec) ((((vec).xy * 255.0) - 127.0) / 127.0) + (vec).zw / 255.0

vec4 write(vec2 vec)
{
    vec2 temp = ((vec * 127.0) + 127.0);
    vec2 a = floor(temp) / 255.0;
    vec2 b = mod(temp, 255.0);
    return vec4(a,b);
}

I think the main problem may be that with any scheme like this it is impossible to write zero.

I'm hoping someone has solved this already, or can see the solution to such a problem :)

Marius

I assume the values you want to store are between 0.0 and 1.0, but you want to have more precision utilizing two effective bytes of data right?

float read(vec2 rawData) 
{
    return rawData.x + rawData.y / 256.0;
}

vec2 write(float value)
{
    return vec2(value, floor(value * 256.0));
}

Setting the limits of the input/output floats to anything different than [0,1] would simply require mapping the output value into the range [0,1] and calling write, or mapping the input value from [0,1] to [min,max] which is simple:

// maps val from [fromMin,fromMax] to [toMin,toMax]
float lerp(float val, float fromMin, float fromMax, float toMin, float toMax)
{
    return toMin + (toMax - toMin) * (val - fromMin) / (fromMax - fromMin);
}

const vec2 minMax = vec2(-5.0, 10.0);

float readMapped(vec2 rawData)
{
    return lerp(read(rawData), 0.0, 1.0, minMax.x, minMax.y);
}

vec2 writeMapped(float value)
{
    return write(lerp(value, minMax.x, minMax.y, 0.0, 1.0));
}

Simply call these functions twice for two-channel input/output.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

IEEE754 Half Precision (16 bit) floating point data in vb.net

From Dev

Can anyone provide sample code demonstrating the use of 16 bit floating point in cuda?

From Dev

Floating point formatted to base 16

From Dev

Floating point formatted to base 16

From Dev

WebGL rendering to floating-point-texture

From Dev

OpenGL ES 3.0. Floating point texture

From Dev

opengl texture format for floating-point gpgpu

From Dev

WebGL iOS render to floating point texture

From Dev

Convert Uint8 (floating-point AUDIO_F32) to int16_t (16bit PCM)

From Dev

Floating point 'error' is php 64bit

From Dev

Native support for 64 bit floating point in Javascript

From Dev

HP 2114/15/16 floating point conversion

From Dev

Floating point differences between 64 bit and 32 bit with Round

From Dev

32-bit floating point math in 64-bit Python

From Dev

Writing to a floating point OpenGL texture in CUDA via a surface

From Dev

16-bit fixed point arithmetic multiplication

From Dev

What is the point of a 16-bit wide character?

From Dev

C++AMP Computing gradient using texture on a 16 bit image

From Dev

C++AMP Computing gradient using texture on a 16 bit image

From Dev

Converting 4 raw bytes into 32-bit floating point

From Dev

x86 80-bit floating point type in Java

From Dev

Handling a quadruple precision floating point (128-bit) number in java

From Dev

Converting a floating point to its corresponding bit-segments

From Dev

How to calculate 32-bit floating-point epsilon?

From Dev

Changing sign of a 64 bit floating point number in verilog?

From Dev

Handling a quadruple precision floating point (128-bit) number in java

From Dev

Float24 (24 bit floating point) to Hex?

From Dev

Floating point quantization from double to 8bit

From Dev

What bit pattern represents the max value for double precision floating point?

Related Related

  1. 1

    IEEE754 Half Precision (16 bit) floating point data in vb.net

  2. 2

    Can anyone provide sample code demonstrating the use of 16 bit floating point in cuda?

  3. 3

    Floating point formatted to base 16

  4. 4

    Floating point formatted to base 16

  5. 5

    WebGL rendering to floating-point-texture

  6. 6

    OpenGL ES 3.0. Floating point texture

  7. 7

    opengl texture format for floating-point gpgpu

  8. 8

    WebGL iOS render to floating point texture

  9. 9

    Convert Uint8 (floating-point AUDIO_F32) to int16_t (16bit PCM)

  10. 10

    Floating point 'error' is php 64bit

  11. 11

    Native support for 64 bit floating point in Javascript

  12. 12

    HP 2114/15/16 floating point conversion

  13. 13

    Floating point differences between 64 bit and 32 bit with Round

  14. 14

    32-bit floating point math in 64-bit Python

  15. 15

    Writing to a floating point OpenGL texture in CUDA via a surface

  16. 16

    16-bit fixed point arithmetic multiplication

  17. 17

    What is the point of a 16-bit wide character?

  18. 18

    C++AMP Computing gradient using texture on a 16 bit image

  19. 19

    C++AMP Computing gradient using texture on a 16 bit image

  20. 20

    Converting 4 raw bytes into 32-bit floating point

  21. 21

    x86 80-bit floating point type in Java

  22. 22

    Handling a quadruple precision floating point (128-bit) number in java

  23. 23

    Converting a floating point to its corresponding bit-segments

  24. 24

    How to calculate 32-bit floating-point epsilon?

  25. 25

    Changing sign of a 64 bit floating point number in verilog?

  26. 26

    Handling a quadruple precision floating point (128-bit) number in java

  27. 27

    Float24 (24 bit floating point) to Hex?

  28. 28

    Floating point quantization from double to 8bit

  29. 29

    What bit pattern represents the max value for double precision floating point?

HotTag

Archive