Convert Shadertoy Shader to glsl webgl

254 views Asked by At

I need to convert this shadertoy shader to glsl , besically it turn-off the texture anti-aliasing, it is manual nearest neighbor filter

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = fragCoord/iResolution.xy;

    ivec2 sz = textureSize(iChannel0, 0);
    uv = (vec2(0.5) + vec2(ivec2(uv * vec2(sz)))) / vec2(sz);
    vec3 col = texture(iChannel0, uv).rgb;

    // Output to screen
    fragColor = vec4(col,1.0);
}

I know void mainImage( out vec4 fragColor, in vec2 fragCoord ) becomes void main( )

and fragCoord becomes gl_FragCoord and fragColor becomes gl_FragColor

I also mentioned uniform sampler2D media; so texture(iChannel0, uv).rgb; becomes texture2D(media, uv).rgb;

But how i convert these 2 lines to glsl

 ivec2 sz = textureSize(iChannel0, 0);
 uv = (vec2(0.5) + vec2(ivec2(uv * vec2(sz)))) / vec2(sz);

i mean what is ivec2 and textureSize is in glsl and how i can convert this ivec2 sz = textureSize(iChannel0, 0); to glsl ?

1

There are 1 answers

0
movAX13h On

You can achieve the same by changing the texture parameter TEXTURE_MIN_FILTER to NEAREST.

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);

And optionally add

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);

Find more info here: https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texParameter