Open Barti1975 opened 11 months ago
The shader is accessible on deaddeer.free.fr installations of my software, Exemples/Classes/Water/beach.ned with/or SteamVR and recompilation of sdl2player.zip on SourceForge directory. it seems that I substract or add a value that is clamped without shader code relative, and I am wondering how this hould be possible with same machine same sdl2 that OpenGL gives different results.
1st fragment shader :
uniform sampler2D Tex; uniform sampler2D Relief; uniform vec4 PRM;
vec2 quad(vec2 pos,float s) { vec4 r0; vec4 r1; vec4 r2; vec4 r3; vec4 r4; vec4 r5;
r0 = vec4( 0.0, 0.0, 0.0,0.0 ); r1.xy = pos.xy; r5.xy = vec2( -1.0, 0.0 ); r4.xy = s r5.xy; r1.xy = r1.xy + r4.xy; r1.xy = clamp( r1.xy , 0.001 , 0.999 ); r4.xy = r1.xy; r4.y = 1.0 - r4.y; r2 = texture2D(Tex, r4.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3 = texture2D(Relief, vec2(r1.xy)); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); if (r2.y<r3.y-0.01) { r0.y = r0.y + r2.y; } if (r2.y<r3.y-0.01) { r0.x = r0.x + 1.0; } if (r2.y>r3.y+0.01) { r0.y = r0.y + 0.00001; } r1.xy = pos.xy; r5.xy = vec2( 1.0, 0.0 ); r4.xy = s r5.xy; r1.xy = r1.xy + r4.xy; r1.xy = clamp( r1.xy , 0.001 , 0.999 ); r4.xy = r1.xy; r4.y = 1.0 - r4.y; r2 = texture2D(Tex, r4.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3 = texture2D(Relief, vec2(r1.xy)); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); if (r2.y<r3.y-0.01) { r0.y = r0.y + r2.y; } if (r2.y<r3.y-0.01) { r0.x = r0.x + 1.0; } if (r2.y>r3.y+0.001) { r0.y = r0.y + 0.00001; } r1.xy = pos.xy; r5.xy = vec2( 0.0, 1.0 ); r4.xy = s r5.xy; r1.xy = r1.xy + r4.xy; r1.xy = clamp( r1.xy , 0.001 , 0.999 ); r4.xy = r1.xy; r4.y = 1.0 - r4.y; r2 = texture2D(Tex, r4.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3 = texture2D(Relief, vec2(r1.xy)); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); if (r2.y<r3.y-0.01) { r0.y = r0.y + r2.y; } if (r2.y<r3.y-0.01) { r0.x = r0.x + 1.0; } if (r2.y>r3.y+0.01) { r0.y = r0.y + 0.000001; } r1.xy = pos.xy; r5.xy = vec2( 0.0, -1.0 ); r4.xy = s r5.xy; r1.xy = r1.xy + r4.xy; r1.xy = clamp( r1.xy , 0.001 , 0.999 ); r4.xy = r1.xy; r4.y = 1.0 - r4.y; r2 = texture2D(Tex, r4.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3 = texture2D(Relief, vec2(r1.xy)); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); if (r2.y<r3.y-0.01) { r0.y = r0.y + r2.y; } if (r2.y<r3.y-0.01) { r0.x = r0.x + 1.0; } if (r2.y>r3.y+0.01) { r0.y = r0.y + 0.00001; } r1.xy = pos.xy; r5.xy = vec2( 0.7, 0.7 ); r4.xy = s r5.xy; r1.xy = r1.xy + r4.xy; r1.xy = clamp( r1.xy , 0.001 , 0.999 ); r4.xy = r1.xy; r4.y = 1.0 - r4.y; r2 = texture2D(Tex, r4.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3 = texture2D(Relief, vec2(r1.xy)); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); if (r2.y<r3.y-0.01) { r0.y = r0.y + r2.y; } if (r2.y<r3.y-0.01) { r0.x = r0.x + 1.0; } if (r2.y>r3.y+0.01) { r0.y = r0.y + 0.00001; } r1.xy = pos.xy; r5.xy = vec2( 0.7, -0.7 ); r4.xy = s r5.xy; r1.xy = r1.xy + r4.xy; r1.xy = clamp( r1.xy , 0.001 , 0.999 ); r4.xy = r1.xy; r4.y = 1.0 - r4.y; r2 = texture2D(Tex, r4.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3 = texture2D(Relief, vec2(r1.xy)); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); if (r2.y<r3.y-0.01) { r0.y = r0.y + r2.y; } if (r2.y<r3.y-0.01) { r0.x = r0.x + 1.0; } if (r2.y>r3.y+0.01) { r0.y = r0.y + 0.00001; } r1.xy = pos.xy; r5.xy = vec2( -0.7, 0.7 ); r4.xy = s r5.xy; r1.xy = r1.xy + r4.xy; r1.xy = clamp( r1.xy , 0.001 , 0.999 ); r4.xy = r1.xy; r4.y = 1.0 - r4.y; r2 = texture2D(Tex, r4.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3 = texture2D(Relief, vec2(r1.xy)); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); if (r2.y<r3.y-0.01) { r0.y = r0.y + r2.y; } if (r2.y<r3.y-0.01) { r0.x = r0.x + 1.0; } if (r2.y>r3.y+0.01) { r0.y = r0.y + 0.00001; } r1.xy = pos.xy; r5.xy = vec2( -0.7, -0.7 ); r4.xy = s r5.xy; r1.xy = r1.xy + r4.xy; r1.xy = clamp( r1.xy , 0.001 , 0.999 ); r4.xy = r1.xy; r4.y = 1.0 - r4.y; r2 = texture2D(Tex, r4.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3 = texture2D(Relief, vec2(r1.xy)); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); if (r2.y<r3.y-0.01) { r0.y = r0.y + r2.y; } if (r2.y<r3.y-0.01) { r0.x = r0.x + 1.0; } if (r2.y>r3.y+0.01) { r0.y = r0.y + 0.00001; } return r0.xy; }
float calc(float color,vec2 tmp) { vec4 r0; vec4 r1; vec4 r2; vec4 r3; vec4 r4;
r0.x = 0.0; r0.y = color; r1 = vec4( 0.0, 1.0, 1.0,0.0 ); for (int a0=0;a0<16;a0++) { r2.xy = quad(tmp.xy,r1.x); r4.x = r0.y; r3.x = r1.y r2.y; r0.y = r4.x + r3.x; r1.x = r1.x + PRM.x; r4.x = r1.z; r3.x = r2.x r1.y; r1.z = r4.x + r3.x; r1.y = r1.y * PRM.y; } r0.y = r0.y / r1.z; return r0.y; }
void main(void) {
vec4 r0; vec4 r1; vec4 r2; vec4 r3; vec4 r4; vec4 r5; vec4 r6; vec4 r7;
r0 = gl_TexCoord[0]; r1 = texture2D(Relief, vec2(r0.xy)); r1.x = 2.0 r1.x - 1.0; r1.y = 2.0(255.0 r1.z + r1.y)/255.0 - 1.0; r1.zw = vec2(0.0,0.0); r5.xy = r0.xy; r5.y = 1.0 - r5.y; r2 = texture2D(Tex, r5.xy); r2.x = 2.0 r2.x - 1.0; r2.y = 2.0(255.0 r2.z + r2.y)/255.0 - 1.0; r2.zw = vec2(0.0,0.0); r3.y = calc(r2.y,r0.xy); r6.x = r2.x; r7.x = r2.y - r3.y; r5.x = r7.x 2.0; r2.x = r6.x + r5.x; r2.x = clamp( r2.x , -1.0 , 1.0 ); r3.z = r2.y - r3.y; if (r3.z<0.0) { r3.y = r3.y + PRM.w; } r4.x = 0.5 + 0.5 (r2.x); r4.w = 0.5 + 0.5 (r3.y); r4.y = fract( 255.0 r4.w ); r4.z = floor( 255.0 * r4.w ) / 255.0; r4.w = 1.0; gl_FragColor = r4; }
2nd fragment shader :
uniform sampler2D Tex; uniform sampler2D Prev; uniform sampler2D Relief; uniform vec4 SIZE; uniform vec4 PRM;
void main(void) {
vec4 r0; vec4 r1; vec4 r2; vec4 r3; vec4 r4; vec4 r5; vec4 r6; vec4 r7; vec4 r8; vec4 r9; vec4 r10; vec4 r11; vec4 r12; vec4 r13; vec4 r14;
r0 = gl_TexCoord[0]; r1 = texture2D(Relief, vec2(r0.xy)); r1.x = 2.0 r1.x - 1.0; r1.y = 2.0(255.0 r1.z + r1.y)/255.0 - 1.0; r1.zw = vec2(0.0,0.0); r0.x = r0.x SIZE.x; r0.y = r0.y SIZE.y; r11.x = r0.x + 1.0; r2.x = r11.x SIZE.z; r11.y = r0.y + 0.0; r2.y = r11.y SIZE.w; r2.xy = clamp( r2.xy , 0.001 , 0.999 ); r11.xy = r2.xy; r11.y = 1.0 - r11.y; r3 = texture2D(Tex, r11.xy); r3.x = 2.0 r3.x - 1.0; r3.y = 2.0(255.0 r3.z + r3.y)/255.0 - 1.0; r3.zw = vec2(0.0,0.0); r11.x = r0.x - 1.0; r2.x = r11.x SIZE.z; r11.y = r0.y + 0.0; r2.y = r11.y SIZE.w; r2.xy = clamp( r2.xy , 0.001 , 0.999 ); r11.xy = r2.xy; r11.y = 1.0 - r11.y; r4 = texture2D(Tex, r11.xy); r4.x = 2.0 r4.x - 1.0; r4.y = 2.0(255.0 r4.z + r4.y)/255.0 - 1.0; r4.zw = vec2(0.0,0.0); r11.x = r0.x + 0.0; r2.x = r11.x SIZE.z; r11.y = r0.y + 1.0; r2.y = r11.y SIZE.w; r2.xy = clamp( r2.xy , 0.001 , 0.999 ); r11.xy = r2.xy; r11.y = 1.0 - r11.y; r5 = texture2D(Tex, r11.xy); r5.x = 2.0 r5.x - 1.0; r5.y = 2.0(255.0 r5.z + r5.y)/255.0 - 1.0; r5.zw = vec2(0.0,0.0); r11.x = r0.x + 0.0; r2.x = r11.x SIZE.z; r11.y = r0.y - 1.0; r2.y = r11.y SIZE.w; r2.xy = clamp( r2.xy , 0.001 , 0.999 ); r11.xy = r2.xy; r11.y = 1.0 - r11.y; r6 = texture2D(Tex, r11.xy); r6.x = 2.0 r6.x - 1.0; r6.y = 2.0(255.0 r6.z + r6.y)/255.0 - 1.0; r6.zw = vec2(0.0,0.0); r2 = gl_TexCoord[0]; r11.xy = r2.xy; r11.y = 1.0 - r11.y; r7 = texture2D(Prev, r11.xy); r7.x = 2.0 r7.x - 1.0; r7.y = 2.0(255.0 r7.z + r7.y)/255.0 - 1.0; r7.zw = vec2(0.0,0.0); r11.xy = r2.xy; r11.y = 1.0 - r11.y; r8 = texture2D(Tex, r11.xy); r8.x = 2.0 r8.x - 1.0; r8.y = 2.0(255.0 r8.z + r8.y)/255.0 - 1.0; r8.zw = vec2(0.0,0.0); r13.x = r3.y; r13.x = r13.x + r4.y; r13.x = r13.x + r5.y; r13.x = r13.x + r6.y; r12.x = 0.25 r13.x; r11.y = r12.x + r8.y; r9.y = 0.5 r11.y; r12.x = r3.x; r12.x = r12.x + r4.x; r12.x = r12.x + r5.x; r12.x = r12.x + r6.x; r11.x = 0.5 r12.x; r9.z = r11.x - r7.x; r9.z = r9.z PRM.x; if (r1.y<r8.y) { r9.z = r9.z 0.5; } r8.z = abs( r9.z ); r11.x = r8.y - r1.y; r8.x = abs( r11.x ); if ((r8.z<PRM.y)&&(r8.x<PRM.y)) { r8.y = r9.y; r12.x = 0.001 + r9.z; r11.x = PRM.z r12.x; r8.y = r8.y - r11.x; } r10.x = 0.5 + 0.5 (r9.z); r10.w = 0.5 + 0.5 (r8.y); r10.y = fract( 255.0 r10.w ); r10.z = floor( 255.0 * r10.w ) / 255.0; r10.w = 1.0; gl_FragColor = r10; }
The 1st fragment calculate diffusion of amount of water meanwhile 2nd calculate waves diff propagation. The output .x component deserves the waves of a water surface, and the .y is relative to height amount of the water. I repeat myself that on all GL platforms it works fine neither but on OpenVR SDK, that .x gives insignifiant result (flat).
I have tested my shader on OpenGL on Mac OS Intel, and MaxOS Window Desktop with SDL2, and on API OpenVR, it seems to clamp arbitrary some values in fragment shader. Is there something wrong with OpenVR implementation of OpenGL ? For exemple I know that GL ES use different precision. Something ?