Location renderer improvements #321

This commit is contained in:
Emux
2017-03-09 13:06:39 +02:00
parent 26253a6104
commit 20f1121d3a
5 changed files with 22 additions and 13 deletions

View File

@@ -6,7 +6,7 @@
- Marker clustering [#312](https://github.com/mapsforge/vtm/issues/312) - Marker clustering [#312](https://github.com/mapsforge/vtm/issues/312)
- Osmagray theme [#300](https://github.com/mapsforge/vtm/issues/300) - Osmagray theme [#300](https://github.com/mapsforge/vtm/issues/300)
- Symbol rotation [#294](https://github.com/mapsforge/vtm/issues/294) - 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) - 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) - 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) - vtm-ios-example module [#326](https://github.com/mapsforge/vtm/issues/326)

View File

@@ -20,9 +20,10 @@ varying vec2 v_tex;
uniform float u_scale; uniform float u_scale;
uniform float u_phase; uniform float u_phase;
uniform vec2 u_dir; uniform vec2 u_dir;
uniform int u_mode;
void main() { void main() {
float len = 1.0 - length(v_tex); 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; gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len;
} else { } else {
// outer ring // outer ring

View File

@@ -20,9 +20,10 @@ varying vec2 v_tex;
uniform float u_scale; uniform float u_scale;
uniform float u_phase; uniform float u_phase;
uniform vec2 u_dir; uniform vec2 u_dir;
uniform int u_mode;
void main() { void main() {
float len = 1.0 - length(v_tex); 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; gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len;
} else { } else {
// outer ring // outer ring

View File

@@ -20,9 +20,10 @@ varying vec2 v_tex;
uniform float u_scale; uniform float u_scale;
uniform float u_phase; uniform float u_phase;
uniform vec2 u_dir; uniform vec2 u_dir;
uniform int u_mode;
void main() { void main() {
float len = 1.0 - length(v_tex); 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; gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len;
} else { } else {
// outer ring // outer ring
@@ -34,11 +35,11 @@ void main() {
vec2 dir = normalize(v_tex); vec2 dir = normalize(v_tex);
float d = dot(dir, u_dir); float d = dot(dir, u_dir);
// 0.5 width of viewshed // 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 // - subtract inner from outer to create the outline
// - multiply by viewshed // - multiply by viewshed
// - add center point // - 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; gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * a;
} }
} }

View File

@@ -47,6 +47,7 @@ public class LocationRenderer extends LayerRenderer {
private int hScale; private int hScale;
private int hPhase; private int hPhase;
private int hDirection; private int hDirection;
private int uMode;
private final Point mIndicatorPosition = new Point(); private final Point mIndicatorPosition = new Point();
@@ -226,14 +227,18 @@ public class LocationRenderer extends LayerRenderer {
gl.uniform1f(hPhase, 1); gl.uniform1f(hPhase, 1);
} }
if (viewShed && mLocationIsVisible && mCallback != null && mCallback.hasRotation()) { if (viewShed && mLocationIsVisible) {
float rotation = mCallback.getRotation(); if (mCallback != null && mCallback.hasRotation()) {
rotation -= 90; float rotation = mCallback.getRotation();
gl.uniform2f(hDirection, rotation -= 90;
(float) Math.cos(Math.toRadians(rotation)), gl.uniform2f(hDirection,
(float) Math.sin(Math.toRadians(rotation))); (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 } else
gl.uniform2f(hDirection, 0, 0); gl.uniform1i(uMode, 1); // Outside screen
gl.drawArrays(GL.TRIANGLE_STRIP, 0, 4); gl.drawArrays(GL.TRIANGLE_STRIP, 0, 4);
} }
@@ -249,6 +254,7 @@ public class LocationRenderer extends LayerRenderer {
hPhase = gl.getUniformLocation(program, "u_phase"); hPhase = gl.getUniformLocation(program, "u_phase");
hScale = gl.getUniformLocation(program, "u_scale"); hScale = gl.getUniformLocation(program, "u_scale");
hDirection = gl.getUniformLocation(program, "u_dir"); hDirection = gl.getUniformLocation(program, "u_dir");
uMode = gl.getUniformLocation(program, "u_mode");
return true; return true;
} }