2

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 ?

3

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.