From 320ce5b44d62eddda7cc473b515162bd7cbb5259 Mon Sep 17 00:00:00 2001 From: Emux Date: Sun, 5 Mar 2017 12:09:53 +0200 Subject: [PATCH] Location shaders: check no rotation, fixes #321 --- docs/Changelog.md | 2 +- vtm/resources/assets/shaders/location_1.glsl | 2 +- .../assets/shaders/location_1_reverse.glsl | 2 +- vtm/resources/assets/shaders/location_2.glsl | 34 +++++++++++-------- .../org/oscim/renderer/LocationRenderer.java | 20 +++++------ 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 44189bb4..c93908ee 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -5,7 +5,7 @@ - Symbol rotation [#294](https://github.com/mapsforge/vtm/issues/294) - Marker clustering [#312](https://github.com/mapsforge/vtm/issues/312) - Osmagray theme [#300](https://github.com/mapsforge/vtm/issues/300) -- Location renderer custom shaders [#317](https://github.com/mapsforge/vtm/issues/317) +- Location custom shaders [#317](https://github.com/mapsforge/vtm/issues/317) - 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) - Many other minor improvements and bug fixes diff --git a/vtm/resources/assets/shaders/location_1.glsl b/vtm/resources/assets/shaders/location_1.glsl index e6100681..8e11f13a 100644 --- a/vtm/resources/assets/shaders/location_1.glsl +++ b/vtm/resources/assets/shaders/location_1.glsl @@ -22,7 +22,7 @@ uniform float u_phase; uniform vec2 u_dir; void main() { float len = 1.0 - length(v_tex); - if (u_dir.x == 0.0 && u_dir.y == 0.0){ + if (u_dir.x == 0.0 && u_dir.y == 0.0) { 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 4b0c4678..67a502fd 100644 --- a/vtm/resources/assets/shaders/location_1_reverse.glsl +++ b/vtm/resources/assets/shaders/location_1_reverse.glsl @@ -22,7 +22,7 @@ uniform float u_phase; uniform vec2 u_dir; void main() { float len = 1.0 - length(v_tex); - if (u_dir.x == 0.0 && u_dir.y == 0.0){ + if (u_dir.x == 0.0 && u_dir.y == 0.0) { 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 81688d5e..c92ca6be 100644 --- a/vtm/resources/assets/shaders/location_2.glsl +++ b/vtm/resources/assets/shaders/location_2.glsl @@ -22,19 +22,23 @@ uniform float u_phase; uniform vec2 u_dir; void main() { float len = 1.0 - length(v_tex); - // outer ring - float a = smoothstep(0.0, 2.0 / u_scale, len); - // inner ring - float b = 0.8 * smoothstep(3.0 / u_scale, 4.0 / u_scale, len); - // center point - float c = 0.5 * (1.0 - smoothstep(14.0 / u_scale, 16.0 / u_scale, 1.0 - len)); - 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); - // - subtract inner from outer to create the outline - // - multiply by viewshed - // - add center point - a = max(d, (a - (b + c)) + c); - gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * a; + if (u_dir.x == 0.0 && u_dir.y == 0.0) { + gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len; + } else { + // outer ring + float a = smoothstep(0.0, 2.0 / u_scale, len); + // inner ring + float b = 0.8 * smoothstep(3.0 / u_scale, 4.0 / u_scale, len); + // center point + float c = 0.5 * (1.0 - smoothstep(14.0 / u_scale, 16.0 / u_scale, 1.0 - len)); + 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); + // - subtract inner from outer to create the outline + // - multiply by viewshed + // - add center point + a = max(d, (a - (b + c)) + c); + 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 fc68f77c..017e2065 100644 --- a/vtm/src/org/oscim/renderer/LocationRenderer.java +++ b/vtm/src/org/oscim/renderer/LocationRenderer.java @@ -226,17 +226,17 @@ public class LocationRenderer extends LayerRenderer { gl.uniform1f(hPhase, 1); } - if (viewShed && mLocationIsVisible) { - float rotation = 0; - if (mCallback != null) - rotation = mCallback.getRotation(); - rotation -= 90; - gl.uniform2f(hDirection, - (float) Math.cos(Math.toRadians(rotation)), - (float) Math.sin(Math.toRadians(rotation))); - } else { + if (viewShed && mLocationIsVisible && mCallback != null) { + float rotation = mCallback.getRotation(); + if (rotation != 0) { + rotation -= 90; + gl.uniform2f(hDirection, + (float) Math.cos(Math.toRadians(rotation)), + (float) Math.sin(Math.toRadians(rotation))); + } else + gl.uniform2f(hDirection, 0, 0); + } else gl.uniform2f(hDirection, 0, 0); - } gl.drawArrays(GL.TRIANGLE_STRIP, 0, 4); }