I would like to create a shader that just messes with the screen. The problem is, I only know how to move individual pixels from the vertex shader. How might I stretch them?
Deformation is just mapping coordinates with a function other than [icode](x1, y1) = (x0, y0)[/icode]
Throw this into ShaderToy with some texture loaded in iChannel0:
void main(void)
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
float distFromCenter = distance(uv, vec2(.5));
uv *= (sin(iGlobalTime) / 2. + 1.) * distFromCenter;
gl_FragColor = texture2D(iChannel0, uv);
}
Edit: Another, more “stretchy” example: (adds to UV instead of multiply)
void main(void)
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
uv += distance(uv, vec2(.5)) * (sin(iGlobalTime)/4.+.25);
gl_FragColor = texture2D(iChannel0, uv);
}
If you use the techniques described here to get the coordinates of the screen, then you can just warp the texture coordinates accordingly.
You got me playing with shadertoy again, but I got one that mimics 3D camera movement:
void main(void)
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
uv += (sin(iGlobalTime)/2.+.5) * dot(uv, vec2(.5));
gl_FragColor = texture2D(iChannel0, uv);
}
Neat.
Change the multiply to a divide and see what happens.
Just mess around until you find something you like.