GLSL shader example

Localized Swirl Distortion

Rotation angle falls to zero with radius so the outer image remains fixed rather than rotating as a whole.

Live example

Edit the code and the preview updates as you type.

What to observe

Localized Swirl Distortion.

Mechanism

Rotation angle falls to zero with radius so the outer image remains fixed rather than rotating as a whole.

The controlling code

float r=length(p),a=(1.-smoothstep(0.,.9,r))*u_parameter*8.;vec2 q=rot(a)*p;c=texture2D(u_texture,q*.5+.5).rgb;

Experiment

Set u_parameter to 0 and then 1, taking the rotation multiplier from zero to eight radians before falloff. The center twists strongly while points outside radius 0.9 receive no rotation.

Debugging and cost

Only one texture lookup follows the rotated coordinate q. Change the falloff endpoint .9 in smoothstep(0.,.9,r) to .5 to confine the twist to a smaller disk without changing sample count.

Built-in functions used

Learn it step by step