美文网首页
缩放滤镜

缩放滤镜

作者: E术家 | 来源:发表于2020-08-14 20:39 被阅读0次

    抖动效果

    uniform float Time;
    
    void main (void) {
        float duration = 0.7;
        float maxScale = 1.1;
        float offset = 0.02;
        
        float progress = mod(Time, duration) / duration; // 0~1
        vec2 offsetCoords = vec2(offset, offset) * progress;
        float scale = 1.0 + (maxScale - 1.0) * progress;
        
        vec2 ScaleTextureCoords = vec2(0.5, 0.5) + (TextureCoordsVarying - vec2(0.5, 0.5)) / scale;
        
        vec4 maskR = texture2D(Texture, ScaleTextureCoords + offsetCoords);
        vec4 maskB = texture2D(Texture, ScaleTextureCoords - offsetCoords);
        vec4 mask = texture2D(Texture, ScaleTextureCoords);
        
        gl_FragColor = vec4(maskR.r, mask.g, maskB.b, mask.a);
    }
    

    灵魂出窍效果

    precision highp float;
    
    uniform sampler2D Texture;
    varying vec2 TextureCoordsVarying;
    
    uniform float Time;
    
    void main (void) {
        float duration = 0.7;
        float maxAlpha = 0.4;
        float maxScale = 1.8;
        
        float progress = mod(Time, duration) / duration; // 0~1
        float alpha = maxAlpha * (1.0 - progress);
        float scale = 1.0 + (maxScale - 1.0) * progress;
        
        float weakX = 0.5 + (TextureCoordsVarying.x - 0.5) / scale;
        float weakY = 0.5 + (TextureCoordsVarying.y - 0.5) / scale;
        vec2 weakTextureCoords = vec2(weakX, weakY);
        
        vec4 weakMask = texture2D(Texture, weakTextureCoords);
        
        vec4 mask = texture2D(Texture, TextureCoordsVarying);
        
        gl_FragColor = mask * (1.0 - alpha) + weakMask * alpha;
    }
    

    毛刺效果

    precision highp float;
    
    uniform sampler2D Texture;
    varying vec2 TextureCoordsVarying;
    
    uniform float Time;
    
    const float PI = 3.1415926;
    
    float rand(float n) {
        return fract(sin(n) * 43758.5453123);
    }
    
    void main (void) {
        float maxJitter = 0.06;
        float duration = 0.3;
        float colorROffset = 0.01;
        float colorBOffset = -0.025;
        
        float time = mod(Time, duration * 2.0);
        float amplitude = max(sin(time * (PI / duration)), 0.0);
        
        float jitter = rand(TextureCoordsVarying.y) * 2.0 - 1.0; // -1~1
        bool needOffset = abs(jitter) < maxJitter * amplitude;
        
        float textureX = TextureCoordsVarying.x + (needOffset ? jitter : (jitter * amplitude * 0.006));
        vec2 textureCoords = vec2(textureX, TextureCoordsVarying.y);
        
        vec4 mask = texture2D(Texture, textureCoords);
        vec4 maskR = texture2D(Texture, textureCoords + vec2(colorROffset * amplitude, 0.0));
        vec4 maskB = texture2D(Texture, textureCoords + vec2(colorBOffset * amplitude, 0.0));
        
        gl_FragColor = vec4(maskR.r, mask.g, maskB.b, mask.a);
    }
    

    相关文章

      网友评论

          本文标题:缩放滤镜

          本文链接:https://www.haomeiwen.com/subject/qpundktx.html