#define PI 3.14159265359 //常数pi
#define SAMPLES 32 //采样次数
#define WIDTH 0.8 //描边宽度
#define COLOR vec4(0.0,0.0,1.0,1.0) //描边颜色
#define NUM_FRAMES 6.0 //使用的纹理是一个序列帧,这里指定帧的个数为6
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 v_texCoord = fragCoord.xy / iResolution.xy; //根据分辨率和屏幕坐标计算uv值
//iChannelResolution[0].xy是纹理的大小 减去15是去掉纹理的外边缘空白
vec2 u_textureRes = iChannelResolution[0].xy - vec2(15.0,0.0);
float frame = floor(mod(iTime*10.0, NUM_FRAMES));
float frameWidth = u_textureRes.x / NUM_FRAMES;
float catUVWidth = u_textureRes.x / iChannelResolution[0].x;
vec4 u_textureBoundsUV = vec4(catUVWidth/NUM_FRAMES * frame, 0.0, catUVWidth/6.0 * (frame+1.0), 1.0);
vec2 catScale = vec2(0.10);
vec2 catPos = vec2(0.0-(frameWidth-2.5)*frame,0.0) + vec2(10.0,0.0);
vec2 catUV = clamp((fragCoord*catScale-catPos) / u_textureRes, u_textureBoundsUV.xy, u_textureBoundsUV.zw );
//OUTLINE
float outlineAlpha = 0.0;
float angle = 0.0;
for( int i=0; i<SAMPLES; i++ ){
angle += 1.0/(float(SAMPLES)/2.0) * PI;
vec2 testPoint = vec2( (WIDTH/u_textureRes.x)*cos(angle), (WIDTH/u_textureRes.y)*sin(angle) );
testPoint = clamp( catUV + testPoint, u_textureBoundsUV.xy, u_textureBoundsUV.zw );
float sampledAlpha = texture( iChannel0, testPoint ).a;
outlineAlpha = max( outlineAlpha, sampledAlpha );
}
fragColor = mix( vec4(0.0), COLOR, outlineAlpha );
//TEXTURE
vec4 tex0 = texture( iChannel0, catUV );
fragColor = mix( fragColor, tex0, tex0.a );
}
网友评论