Optimizations

This commit is contained in:
Anuken
2018-07-11 12:19:21 -04:00
parent bce0101278
commit 2b58bd5bd8
11 changed files with 21 additions and 91 deletions
+9 -22
View File
@@ -3,6 +3,8 @@ precision mediump float;
precision mediump int;
#endif
#define SPACE 1.0
uniform sampler2D u_texture;
uniform vec4 u_color;
@@ -11,30 +13,15 @@ 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;
vec4 c = texture2D(u_texture, v_texCoord.xy);
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;
}
gl_FragColor = mix(c * v_color, u_color,
(1.0-step(0.1, texture2D(u_texture, v_texCoord.xy).a)) *
step(0.1, texture2D(u_texture, v_texCoord.xy + vec2(0, SPACE) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, -SPACE) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, 0) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-SPACE, 0) * v).a));
}