ODOShader

ODOS丨NeonGlitch

by ERIN.Z, 2022-02-25


Snipaste_2022-02-25_13-11-57.png mentor说下周要给霓虹灯写一个shader,去看了一下毛老师关于GlitchPostPocessing的文章,说白了其实就是个随机函数嘛。 lovedeathrobot 这咱熟,整上:

float hash21(vec2 p){
    return fract(sin(dot(p ,vec2(12.9898,78.233))) * 43758.5453);
}
float glitch(vec2 p){
    float time = fract(iTime*.5);//2s loop
    time = floor(time*30.)/30.;//min interval
    float t=hash21(p+time)*2.;
    float k = 16.;
    float threshold = max(2.*k*time*exp(1.0-k*time),1.-(time+hash21(p)*.2));//expImpulse
    t *= threshold;
    return t;
    return t<threshold? t:0.;
}

灭灯之前会先额外亮一下,所以用到了这个指数脉冲函数: expImpulse 今天突然登录不上shadertoy,只好录vscode了: expImpulse 频闪的效果就是直接用index+time获取以随机数,与threshold混合: neon glitch 今天这个shader超简单,就暂时不传shadertoy了,main函数代码如下——

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = (2.0*fragCoord-iResolution.xy)/iResolution.y;
    float scale = 2.;
    vec2 i = floor(uv*scale);
    vec2 f = fract(uv*scale);
    float m = 1. - S(abs(length(f-.5)-.3),.08);//ring
    m = clamp(m+.5*smoothstep(.2,.1,abs(length(f-.5)-.3)),0.,1.);//bloom
    float t = glitch(i);
    //BackGround
    vec3 col = mix(vec3(.9,0.35,.8),vec3(0.17,0.8,0.87),hash21(i))*m*t;//random neon
    col += logo(uv);
    fragColor = vec4(col,1.0);
}

下班!

by ERIN.Z

2024 © typecho & elise