From a6ce05034a9b00fd4032a033753ff03d74cebd8e Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Thu, 16 May 2019 08:19:09 +0200 Subject: [PATCH] Adapt / refactor shader uniforms and attributes --- vtm/resources/assets/shaders/line_aa.glsl | 4 ++-- vtm/resources/assets/shaders/line_aa_proj.glsl | 4 ++-- .../assets/shaders/linetex_layer_tex.glsl | 4 ++-- vtm/resources/assets/shaders/poly_texture.glsl | 4 ++-- .../assets/shaders/polygon_layer_tex.glsl | 4 ++-- .../assets/shaders/texture_alpha.glsl | 12 ++++++------ .../assets/shaders/texture_layer.glsl | 18 +++++++++--------- .../oscim/renderer/bucket/BitmapBucket.java | 4 ++-- .../oscim/renderer/bucket/TextureBucket.java | 4 ++-- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/vtm/resources/assets/shaders/line_aa.glsl b/vtm/resources/assets/shaders/line_aa.glsl index 9b35858d..34924ed2 100644 --- a/vtm/resources/assets/shaders/line_aa.glsl +++ b/vtm/resources/assets/shaders/line_aa.glsl @@ -26,7 +26,7 @@ $$ #ifdef GLES precision highp float; #endif -uniform sampler2D tex; +uniform sampler2D u_tex; uniform float u_fade; uniform int u_mode; uniform vec4 u_color; @@ -39,7 +39,7 @@ void main() { #ifdef DESKTOP_QUIRKS len = length(v_st); #else - len = texture2D(tex, v_st).a; + len = texture2D(u_tex, v_st).a; #endif } else { // flat cap line diff --git a/vtm/resources/assets/shaders/line_aa_proj.glsl b/vtm/resources/assets/shaders/line_aa_proj.glsl index 39fe954a..2c6da947 100644 --- a/vtm/resources/assets/shaders/line_aa_proj.glsl +++ b/vtm/resources/assets/shaders/line_aa_proj.glsl @@ -29,7 +29,7 @@ $$ #ifdef GLES precision highp float; #endif -uniform sampler2D tex; +uniform sampler2D u_tex; uniform int u_mode; uniform vec4 u_color; uniform float u_fade; @@ -43,7 +43,7 @@ void main() { #ifdef DESKTOP_QUIRKS len = length(v_st); #else - len = texture2D(tex, v_st).a; + len = texture2D(u_tex, v_st).a; #endif vec2 st_width = fwidth(v_st); fuzz = max(st_width.s, st_width.t); diff --git a/vtm/resources/assets/shaders/linetex_layer_tex.glsl b/vtm/resources/assets/shaders/linetex_layer_tex.glsl index 05200fa4..522afef0 100644 --- a/vtm/resources/assets/shaders/linetex_layer_tex.glsl +++ b/vtm/resources/assets/shaders/linetex_layer_tex.glsl @@ -38,7 +38,7 @@ uniform vec4 u_color; uniform vec4 u_bgcolor; uniform float u_pwidth; varying vec2 v_st; -uniform sampler2D tex; +uniform sampler2D u_tex; uniform int u_mode; void main() { @@ -50,7 +50,7 @@ void main() { } // use lineLength mod texture step (mod is always positive) // 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); gl_FragColor = (c * u_color) * smoothstep(0.5 - fuzz, 0.5 + fuzz, c.a); } else { diff --git a/vtm/resources/assets/shaders/poly_texture.glsl b/vtm/resources/assets/shaders/poly_texture.glsl index b3f605a0..0e5dd148 100644 --- a/vtm/resources/assets/shaders/poly_texture.glsl +++ b/vtm/resources/assets/shaders/poly_texture.glsl @@ -19,11 +19,11 @@ $$ precision highp float; #endif uniform vec4 u_color; -uniform sampler2D tex; +uniform sampler2D u_tex; uniform vec2 u_scale; varying vec2 v_st; varying vec2 v_st2; 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); } diff --git a/vtm/resources/assets/shaders/polygon_layer_tex.glsl b/vtm/resources/assets/shaders/polygon_layer_tex.glsl index 8fa634a4..9e3254a9 100644 --- a/vtm/resources/assets/shaders/polygon_layer_tex.glsl +++ b/vtm/resources/assets/shaders/polygon_layer_tex.glsl @@ -19,11 +19,11 @@ $$ precision highp float; #endif uniform vec4 u_color; -uniform sampler2D tex; +uniform sampler2D u_tex; uniform vec2 u_scale; varying vec2 v_st; varying vec2 v_st2; 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; } diff --git a/vtm/resources/assets/shaders/texture_alpha.glsl b/vtm/resources/assets/shaders/texture_alpha.glsl index 9e61f7fe..fa92d9ff 100644 --- a/vtm/resources/assets/shaders/texture_alpha.glsl +++ b/vtm/resources/assets/shaders/texture_alpha.glsl @@ -1,14 +1,14 @@ #ifdef GLES precision highp float; #endif -attribute vec2 vertex; -attribute vec2 tex_coord; +attribute vec2 a_pos; +attribute vec2 a_tex_coord; uniform mat4 u_mvp; varying vec2 tex_c; void main() { - gl_Position = u_mvp * vec4(vertex, 0.0, 1.0); - tex_c = tex_coord; + gl_Position = u_mvp * vec4(a_pos, 0.0, 1.0); + tex_c = a_tex_coord; } $$ @@ -16,10 +16,10 @@ $$ #ifdef GLES precision highp float; #endif -uniform sampler2D tex; +uniform sampler2D u_tex; uniform float u_alpha; varying vec2 tex_c; void main() { - gl_FragColor = texture2D(tex, tex_c) * u_alpha; + gl_FragColor = texture2D(u_tex, tex_c) * u_alpha; } diff --git a/vtm/resources/assets/shaders/texture_layer.glsl b/vtm/resources/assets/shaders/texture_layer.glsl index 7881b362..9fbb00f4 100644 --- a/vtm/resources/assets/shaders/texture_layer.glsl +++ b/vtm/resources/assets/shaders/texture_layer.glsl @@ -1,8 +1,8 @@ #ifdef GLES precision highp float; #endif -attribute vec4 vertex; -attribute vec2 tex_coord; +attribute vec4 a_pos; +attribute vec2 a_tex_coord; uniform mat4 u_mv; uniform mat4 u_proj; uniform float u_scale; @@ -12,16 +12,16 @@ varying vec2 tex_c; void main() { vec4 pos; - vec2 dir = vertex.zw; + vec2 dir = a_pos.zw; float coord_scale = 1.0 / u_coord_scale; - if (abs(mod(vertex.x, 2.0)) == 0.0) { - pos = u_proj * (u_mv * vec4(vertex.xy + dir * u_scale, 0.0, 1.0)); + if (abs(mod(a_pos.x, 2.0)) == 0.0) { + pos = u_proj * (u_mv * vec4(a_pos.xy + dir * u_scale, 0.0, 1.0)); } 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)); } gl_Position = pos; - tex_c = tex_coord * u_div; + tex_c = a_tex_coord * u_div; } $$ @@ -29,9 +29,9 @@ $$ #ifdef GLES precision highp float; #endif -uniform sampler2D tex; +uniform sampler2D u_tex; varying vec2 tex_c; void main() { - gl_FragColor = texture2D(tex, tex_c.xy); + gl_FragColor = texture2D(u_tex, tex_c.xy); } diff --git a/vtm/src/org/oscim/renderer/bucket/BitmapBucket.java b/vtm/src/org/oscim/renderer/bucket/BitmapBucket.java index 440b8923..e9ecdf01 100644 --- a/vtm/src/org/oscim/renderer/bucket/BitmapBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/BitmapBucket.java @@ -171,8 +171,8 @@ public class BitmapBucket extends TextureBucket { return; uMVP = getUniform("u_mvp"); uAlpha = getUniform("u_alpha"); - aPos = getAttrib("vertex"); - aTexCoord = getAttrib("tex_coord"); + aPos = getAttrib("a_pos"); + aTexCoord = getAttrib("a_tex_coord"); } @Override diff --git a/vtm/src/org/oscim/renderer/bucket/TextureBucket.java b/vtm/src/org/oscim/renderer/bucket/TextureBucket.java index 1c36fb7f..823c2603 100644 --- a/vtm/src/org/oscim/renderer/bucket/TextureBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/TextureBucket.java @@ -95,8 +95,8 @@ public class TextureBucket extends RenderBucket { uScale = getUniform("u_scale"); uCoordScale = getUniform("u_coord_scale"); uTexSize = getUniform("u_div"); - aPos = getAttrib("vertex"); - aTexCoord = getAttrib("tex_coord"); + aPos = getAttrib("a_pos"); + aTexCoord = getAttrib("a_tex_coord"); } @Override