Mindustry/core/assets/shaders/outline.fragment

37 lines
785 B
Plaintext

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define SPACE 1.0
#define RADIUS 3.0
uniform sampler2D u_texture;
uniform vec4 u_color;
uniform vec2 u_texsize;
uniform float u_scl;
varying vec4 v_color;
varying vec2 v_texCoord;
void main() {
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
vec4 c = texture2D(u_texture, v_texCoord.xy);
float spacing = SPACE * u_scl;
if(c.a >= 0.001){
gl_FragColor = c * v_color;
}else{
for(float cx = -RADIUS; cx <= RADIUS; cx ++){
for(float cy = -RADIUS; cy <= RADIUS; cy ++){
if(texture2D(u_texture, v_texCoord.xy + vec2(cx, cy) * v * spacing).a >= 0.001){
gl_FragColor = u_color;
break;
}
}
}
}
}