Skip to content

Instantly share code, notes, and snippets.

@Gorillarigo
Last active October 17, 2017 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gorillarigo/25a6e7773bdc3fed81f9a4495dda7d65 to your computer and use it in GitHub Desktop.
Save Gorillarigo/25a6e7773bdc3fed81f9a4495dda7d65 to your computer and use it in GitHub Desktop.
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
//Sawtooth function to pulse from centre.
float offset = (iTime- floor(iTime))/iTime;
float CurrentTime = (iTime)*(offset);
vec3 WaveParams = vec3(10.0, 0.8, 0.1 );
float ratio = iResolution.y/iResolution.x;
//Use this if you want to place the centre with the mouse instead
vec2 WaveCentre = vec2( iMouse.xy / iResolution.xy );
//vec2 WaveCentre = vec2(0.5, 0.5);
WaveCentre.y *= ratio;
vec2 texCoord = fragCoord.xy / iResolution.xy;
texCoord.y *= ratio;
float Dist = distance(texCoord, WaveCentre);
vec4 Color = texture(iChannel0, texCoord);
//Only distort the pixels within the parameter distance from the centre
if ((Dist <= ((CurrentTime) + (WaveParams.z))) &&
(Dist >= ((CurrentTime) - (WaveParams.z))))
{
//The pixel offset distance based on the input parameters
float Diff = (Dist - CurrentTime);
float ScaleDiff = (1.0 - pow(abs(Diff * WaveParams.x), WaveParams.y));
float DiffTime = (Diff * ScaleDiff);
//The direction of the distortion
vec2 DiffTexCoord = normalize(texCoord - WaveCentre);
//Perform the distortion and reduce the effect over time
texCoord += ((DiffTexCoord * DiffTime) / (CurrentTime * Dist * 40.0));
Color = texture(iChannel0, texCoord);
//Blow out the color and reduce the effect over time
Color += (Color * ScaleDiff) / (CurrentTime * Dist * 40.0);
}
fragColor = Color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment