floating point - OpengL ES / Angle : rendering to single channel float texture -


i trying use shaders simple operations on large matrices/images. wrote code running regular opengl rendering single channel float textures in frame buffer objects, works fine.

i need have run on different platforms (uwp + angle, android,...) i'm trying port code opengl es 2.0 ; can make work regular rgba images, doesn't float images.

what works (output buffer 'data_out' contains result of render)

format = gl_rgba; type = gl_unsigned_byte; internal_format = gl_rgba; glteximage2d(gl_texture_2d, 0, internal_format,     width,     height,     0, format, type,     data  (...) gldrawelements(gl_triangles, (2) * 3, gl_unsigned_short, 0); glreadpixels(0, 0, width, height, gl_rgba, gl_unsigned_byte, data_out); 

what doesn't work :

format = gl_red_ext; type = gl_float; internal_format = gl_red_ext; glteximage2d(gl_texture_2d, 0, internal_format,     width,     height,     0, format, type,     data); (...) glreadpixels(0, 0, width, height, gl_red_ext, gl_float, data_out); 

what expect in data_out :

27.0000000  float 22.7840576  float 11.4528332  float -3.45501971 float -17.2838974 float -25.7151508 float -26.1157665 float (...) 

what :

-25.7161427 float -25.7161427 float -25.7161427 float -25.7161427 float -25.7161427 float -17.2863979 float -17.2863979 float (...) 

i not find many similar issues online, except following discussion : https://groups.google.com/forum/#!topic/webgl-dev-list/ms21hnwk0tg , seems conclude "it can't done", written in 2012.

so there no way of rendering single channel float texture opengl es 2.0 ? because major issue project.

update - tried float to/from rgba encoding mentioned in comment below.

inline float4 encodefloatrgba( float v ) { float4 enc = float4(1.0, 255.0, 65025.0, 160581375.0) * v; enc = frac(enc); enc -= enc.yzww * float4(1.0/255.0,1.0/255.0,1.0/255.0,0.0); return enc; } inline float decodefloatrgba( float4 rgba ) { return dot( rgba, float4(1.0, 1/255.0, 1/65025.0, 1/160581375.0) ); } void main() { float raw_value = decodefloatrgba(texture2d( mytexturesampler, uv )); gl_fragcolor = encodefloatrgba(raw_value); } 

pushing texture filled arbitrary value (5.23) , retrieving display glreadpixels, 3 bytes out of 4, alpha being stuck 0

input value (byte per byte)

[0] 41 ')'  unsigned char [1] 92 '\\' unsigned char [2] 167 '§' unsigned char [3] 64 '@'  unsigned char 

output value (byte per byte)

[0] 41 ')'  unsigned char [1] 92 '\\' unsigned char [2] 167 '§' unsigned char [3] 0 '\0'  unsigned char 

for floating point format support need extension: https://www.khronos.org/registry/opengl/extensions/oes/oes_texture_float.txt

for single channel render formats need extension: https://www.khronos.org/registry/opengl/extensions/ext/ext_texture_rg.txt

it's not unusual approach encode floating point number across multiple channels of 8888 or 4444 render target. there's example , several links here: http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -