Skip to content

Instantly share code, notes, and snippets.

@ahmetilgin
Last active August 10, 2020 18:44
Show Gist options
  • Save ahmetilgin/68ed21fa3a3fd84fb872ee634e03ce5d to your computer and use it in GitHub Desktop.
Save ahmetilgin/68ed21fa3a3fd84fb872ee634e03ce5d to your computer and use it in GitHub Desktop.
shader_type canvas_item;
void fragment() {
vec2 iRes = (1.0/ SCREEN_PIXEL_SIZE);
float offset = (TIME- floor(TIME))/TIME;
float CurrentTime = (TIME)*(offset);
vec3 WaveParams = vec3(.5, 0.1, 0.1);
float ratio = iRes.y/iRes.x;
//Use this if you want to place the centre with the mouse instead
//vec2 WaveCentre = vec2( vec2(500.0, 500.0) / iRes );
vec2 WaveCentre = vec2(0.5, 0.5);
WaveCentre.y *= ratio;
vec4 texCor = FRAGCOORD / vec4(iRes.x,iRes.y,0,0);
vec2 texCoord = vec2(texCor.x,texCor.y);
texCoord.y *= ratio;
float Dist = distance(vec2(texCoord.x,texCoord.y), WaveCentre);
vec4 Color = texture(TEXTURE, vec2(texCoord.x,texCoord.y));
//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 = (5.0 - pow(abs(Diff * WaveParams.x), WaveParams.y));
float DiffTime = (Diff * ScaleDiff);
//The direction of the distortion
vec2 DiffTexCoord = normalize(vec2(texCoord.x,texCoord.y) - WaveCentre);
//Perform the distortion and reduce the effect over time
texCoord += ((DiffTexCoord * DiffTime) / (CurrentTime * Dist * 5.0));
Color = texture(TEXTURE, texCoord);
//Blow out the color and reduce the effect over time
Color += (Color * ScaleDiff) / (CurrentTime * Dist * 5.0);
}
COLOR = Color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment