Mindustry/core/assets/shaders/outline.fragment

45 lines
1.6 KiB
Plaintext
Raw Normal View History

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
2018-11-17 09:33:10 +07:00
#define SPACE 2.0
2018-07-11 23:19:21 +07:00
uniform sampler2D u_texture;
uniform vec4 u_color;
uniform vec2 u_texsize;
2018-12-30 01:06:17 +07:00
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);
2018-07-11 23:19:21 +07:00
vec4 c = texture2D(u_texture, v_texCoord.xy);
2018-12-30 01:06:17 +07:00
float spacing = SPACE * u_scl;
2018-07-11 23:19:21 +07:00
gl_FragColor = mix(c * v_color, u_color,
(1.0-step(0.1, texture2D(u_texture, v_texCoord.xy).a)) *
2018-11-17 09:33:10 +07:00
step(0.1,
//cardinals
2018-12-30 01:06:17 +07:00
texture2D(u_texture, v_texCoord.xy + vec2(0, spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, -spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(spacing, 0) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, 0) * v).a +
2018-11-17 09:33:10 +07:00
//cardinal edges
2018-12-30 01:06:17 +07:00
texture2D(u_texture, v_texCoord.xy + vec2(spacing, spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(spacing, -spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, -spacing) * v).a +
2018-11-17 09:33:10 +07:00
//cardinals * 2
2018-12-30 01:06:17 +07:00
texture2D(u_texture, v_texCoord.xy + vec2(0, spacing) * v*2.0).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, -spacing) * v*2.0).a +
texture2D(u_texture, v_texCoord.xy + vec2(spacing, 0) * v*2.0).a +
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, 0) * v*2.0).a
2018-11-17 09:33:10 +07:00
));
}