patriciogonzalezvivo/glslCanvas

Difference in handling textures in glslCanvas and glslViewer

edap opened this issue · 3 comments

edap commented

I have the same exact code that gives me two different results on glslCanvas and glslViewer.

vec2 origSt = (2.0 * gl_FragCoord.xy - u_resolution.xy)/ u_resolution.y;
vec4 texZoom = vec4(texture2D(u_tex0, origSt + vec2(0.5)));
gl_FragColor = texZoom;

This is the result using glslViewer:
Screen Shot 2019-12-04 at 15 03 51

And this is the result on glslCanvas:
Screen Shot 2019-12-04 at 15 05 18

Can it be that gl.REPEAT is different between the two?

edap commented

So, basically glslViewer is loading the texture using GL_REPEAT, see https://github.com/patriciogonzalezvivo/glslViewer/blob/16b17f524680f0f50702fc9bb1e61a981386cbbf/src/gl/texture.cpp#L37

While in glslCanvas gl.REPEAT is set just if it is passes through options.

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, options.TEXTURE_WRAP_S || options.repeat && gl.REPEAT || gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, options.TEXTURE_WRAP_T || options.repeat && gl.REPEAT || gl.CLAMP_TO_EDGE);

via https://rawgit.com/patriciogonzalezvivo/glslCanvas/master/dist/GlslCanvas.js

Is there some documentation about how to pass that option? I am hardcoding it at the moment and it works.

Hi! so a quick hack for this is to force the repeat using fract()
So could look like this:

vec4 texZoom = vec4(texture2D(u_tex0, fract(origSt + vec2(0.5))));
edap commented

I have simply hardcoded:
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
As this is the behaviour in glslViewer.

I wanted to port a sketch done in glslViewer on glslCanvas.Last time that I did it it went smoothly, this time I have some issues, but I am figuring them out.
Many thanks for your tools ;)