Mindustry/core/assets/shaders/outline.fragment
2018-03-15 21:42:23 -04:00

41 lines
747 B
Plaintext

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D u_texture;
uniform vec4 u_color;
uniform vec2 u_texsize;
varying vec4 v_color;
varying vec2 v_texCoord;
bool id(vec4 v){
return v.a > 0.1;
}
void main() {
vec2 T = v_texCoord.xy;
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
bool any = false;
float step = 1.0;
vec4 c = texture2D(u_texture, T);
if(texture2D(u_texture, T).a < 0.1 &&
(id(texture2D(u_texture, T + vec2(0, step) * v)) || id(texture2D(u_texture, T + vec2(0, -step) * v)) ||
id(texture2D(u_texture, T + vec2(step, 0) * v)) || id(texture2D(u_texture, T + vec2(-step, 0) * v))))
any = true;
if(any){
gl_FragColor = u_color;
}else{
gl_FragColor = c * v_color;
}
}