抄来的一个高斯模糊

2022-10-16  本文已影响0人  大旺旺的弟弟小旺旺

抄来的高斯模糊效果不错

vec3 draw(vec2 uv) {
    return texture(iChannel0,vec2(uv.x,1.-uv.y)).rgb;   
    //return texture(iChannel0,uv).rgb;  
}

float grid(float var, float size) {
    return floor(var*size)/size;
}

float rand(vec2 co){
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    float time = iTime;
    vec2 uv = (fragCoord.xy / iResolution.xy);
    
    float bluramount = 0.04;
    if (iMouse.w >= 1.) {
    bluramount = (iMouse.x/iResolution.x)/10.;
    }

    //float dists = 5.;
    vec3 blurred_image = vec3(0.);
    #define repeats 20.
    for (float i = 0.; i < repeats; i++) { 
        //Older:
        //vec2 q = vec2(cos(degrees((grid(i,dists)/repeats)*360.)),sin(degrees((grid(i,dists)/repeats)*360.))) * (1./(1.+mod(i,dists)));
        vec2 q = vec2(cos(degrees((i/repeats)*360.)),sin(degrees((i/repeats)*360.))) *  (rand(vec2(i,uv.x+uv.y))+bluramount); 
        vec2 uv2 = uv+(q*bluramount);
        blurred_image += draw(uv2)/2.;
        //One more to hide the noise.
        q = vec2(cos(degrees((i/repeats)*360.)),sin(degrees((i/repeats)*360.))) *  (rand(vec2(i+2.,uv.x+uv.y+24.))+bluramount); 
        uv2 = uv+(q*bluramount);
        blurred_image += draw(uv2)/2.;
    }
    blurred_image /= repeats;
        
    fragColor = vec4(blurred_image,1.0);
}
image.png
上一篇 下一篇

猜你喜欢

热点阅读