GLSL to Metal. Tile

213 Views Asked by At

I'm trying to make tile effect from example on shadertoy (https://www.shadertoy.com/view/3llcRN) . Here is code on GLSL:

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = (2.*fragCoord.xy - iResolution.xy)/iResolution.y;    
    fragColor = vec4( texture(iChannel0, uv ).rgba );
}

Result: enter image description here

Here is my code on Metal:

kernel vec4 colorKernel(sampler source, float w, float h)
{
    vec2 d = vec2(w, h);
    vec2 uv = (2.*destCoord().xy - d.xy)/h;
    return vec4( sample(source, uv).rgba );
}

And result:

enter image description here

What is missing? I need same result as on shadertoy

1

There are 1 best solutions below

0
On

The problem is that when UV's coordinates bigger than 1 it returns just empty color