Open danilw opened 2 years ago
P.S. Two problems in GLES2 because GLES2 dont have texelFetch
:
First - remember about interpolation when use GLES2 and want read "exact values".
And better use function textureLod
to avoid problems in GLES2 that "broken GPU drivers" can bring because function texture
use LODs (and huge slowdown because derivatives).
https://registry.khronos.org/OpenGL-Refpages/es3.0/html/textureLod.xhtml
(just replace)
vec4 data1=texture(iChannel1,vec2(0,0));
to
vec4 data1=textureLod(iChannel1,vec2(0,0),0.);
(etc to all texture function)
And remember that you need point middle of pixel when use texture
or textureLod
(and want read exact values).
Because if you set Filter that means Viewport apply linear interpolation to pixels on read.
And I did set it to enabled in this project:
https://github.com/Volkovina/Shadertoy-to-Godot-forked-changed-/blob/main/mainImage.gd#L16
iChannel.flags=Texture.FLAG_FILTER
I think you can replace it by 0 to disable
(and I do not remember if Godot3 force linear filtering anyway in GLES2, or its another GLES2 limitation and linear filtering enabled always)
so correct code will be:
vec4 data1=textureLod(iChannel1,vec2(0,0)+0.5/iResolution.xy,0.);
vec4 data2=textureLod(iChannel1,vec2((iResolution.x-1.)/iResolution.x, 0.0)+0.5/iResolution.xy,0.);
vec4 data3=textureLod(iChannel1,vec2(0.0,(iResolution.y-1.) / iResolution.y)+0.5/iResolution.xy,0.);
vec4 data4=textureLod(iChannel1,vec2((iResolution.x-1.)/iResolution.x
,(iResolution.y-1.)/ iResolution.y)+0.5/iResolution.xy,0.);
(added +0.5/iResolution.xy
to point middle of pixel)
Second: At some point pixel center will be shifted because float precision. From my experience when you read larger than 512 pixel using textureLod - you can not point to middle anymore, it always will be +0.500001 or +0.49999 shift - that means float value will be ruined by linear interpolation (if its enabled for texture)
Something like this can happen https://youtu.be/rqmQ7EnDmb8 (it other bug, but result very similar to "broken value by linear interpolation")
P.S.S But "it works" in GLES2(if you dodge all problems that you may face) I have this project https://danilw.itch.io/cubes-experiment
This project/game is GLES2, and it use many framebuffers(viewports) to store data for custom lighting and I read all this data by textureLod
, and viewport size there less than 512x512 pixels because if more than this my data was ruined by interpolation(or other bugs, I dont remember everything now, there was way too many bugs everywhere(in Godot, in WebGL, in GPU drivers, I did many bugreports from this project to all related stuff)).
(ofc biggest limitation of GLES2 is 8 bit buffers, that 0 to 1 or 0 to 255 because you can store only 1/255 step in 8 bit float)
Context: https://www.youtube.com/watch?v=v48O7Nk_n4g&lc=UgznYgtuokUKpT53KC54AaABAg
shaders I use there from https://www.shadertoy.com/view/WlcBWr BufB write numbers to self, when BufA and BufC display those numbers as you can see in BufB
fragColor=vec4(iTime,float(iFrame),data.z+1.,0.);
I write iTime and iFrame as color, so its >1.0 values (after 30-60 frames iTime will be >1.0)Godot3 GLES3 default build use 16-bit floats for buffers (when 3d and HDR clicked in Viewport options) so in Godot 3 GLES3 you can write "big" floats bigger than 1.0, this why writing/reading iTime and IFrame works
in GLES2 you have limitation is 8-bit buffers, that means only 0.0 to 1.0 values can be stored in Viewport this why you see 1.0 instead of big numbers in GLES2 in Godot3
you can do "small fix(to test your GLES2 version)":
https://github.com/Volkovina/Shadertoy-to-Godot-forked-changed-/blob/main/iChannel1.shader#L85 change it to:
fragColor=vec4(iTime/10.,float(iFrame)/256.,(data.z*256.+1.)/256.,0.);
this should show iTime for first 10 sec, then it will be >1.0 and iFrame for first 256 frames, after 256 it also will be >1.0
(to display iTime to 10 and frames to 256) https://github.com/Volkovina/Shadertoy-to-Godot-forked-changed-/blob/main/iChannel0.shader#L100 https://github.com/Volkovina/Shadertoy-to-Godot-forked-changed-/blob/main/iChannel2.shader#L100
change to: