From 20f1121d3a5dd762cb8a0009dd9d982ae2c66ba7 Mon Sep 17 00:00:00 2001 From: Emux Date: Thu, 9 Mar 2017 13:06:39 +0200 Subject: [PATCH] Location renderer improvements #321 --- docs/Changelog.md | 2 +- vtm/resources/assets/shaders/location_1.glsl | 3 ++- .../assets/shaders/location_1_reverse.glsl | 3 ++- vtm/resources/assets/shaders/location_2.glsl | 7 ++++--- .../org/oscim/renderer/LocationRenderer.java | 20 ++++++++++++------- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 07b0d7ce..3b620b69 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -6,7 +6,7 @@ - Marker clustering [#312](https://github.com/mapsforge/vtm/issues/312) - Osmagray theme [#300](https://github.com/mapsforge/vtm/issues/300) - Symbol rotation [#294](https://github.com/mapsforge/vtm/issues/294) -- Location custom shaders [#317](https://github.com/mapsforge/vtm/issues/317) +- Location custom shaders & improvements [#317](https://github.com/mapsforge/vtm/issues/317) [#321](https://github.com/mapsforge/vtm/issues/321) - OkHttp external cache [#135](https://github.com/mapsforge/vtm/issues/135) - Texture atlas improvements [#301](https://github.com/mapsforge/vtm/pull/301) [#304](https://github.com/mapsforge/vtm/pull/304) - vtm-ios-example module [#326](https://github.com/mapsforge/vtm/issues/326) diff --git a/vtm/resources/assets/shaders/location_1.glsl b/vtm/resources/assets/shaders/location_1.glsl index 8e11f13a..f726b13a 100644 --- a/vtm/resources/assets/shaders/location_1.glsl +++ b/vtm/resources/assets/shaders/location_1.glsl @@ -20,9 +20,10 @@ varying vec2 v_tex; uniform float u_scale; uniform float u_phase; uniform vec2 u_dir; +uniform int u_mode; void main() { float len = 1.0 - length(v_tex); - if (u_dir.x == 0.0 && u_dir.y == 0.0) { + if (u_mode == 1) { gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len; } else { // outer ring diff --git a/vtm/resources/assets/shaders/location_1_reverse.glsl b/vtm/resources/assets/shaders/location_1_reverse.glsl index 67a502fd..dd3a4b6b 100644 --- a/vtm/resources/assets/shaders/location_1_reverse.glsl +++ b/vtm/resources/assets/shaders/location_1_reverse.glsl @@ -20,9 +20,10 @@ varying vec2 v_tex; uniform float u_scale; uniform float u_phase; uniform vec2 u_dir; +uniform int u_mode; void main() { float len = 1.0 - length(v_tex); - if (u_dir.x == 0.0 && u_dir.y == 0.0) { + if (u_mode == 1) { gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len; } else { // outer ring diff --git a/vtm/resources/assets/shaders/location_2.glsl b/vtm/resources/assets/shaders/location_2.glsl index c92ca6be..42178738 100644 --- a/vtm/resources/assets/shaders/location_2.glsl +++ b/vtm/resources/assets/shaders/location_2.glsl @@ -20,9 +20,10 @@ varying vec2 v_tex; uniform float u_scale; uniform float u_phase; uniform vec2 u_dir; +uniform int u_mode; void main() { float len = 1.0 - length(v_tex); - if (u_dir.x == 0.0 && u_dir.y == 0.0) { + if (u_mode == 1) { gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len; } else { // outer ring @@ -34,11 +35,11 @@ void main() { vec2 dir = normalize(v_tex); float d = dot(dir, u_dir); // 0.5 width of viewshed - d = clamp(smoothstep(0.7, 0.7 + 2.0/u_scale, d) * len, 0.0, 1.0); + d = clamp(smoothstep(0.7, 0.7 + 2.0 / u_scale, d) * len, 0.0, 1.0); // - subtract inner from outer to create the outline // - multiply by viewshed // - add center point - a = max(d, (a - (b + c)) + c); + a = max(d, (a - (b + c)) + c) + (u_mode == 2 ? c : 0); gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * a; } } diff --git a/vtm/src/org/oscim/renderer/LocationRenderer.java b/vtm/src/org/oscim/renderer/LocationRenderer.java index 05bf1695..868b7c79 100644 --- a/vtm/src/org/oscim/renderer/LocationRenderer.java +++ b/vtm/src/org/oscim/renderer/LocationRenderer.java @@ -47,6 +47,7 @@ public class LocationRenderer extends LayerRenderer { private int hScale; private int hPhase; private int hDirection; + private int uMode; private final Point mIndicatorPosition = new Point(); @@ -226,14 +227,18 @@ public class LocationRenderer extends LayerRenderer { gl.uniform1f(hPhase, 1); } - if (viewShed && mLocationIsVisible && mCallback != null && mCallback.hasRotation()) { - float rotation = mCallback.getRotation(); - rotation -= 90; - gl.uniform2f(hDirection, - (float) Math.cos(Math.toRadians(rotation)), - (float) Math.sin(Math.toRadians(rotation))); + if (viewShed && mLocationIsVisible) { + if (mCallback != null && mCallback.hasRotation()) { + float rotation = mCallback.getRotation(); + rotation -= 90; + gl.uniform2f(hDirection, + (float) Math.cos(Math.toRadians(rotation)), + (float) Math.sin(Math.toRadians(rotation))); + gl.uniform1i(uMode, 3); // With bearing + } else + gl.uniform1i(uMode, 2); // Without bearing } else - gl.uniform2f(hDirection, 0, 0); + gl.uniform1i(uMode, 1); // Outside screen gl.drawArrays(GL.TRIANGLE_STRIP, 0, 4); } @@ -249,6 +254,7 @@ public class LocationRenderer extends LayerRenderer { hPhase = gl.getUniformLocation(program, "u_phase"); hScale = gl.getUniformLocation(program, "u_scale"); hDirection = gl.getUniformLocation(program, "u_dir"); + uMode = gl.getUniformLocation(program, "u_mode"); return true; }