Mindustry/core/assets/shaders/shield.fragment

73 lines
1.8 KiB
Plaintext

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define MAX_HITS 64
#define HIT_RADIUS 12.0
uniform sampler2D u_texture;
uniform vec4 u_color;
uniform vec2 u_texsize;
uniform float u_time;
uniform float u_scaling;
uniform vec2 u_offset;
uniform int u_hitamount;
uniform vec3 u_hits[MAX_HITS];
varying vec4 v_color;
varying vec2 v_texCoord;
void main() {
vec2 T = v_texCoord.xy;
vec2 coords = (T * u_texsize) + u_offset;
T += vec2(sin(coords.y / 3.0 + u_time / 20.0) / 250.0, sin(coords.x / 3.0 + u_time / 20.0) / 250.0) * u_scaling;
float si = 1.0 + sin(u_time / 20.0 /*+ (coords.x + coords.y) / 30.0*/) / 8.0;
vec4 color = texture2D(u_texture, T) * vec4(si, si, si, 1.0);
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
bool any = false;
float thickness = 1.0;
float step = 1.5;
if(texture2D(u_texture, T).a < 0.1 &&
(texture2D(u_texture, T + vec2(0, step) * v).a > 0.1 || texture2D(u_texture, T + vec2(0, -step) * v).a > 0.1 ||
texture2D(u_texture, T + vec2(step, 0) * v).a > 0.1 || texture2D(u_texture, T + vec2(-step, 0) * v).a > 0.1))
any = true;
if(any){
gl_FragColor = u_color * vec4(si, si, si, 1.0);
}else{
//coords.x = float(int(coords.x));
if(color.a > 0.1){
if(mod(coords.x + coords.y + sin(coords.x / 5.0) * 3.0 + sin(coords.y / 5.0) * 3.0 + u_time / 4.0, 10.0) < 2.0){
color *= 1.65;
}
color.a = 0.18;
for(int i = 0; i < u_hitamount; i ++){
vec3 hit = u_hits[i];
float rad = hit.z * HIT_RADIUS;
float fract = 1.0 - hit.z;
if(abs(distance(vec2(hit.x, hit.y), coords - u_texsize/2.0) - rad) < 1.0){
color = mix(color, u_color* vec4(si, si, si, 1.0), (1.0 * fract));
color.a = 0.18 + 0.82 *fract;
}
}
}
gl_FragColor = color;
}
}