From 8f4258b11900640199cf0f156b4916b0e3acd39a Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 26 Feb 2019 16:02:06 -0500 Subject: [PATCH] Build shader swap --- core/assets/shaders/unitbuild.fragment | 27 +++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/core/assets/shaders/unitbuild.fragment b/core/assets/shaders/unitbuild.fragment index 1faf952c8d..35a956c35a 100644 --- a/core/assets/shaders/unitbuild.fragment +++ b/core/assets/shaders/unitbuild.fragment @@ -3,6 +3,8 @@ precision mediump float; precision mediump int; #endif +#define step 3.0 + uniform sampler2D u_texture; uniform float u_time; @@ -15,19 +17,22 @@ uniform vec2 u_texsize; varying vec4 v_color; varying vec2 v_texCoord; -#define SPACE 1.3 -#define RADIUS 2.0 +bool id(vec4 v){ + return v.a > 0.1; +} -bool cont(vec2 t, vec2 v){ +bool id(vec2 coords, vec4 base){ + vec4 target = texture2D(u_texture, coords); + return target.a < 0.1 || (coords.x < u_uv.x || coords.y < u_uv.y || coords.x > u_uv2.x || coords.y > u_uv2.y); +} - 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 * SPACE).a <= 0.001){ - return true; - } - } - } - return false; +bool cont(vec2 T, vec2 v){ + vec4 base = texture2D(u_texture, T); + return base.a > 0.1 && + (id(T + vec2(0, step) * v, base) || id(T + vec2(0, -step) * v, base) || + id(T + vec2(step, 0) * v, base) || id(T + vec2(-step, 0) * v, base) || + id(T + vec2(step, step) * v, base) || id(T + vec2(-step, -step) * v, base) || + id(T + vec2(step, -step) * v, base) || id(T + vec2(-step, step) * v, base)); } void main() {