- LineClipper added start(x0,y0), clipNext(x1,y1) 'state' clipping mode
- use vec4 array for extrusion colors -> set color only once for all tiles - use full range for direction vector in extrusion vertex
This commit is contained in:
@@ -78,10 +78,11 @@ public class ExtrusionLayer extends Layer {
|
||||
boolean simple = true;
|
||||
int startVertex = mNumVertices;
|
||||
|
||||
// just a guess to make it look ok
|
||||
if (height == 0)
|
||||
height = 400;
|
||||
height = 320;
|
||||
else
|
||||
height *= 40;
|
||||
height *= 30;
|
||||
|
||||
int length = 0;
|
||||
for (int ipos = 0, ppos = 0, n = index.length; ipos < n; ipos++, ppos += length) {
|
||||
@@ -212,7 +213,8 @@ public class ExtrusionLayer extends Layer {
|
||||
float ux, uy;
|
||||
|
||||
float a = (float) Math.sqrt(vx * vx + vy * vy);
|
||||
short color1 = getColor(vx, a);
|
||||
//float vlight = vx > 0 ? (vx / a) : -(vx / a);
|
||||
short color1 = (short) ((1 + vx / a) * 127);
|
||||
short fcolor = color1;
|
||||
short color2 = 0;
|
||||
|
||||
@@ -226,6 +228,8 @@ public class ExtrusionLayer extends Layer {
|
||||
short[] vertices = mCurVertices.vertices;
|
||||
int v = mCurVertices.used;
|
||||
|
||||
mClipper.clipStart((int) nx, (int) ny);
|
||||
|
||||
for (int i = 2, n = vertexCnt + 2; i < n; i += 2, v += 8) {
|
||||
cx = nx;
|
||||
cy = ny;
|
||||
@@ -269,7 +273,7 @@ public class ExtrusionLayer extends Layer {
|
||||
|
||||
// set lighting (by direction)
|
||||
a = (float) Math.sqrt(vx * vx + vy * vy);
|
||||
color2 = getColor(vx, a);
|
||||
color2 = (short) ((1 + vx / a) * 127); //getColor(vx, a);
|
||||
|
||||
short c;
|
||||
if (even == 0)
|
||||
@@ -294,7 +298,7 @@ public class ExtrusionLayer extends Layer {
|
||||
}
|
||||
|
||||
/* check if face is within tile */
|
||||
if (!mClipper.clip((int) cx, (int) cy, (int) nx, (int) ny)) {
|
||||
if (!mClipper.clipNext((int) nx, (int) ny)) {
|
||||
even = (even + 1) % 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -146,11 +146,15 @@ public class ExtrusionOverlay extends RenderOverlay {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean debug = false;
|
||||
private boolean debug = false;
|
||||
private final float[] mVPMatrix = new float[16];
|
||||
|
||||
@Override
|
||||
public synchronized void render(MapPosition pos, float[] mv, float[] proj) {
|
||||
|
||||
Matrix.multiplyMM(mVPMatrix, 0, proj, 0, pos.viewMatrix, 0);
|
||||
proj = mVPMatrix;
|
||||
|
||||
MapTile[] tiles = mTiles;
|
||||
|
||||
float div = FastMath.pow(tiles[0].zoomLevel - pos.zoomLevel);
|
||||
@@ -162,7 +166,7 @@ public class ExtrusionOverlay extends RenderOverlay {
|
||||
|
||||
GLState.enableVertexArrays(hExtrusionVertexPosition, hExtrusionLightPosition);
|
||||
GLES20.glUniform1i(hExtrusionMode, 0);
|
||||
GLES20.glUniform4f(hExtrusionColor, 0.6f, 0.6f, 0.6f, 0.8f);
|
||||
GLES20.glUniform4fv(hExtrusionColor, 4, mColor, 0);
|
||||
|
||||
GLState.test(false, false);
|
||||
|
||||
@@ -209,6 +213,7 @@ public class ExtrusionOverlay extends RenderOverlay {
|
||||
GLES20.glDepthMask(true);
|
||||
GLES20.glColorMask(false, false, false, false);
|
||||
GLES20.glUniform1i(hExtrusionMode, 0);
|
||||
GLES20.glUniform4fv(hExtrusionColor, 4, mColor, 0);
|
||||
|
||||
// draw to depth buffer
|
||||
for (int i = 0; i < mTileCnt; i++) {
|
||||
@@ -255,30 +260,23 @@ public class ExtrusionOverlay extends RenderOverlay {
|
||||
|
||||
// draw roof
|
||||
GLES20.glUniform1i(hExtrusionMode, 0);
|
||||
GLES20.glUniform4fv(hExtrusionColor, 1, mRoofColor, 0);
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, el.mIndiceCnt[2],
|
||||
GLES20.GL_UNSIGNED_SHORT, (el.mIndiceCnt[0] + el.mIndiceCnt[1]) * 2);
|
||||
|
||||
// draw sides 1
|
||||
GLES20.glUniform4fv(hExtrusionColor, 1, mColor, 0);
|
||||
GLES20.glUniform1i(hExtrusionMode, 1);
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, el.mIndiceCnt[0],
|
||||
GLES20.GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
// draw sides 2
|
||||
GLES20.glUniform4fv(hExtrusionColor, 1, mColor2, 0);
|
||||
GLES20.glUniform1i(hExtrusionMode, 2);
|
||||
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, el.mIndiceCnt[1],
|
||||
GLES20.GL_UNSIGNED_SHORT, el.mIndiceCnt[0] * 2);
|
||||
|
||||
//GLES20.glDepthFunc(GLES20.GL_LEQUAL);
|
||||
GLES20.glUniform1i(hExtrusionMode, 3);
|
||||
GLES20.glUniform4f(hExtrusionColor, 0.7f, 0.7f, 0.7f, 1.0f);
|
||||
GLES20.glDrawElements(GLES20.GL_LINES, el.mIndiceCnt[3],
|
||||
GLES20.GL_UNSIGNED_SHORT,
|
||||
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]) * 2);
|
||||
//GLES20.glDepthFunc(GLES20.GL_EQUAL);
|
||||
|
||||
// just a temporary reference!
|
||||
tiles[i] = null;
|
||||
@@ -309,48 +307,46 @@ public class ExtrusionOverlay extends RenderOverlay {
|
||||
matrix[5] = scale;
|
||||
matrix[10] = scale / 1000f;
|
||||
|
||||
Matrix.multiplyMM(matrix, 0, mapPosition.viewMatrix, 0, matrix, 0);
|
||||
Matrix.multiplyMM(matrix, 0, proj, 0, matrix, 0);
|
||||
}
|
||||
|
||||
// sligthly differ adjacent faces to improve contrast
|
||||
//float mColor[] = { 0.76872549f, 0.751960784f, 0.740196078f, 0.8f };
|
||||
//float mColor2[] = { 0.76372549f, 0.751960784f, 0.745196078f, 0.8f };
|
||||
private final float _a = 0.8f;
|
||||
|
||||
float mColor[] = { 201 / 255f, 200 / 255f, 198 / 255f, 0.8f };
|
||||
float mColor2[] = { 201 / 255f, 200 / 255f, 199 / 255f, 0.8f };
|
||||
|
||||
//float mRoofColor[] = { 0.895f, 0.89f, 0.88f, 0.9f };
|
||||
float _a = 0.8f;
|
||||
float mRoofColor[] = { 236 / 255f * _a, 235 / 255f * _a, 234 / 255f * _a, _a };
|
||||
private final float[] mColor = {
|
||||
// roof color
|
||||
236 / 255f * _a, 235 / 255f * _a, 234 / 255f * _a, _a,
|
||||
// sligthly differ adjacent side faces to improve contrast
|
||||
201 / 255f, 200 / 255f, 198 / 255f, _a,
|
||||
200 / 255f, 200 / 255f, 196 / 255f, _a,
|
||||
// roof outline
|
||||
0.75f, 0.75f, 0.75f, 1.0f
|
||||
};
|
||||
|
||||
final static String extrusionVertexShader = ""
|
||||
+ "precision mediump float;"
|
||||
+ "uniform mat4 u_mvp;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "uniform vec4 u_color[4];"
|
||||
+ "uniform int u_mode;"
|
||||
+ "attribute vec4 a_position;"
|
||||
+ "attribute vec2 a_light;"
|
||||
+ "varying vec4 color;"
|
||||
+ "const float ff = 255.0;"
|
||||
+ "const float a = 0.8;"
|
||||
+ "void main() {"
|
||||
+ " gl_Position = u_mvp * a_position;"
|
||||
+ " if (u_mode == 0)"
|
||||
// roof / depth pass
|
||||
+ " color = u_color;"
|
||||
+ " else {"
|
||||
// decrease contrast with distance
|
||||
+ " float alpha = 0.95 + gl_Position.z * 0.05;"
|
||||
+ " if (u_mode == 1)"
|
||||
+ " color = u_color[0];"
|
||||
+ " else if (u_mode == 1)"
|
||||
// sides 1 - use 0xff00
|
||||
+ " color = vec4(u_color.rgb * (a_light.y / ff * alpha), 1.0) * (0.8 * alpha);"
|
||||
+ " color = vec4(u_color[1].rgb * ((0.90 + (0.5 - (a_light.y / ff)) * 0.2) * a), a);"
|
||||
+ " else if (u_mode == 2)"
|
||||
// sides 2 - use 0x00ff
|
||||
+ " color = vec4(u_color.rgb * (a_light.x / ff * alpha), 1.0) * (0.8 * alpha);"
|
||||
+ " color = vec4(u_color[2].rgb * ((0.90 + (0.5 - (a_light.x / ff)) * 0.2) * a), a);"
|
||||
+ " else"
|
||||
// sides 2 - use 0x00ff
|
||||
+ " color = u_color * alpha;"
|
||||
+ "}}";
|
||||
// outline - decrease contrast with distance
|
||||
+ " color = u_color[3] * (0.98 + gl_Position.z * 0.02);"
|
||||
+ "}";
|
||||
|
||||
// final static String extrusionVertexAnimShader = ""
|
||||
// + "precision mediump float;"
|
||||
|
||||
Reference in New Issue
Block a user