Week 5 – Dysmorphic Mosaic

screen-shot-2021-03-17-at-12-35-43-am screen-shot-2021-03-17-at-12-36-23-am


#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D tex0;
uniform vec2 uResolution;
uniform float uTime;
uniform float uDisplacement;
uniform vec2 uMousePosition;

varying vec2 vTexCoord;

float amt = -0.05; // the amount of displacement
float squares = 40.0; // the number of squares to render vertically

void main() {

float aspect = uResolution.x / uResolution.y;
float offset = amt * 0.5;

vec2 uv = vTexCoord;

// the texture is loaded upside down and backwards by default so lets flip it
uv.y = 1.0 - uv.y;

// copy of the texture coords
vec2 tc = uv;

// move into a range of -0.5 - 0.5
uv -= 0.5;

// correct for window aspect to make squares
uv.x *= aspect;

// tile will be used to offset the texture coordinates
vec2 tile = fract(uv * squares + 0.5) * (tan(amt));

// sample the texture using our computed tile
// offset will remove some texcoord edge artifacting
vec4 tex = texture2D(tex0, vec2(fract(tc*uDisplacement) + fract(tile*uDisplacement-uTime*0.1) - offset));

// render the output
gl_FragColor = tex;

}

Leave a Reply