Add building z-limit function to shader and web ui (#462)

This commit is contained in:
Izumi Kawashima
2017-12-26 17:04:47 +09:00
committed by Emux
parent 0367507dae
commit abac84e82a
6 changed files with 125 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ uniform mat4 u_mvp;
uniform vec4 u_color[4];
uniform int u_mode;
uniform float u_alpha;
uniform float u_zlimit;
attribute vec4 a_pos;
attribute vec2 a_light;
varying vec4 color;
@@ -13,7 +14,11 @@ const float ff = 255.0;
void
main(){
// change height by u_alpha
gl_Position = u_mvp * vec4(a_pos.xy, a_pos.z * u_alpha, 1.0);
float height = a_pos.z * u_alpha;
if (height > u_zlimit) {
height = u_zlimit;
}
gl_Position = u_mvp * vec4(a_pos.xy, height, 1.0);
// depth = gl_Position.z;
if (u_mode == -1) {
;

View File

@@ -1,5 +1,7 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2017 Izumi Kawashima
* Copyright 2017 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@@ -38,13 +40,15 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
protected int mBucketsCnt;
protected float mAlpha = 1;
private float mZLimit = Float.MAX_VALUE;
public ExtrusionRenderer(boolean mesh, boolean alpha) {
mMode = mesh ? 1 : 0;
mTranslucent = alpha;
}
public static class Shader extends GLShader {
int uMVP, uColor, uAlpha, uMode, aPos, aLight;
int uMVP, uColor, uAlpha, uMode, aPos, aLight, uZLimit;
public Shader(String shader) {
if (!create(shader))
@@ -54,6 +58,7 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
uColor = getUniform("u_color");
uAlpha = getUniform("u_alpha");
uMode = getUniform("u_mode");
uZLimit = getUniform("u_zlimit");
aPos = getAttrib("a_pos");
aLight = getAttrib("a_light");
}
@@ -114,6 +119,7 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
gl.depthFunc(GL.LESS);
gl.uniform1f(s.uAlpha, mAlpha);
gl.uniform1f(s.uZLimit, mZLimit);
ExtrusionBuckets[] ebs = mExtrusionBucketSet;
@@ -268,4 +274,8 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
}
v.mvp.setAsUniform(s.uMVP);
}
public void setZLimit(float zLimit) {
mZLimit = zLimit;
}
}