Mindustry/core/assets/shaders/shadow.fragment

36 lines
795 B
Plaintext
Raw Normal View History

2019-01-28 11:26:07 +07:00
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define SPACE 0.75
#define RADIUS 5.0
2019-01-28 11:26:07 +07:00
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(cx*cx + cy*cy <= RADIUS * RADIUS && texture2D(u_texture, v_texCoord.xy + vec2(cx, cy) * v * spacing).a >= 0.001){
gl_FragColor = u_color;
}
}
}
}
2019-01-28 11:26:07 +07:00
}