Skip to content

Instantly share code, notes, and snippets.

@alijaya
Created November 21, 2017 17:34
Show Gist options
  • Select an option

  • Save alijaya/b6530b4a82b6e264b661e92665faeb49 to your computer and use it in GitHub Desktop.

Select an option

Save alijaya/b6530b4a82b6e264b661e92665faeb49 to your computer and use it in GitHub Desktop.

Revisions

  1. alijaya created this gist Nov 21, 2017.
    25 changes: 25 additions & 0 deletions linearwave.glsl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #define TAU 6.2831853072

    uniform vec2 origin = vec2(0.0, 0.0);
    uniform float direction = 0.0;
    uniform float amplitude = 10.0;
    uniform float length = 10.0;
    uniform float evolution = 0.0;

    vec2 distanceDirection(vec2 pos) {
    float angle = direction * TAU;
    vec2 normal = vec2(cos(angle), sin(angle));
    vec2 relative = pos - origin;
    return vec2(dot(normal, relative), angle + TAU / 4);
    }

    vec2 generateShift(vec2 pos) {
    vec2 dd = distanceDirection(pos);
    float shift = amplitude * sin(dd.x / length - evolution * TAU);
    return vec2(shift * cos(dd.y), shift * sin(dd.y));
    }

    void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
    vec2 shift = generateShift(fragCoord.xy / iRenderScale) * iRenderScale;
    fragColor = texture2D( iChannel0, (fragCoord.xy + shift) / iResolution.xy);
    }
    24 changes: 24 additions & 0 deletions radialwave.glsl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #define TAU 6.2831853072

    uniform vec2 origin = vec2(0.0, 0.0);
    uniform float amplitude = 10.0;
    uniform float length = 10.0;
    uniform float evolution = 0.0;

    vec2 distanceDirection(vec2 pos) {
    vec2 relative = pos - origin;
    float distance = length(relative);
    float angle = atan(relative.y, relative.x);
    return vec2(distance, angle + TAU / 4);
    }

    vec2 generateShift(vec2 pos) {
    vec2 dd = distanceDirection(pos);
    float shift = amplitude * sin(dd.x / length - evolution * TAU);
    return vec2(shift * cos(dd.y), shift * sin(dd.y));
    }

    void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
    vec2 shift = generateShift(fragCoord.xy / iRenderScale) * iRenderScale;
    fragColor = texture2D( iChannel0, (fragCoord.xy + shift) / iResolution.xy);
    }