Skip to content

Commit

Permalink
Location renderer: activate all fragment shaders opensciencemap#171
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Sep 17, 2016
1 parent 769dd69 commit 50ccecc
Showing 1 changed file with 42 additions and 27 deletions.
69 changes: 42 additions & 27 deletions vtm/src/org/oscim/renderer/LocationRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
public class LocationRenderer extends LayerRenderer {
private static final int SHOW_ACCURACY_ZOOM = 16;

public enum Shader {SHADER_1, SHADER_2}

private final Map mMap;
private final Layer mLayer;

Expand Down Expand Up @@ -60,6 +62,7 @@ public class LocationRenderer extends LayerRenderer {
private Callback mCallback;
private final Point mLocation = new Point(Double.NaN, Double.NaN);
private double mRadius;
private Shader mShader = Shader.SHADER_1;
private int mShowAccuracyZoom = SHOW_ACCURACY_ZOOM;

public LocationRenderer(Map map, Layer layer) {
Expand All @@ -77,6 +80,10 @@ public void setLocation(double x, double y, double radius) {
mRadius = radius;
}

public void setShader(Shader shader) {
mShader = shader;
}

public void setShowAccuracyZoom(int showAccuracyZoom) {
mShowAccuracyZoom = showAccuracyZoom;
}
Expand Down Expand Up @@ -234,7 +241,15 @@ public void render(GLViewport v) {
}

private boolean init() {
int shader = GLShader.createProgram(vShaderStr, fShaderStr);
int shader = 0;
switch (mShader) {
case SHADER_1:
shader = GLShader.createProgram(vShaderStr, fShaderStr1);
break;
case SHADER_2:
shader = GLShader.createProgram(vShaderStr, fShaderStr2);
break;
}
if (shader == 0)
return false;

Expand All @@ -248,7 +263,7 @@ private boolean init() {
return true;
}

private final static String vShaderStr = ""
private static final String vShaderStr = ""
+ "precision mediump float;"
+ "uniform mat4 u_mvp;"
+ "uniform float u_phase;"
Expand All @@ -260,7 +275,7 @@ private boolean init() {
+ " v_tex = a_pos;"
+ "}";

private final static String fShaderStr = ""
private static final String fShaderStr1 = ""
+ "precision mediump float;"
+ "varying vec2 v_tex;"
+ "uniform float u_scale;"
Expand Down Expand Up @@ -289,30 +304,30 @@ private boolean init() {
+ " gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * a;"
+ "}}";

//private final static String fShaderStr = ""
// + "precision mediump float;"
// + "varying vec2 v_tex;"
// + "uniform float u_scale;"
// + "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;"
// + "}";
private static final String fShaderStr2 = ""
+ "precision mediump float;"
+ "varying vec2 v_tex;"
+ "uniform float u_scale;"
+ "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;"
+ "}";

public interface Callback {
float getRotation();
Expand Down

0 comments on commit 50ccecc

Please sign in to comment.