一种分隔屏幕显示效果

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/asd77882566/article/details/78084125

原shader地址:http://glslsandbox.com/e#40822.0

个人实现效果:

const float lineScale = 40.0;

float GetColor(vec2 pos)
{
    float radius = atan(pos.x, pos.y);
    float num = abs(pos.x) + abs(pos.y);
    //float num = length(pos);
    float curLine = floor(num * lineScale);
    float speed = sin(curLine * 24.3);
    float offset = fract(sin(speed));

    float c = step(.4, tan(radius + offset + speed * iTime ));

    float rnd = offset;
    return c * rnd;
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;

    fragColor = vec4(GetColor(uv ), GetColor(uv - 0.003), GetColor(uv),1.0);
}

其中

float num = abs(pos.x) + abs(pos.y);
    //float num = length(pos);
float curLine = floor(num * lineScale);

是屏幕分隔算法,将屏幕分割成倾斜的方框,分隔效果如图示:

这里写图片描述

length(pos)将屏幕分割成圆环。

float c = step(.4, tan(radius + offset + speed * iTime ));

控制当前环中显示颜色的地方。

猜你喜欢

转载自blog.csdn.net/asd77882566/article/details/78084125