Adapt / refactor shader uniforms and attributes

This commit is contained in:
Gustl22
2019-05-16 08:19:09 +02:00
parent 30ae0fb48f
commit a6ce05034a
9 changed files with 29 additions and 29 deletions

View File

@@ -26,7 +26,7 @@ $$
#ifdef GLES #ifdef GLES
precision highp float; precision highp float;
#endif #endif
uniform sampler2D tex; uniform sampler2D u_tex;
uniform float u_fade; uniform float u_fade;
uniform int u_mode; uniform int u_mode;
uniform vec4 u_color; uniform vec4 u_color;
@@ -39,7 +39,7 @@ void main() {
#ifdef DESKTOP_QUIRKS #ifdef DESKTOP_QUIRKS
len = length(v_st); len = length(v_st);
#else #else
len = texture2D(tex, v_st).a; len = texture2D(u_tex, v_st).a;
#endif #endif
} else { } else {
// flat cap line // flat cap line

View File

@@ -29,7 +29,7 @@ $$
#ifdef GLES #ifdef GLES
precision highp float; precision highp float;
#endif #endif
uniform sampler2D tex; uniform sampler2D u_tex;
uniform int u_mode; uniform int u_mode;
uniform vec4 u_color; uniform vec4 u_color;
uniform float u_fade; uniform float u_fade;
@@ -43,7 +43,7 @@ void main() {
#ifdef DESKTOP_QUIRKS #ifdef DESKTOP_QUIRKS
len = length(v_st); len = length(v_st);
#else #else
len = texture2D(tex, v_st).a; len = texture2D(u_tex, v_st).a;
#endif #endif
vec2 st_width = fwidth(v_st); vec2 st_width = fwidth(v_st);
fuzz = max(st_width.s, st_width.t); fuzz = max(st_width.s, st_width.t);

View File

@@ -38,7 +38,7 @@ uniform vec4 u_color;
uniform vec4 u_bgcolor; uniform vec4 u_bgcolor;
uniform float u_pwidth; uniform float u_pwidth;
varying vec2 v_st; varying vec2 v_st;
uniform sampler2D tex; uniform sampler2D u_tex;
uniform int u_mode; uniform int u_mode;
void main() { void main() {
@@ -50,7 +50,7 @@ void main() {
} }
// use lineLength mod texture step (mod is always positive) // use lineLength mod texture step (mod is always positive)
// add 1.0 to avoid static line textures while zooming // add 1.0 to avoid static line textures while zooming
vec4 c = texture2D(tex, vec2(mod(v_st.s + 1.0, step), (v_st.t + 1.0) * 0.5)); vec4 c = texture2D(u_tex, vec2(mod(v_st.s + 1.0, step), (v_st.t + 1.0) * 0.5));
float fuzz = fwidth(c.a); float fuzz = fwidth(c.a);
gl_FragColor = (c * u_color) * smoothstep(0.5 - fuzz, 0.5 + fuzz, c.a); gl_FragColor = (c * u_color) * smoothstep(0.5 - fuzz, 0.5 + fuzz, c.a);
} else { } else {

View File

@@ -19,11 +19,11 @@ $$
precision highp float; precision highp float;
#endif #endif
uniform vec4 u_color; uniform vec4 u_color;
uniform sampler2D tex; uniform sampler2D u_tex;
uniform vec2 u_scale; uniform vec2 u_scale;
varying vec2 v_st; varying vec2 v_st;
varying vec2 v_st2; varying vec2 v_st2;
void main() { void main() {
gl_FragColor = mix(texture2D(tex, v_st), texture2D(tex, v_st2), u_scale.x); gl_FragColor = mix(texture2D(u_tex, v_st), texture2D(u_tex, v_st2), u_scale.x);
} }

View File

@@ -19,11 +19,11 @@ $$
precision highp float; precision highp float;
#endif #endif
uniform vec4 u_color; uniform vec4 u_color;
uniform sampler2D tex; uniform sampler2D u_tex;
uniform vec2 u_scale; uniform vec2 u_scale;
varying vec2 v_st; varying vec2 v_st;
varying vec2 v_st2; varying vec2 v_st2;
void main() { void main() {
gl_FragColor = mix(texture2D(tex, v_st), texture2D(tex, v_st2), u_scale.x) * u_color; gl_FragColor = mix(texture2D(u_tex, v_st), texture2D(u_tex, v_st2), u_scale.x) * u_color;
} }

View File

@@ -1,14 +1,14 @@
#ifdef GLES #ifdef GLES
precision highp float; precision highp float;
#endif #endif
attribute vec2 vertex; attribute vec2 a_pos;
attribute vec2 tex_coord; attribute vec2 a_tex_coord;
uniform mat4 u_mvp; uniform mat4 u_mvp;
varying vec2 tex_c; varying vec2 tex_c;
void main() { void main() {
gl_Position = u_mvp * vec4(vertex, 0.0, 1.0); gl_Position = u_mvp * vec4(a_pos, 0.0, 1.0);
tex_c = tex_coord; tex_c = a_tex_coord;
} }
$$ $$
@@ -16,10 +16,10 @@ $$
#ifdef GLES #ifdef GLES
precision highp float; precision highp float;
#endif #endif
uniform sampler2D tex; uniform sampler2D u_tex;
uniform float u_alpha; uniform float u_alpha;
varying vec2 tex_c; varying vec2 tex_c;
void main() { void main() {
gl_FragColor = texture2D(tex, tex_c) * u_alpha; gl_FragColor = texture2D(u_tex, tex_c) * u_alpha;
} }

View File

@@ -1,8 +1,8 @@
#ifdef GLES #ifdef GLES
precision highp float; precision highp float;
#endif #endif
attribute vec4 vertex; attribute vec4 a_pos;
attribute vec2 tex_coord; attribute vec2 a_tex_coord;
uniform mat4 u_mv; uniform mat4 u_mv;
uniform mat4 u_proj; uniform mat4 u_proj;
uniform float u_scale; uniform float u_scale;
@@ -12,16 +12,16 @@ varying vec2 tex_c;
void main() { void main() {
vec4 pos; vec4 pos;
vec2 dir = vertex.zw; vec2 dir = a_pos.zw;
float coord_scale = 1.0 / u_coord_scale; float coord_scale = 1.0 / u_coord_scale;
if (abs(mod(vertex.x, 2.0)) == 0.0) { if (abs(mod(a_pos.x, 2.0)) == 0.0) {
pos = u_proj * (u_mv * vec4(vertex.xy + dir * u_scale, 0.0, 1.0)); pos = u_proj * (u_mv * vec4(a_pos.xy + dir * u_scale, 0.0, 1.0));
} else { // place as billboard } else { // place as billboard
vec4 center = u_mv * vec4(vertex.xy, 0.0, 1.0); vec4 center = u_mv * vec4(a_pos.xy, 0.0, 1.0);
pos = u_proj * (center + vec4(dir * coord_scale, 0.0, 0.0)); pos = u_proj * (center + vec4(dir * coord_scale, 0.0, 0.0));
} }
gl_Position = pos; gl_Position = pos;
tex_c = tex_coord * u_div; tex_c = a_tex_coord * u_div;
} }
$$ $$
@@ -29,9 +29,9 @@ $$
#ifdef GLES #ifdef GLES
precision highp float; precision highp float;
#endif #endif
uniform sampler2D tex; uniform sampler2D u_tex;
varying vec2 tex_c; varying vec2 tex_c;
void main() { void main() {
gl_FragColor = texture2D(tex, tex_c.xy); gl_FragColor = texture2D(u_tex, tex_c.xy);
} }

View File

@@ -171,8 +171,8 @@ public class BitmapBucket extends TextureBucket {
return; return;
uMVP = getUniform("u_mvp"); uMVP = getUniform("u_mvp");
uAlpha = getUniform("u_alpha"); uAlpha = getUniform("u_alpha");
aPos = getAttrib("vertex"); aPos = getAttrib("a_pos");
aTexCoord = getAttrib("tex_coord"); aTexCoord = getAttrib("a_tex_coord");
} }
@Override @Override

View File

@@ -95,8 +95,8 @@ public class TextureBucket extends RenderBucket {
uScale = getUniform("u_scale"); uScale = getUniform("u_scale");
uCoordScale = getUniform("u_coord_scale"); uCoordScale = getUniform("u_coord_scale");
uTexSize = getUniform("u_div"); uTexSize = getUniform("u_div");
aPos = getAttrib("vertex"); aPos = getAttrib("a_pos");
aTexCoord = getAttrib("tex_coord"); aTexCoord = getAttrib("a_tex_coord");
} }
@Override @Override