add shader for depth buffer testing
This commit is contained in:
parent
bca4a24c38
commit
cb6a861f7f
@ -69,8 +69,11 @@ public final class PolygonRenderer {
|
|||||||
static boolean init() {
|
static boolean init() {
|
||||||
|
|
||||||
// Set up the program for rendering polygons
|
// Set up the program for rendering polygons
|
||||||
|
// polygonProgram = GlUtils.createProgram(Shaders.polygonVertexShaderZ,
|
||||||
|
// Shaders.polygonFragmentShaderZ);
|
||||||
polygonProgram = GlUtils.createProgram(Shaders.polygonVertexShader,
|
polygonProgram = GlUtils.createProgram(Shaders.polygonVertexShader,
|
||||||
Shaders.polygonFragmentShader);
|
Shaders.polygonFragmentShader);
|
||||||
|
|
||||||
if (polygonProgram == 0) {
|
if (polygonProgram == 0) {
|
||||||
// Log.e(TAG, "Could not create polygon program.");
|
// Log.e(TAG, "Could not create polygon program.");
|
||||||
return false;
|
return false;
|
||||||
@ -232,11 +235,9 @@ public final class PolygonRenderer {
|
|||||||
glStencilMask(0xFF);
|
glStencilMask(0xFF);
|
||||||
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
|
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
|
||||||
|
|
||||||
|
// draw clip-region into depth buffer:
|
||||||
|
// this is used for lines and polygons
|
||||||
if (first && drawClipped) {
|
if (first && drawClipped) {
|
||||||
//GLState.test(true, true);
|
|
||||||
// draw clip-region into depth buffer:
|
|
||||||
// this is used for lines and polygons
|
|
||||||
|
|
||||||
// write to depth buffer
|
// write to depth buffer
|
||||||
glDepthMask(true);
|
glDepthMask(true);
|
||||||
|
|
||||||
@ -260,7 +261,7 @@ public final class PolygonRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no need for depth test while drawing stencil
|
// no need for depth test while drawing stencil
|
||||||
//GLState.test(false, true);
|
GLState.test(false, true);
|
||||||
|
|
||||||
mFillPolys[mCount] = pl;
|
mFillPolys[mCount] = pl;
|
||||||
|
|
||||||
@ -272,8 +273,8 @@ public final class PolygonRenderer {
|
|||||||
// draw up to 8 layers into stencil buffer
|
// draw up to 8 layers into stencil buffer
|
||||||
if (mCount == STENCIL_BITS) {
|
if (mCount == STENCIL_BITS) {
|
||||||
/* only draw where nothing was drawn yet */
|
/* only draw where nothing was drawn yet */
|
||||||
//if (drawClipped)
|
if (drawClipped)
|
||||||
// GLState.test(true, true);
|
GLState.test(true, true);
|
||||||
|
|
||||||
fillPolygons(zoom, scale);
|
fillPolygons(zoom, scale);
|
||||||
mCount = 0;
|
mCount = 0;
|
||||||
@ -283,8 +284,8 @@ public final class PolygonRenderer {
|
|||||||
|
|
||||||
if (mCount > 0) {
|
if (mCount > 0) {
|
||||||
/* only draw where nothing was drawn yet */
|
/* only draw where nothing was drawn yet */
|
||||||
//if (drawClipped)
|
if (drawClipped)
|
||||||
// GLState.test(true, true);
|
GLState.test(true, true);
|
||||||
|
|
||||||
fillPolygons(zoom, scale);
|
fillPolygons(zoom, scale);
|
||||||
}
|
}
|
||||||
@ -305,7 +306,7 @@ public final class PolygonRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static float[] debugFillColor = { 0.3f, 0.0f, 0.0f, 0.3f };
|
private static float[] debugFillColor = { 0.3f, 0.0f, 0.0f, 0.3f };
|
||||||
private static float[] debugFillColor2 = { 0.0f, 0.3f, 0.0f, 0.3f };
|
private static float[] debugFillColor2 = { .8f, .8f, .8f, .8f };
|
||||||
private static FloatBuffer mDebugFill;
|
private static FloatBuffer mDebugFill;
|
||||||
|
|
||||||
static void debugDraw(float[] matrix, float[] coords, int color) {
|
static void debugDraw(float[] matrix, float[] coords, int color) {
|
||||||
|
@ -79,7 +79,7 @@ public final class Shaders {
|
|||||||
+ "}";
|
+ "}";
|
||||||
|
|
||||||
final static String polygonVertexShader = ""
|
final static String polygonVertexShader = ""
|
||||||
+ "precision mediump float;"
|
+ "precision highp float;"
|
||||||
+ "uniform mat4 u_mvp;"
|
+ "uniform mat4 u_mvp;"
|
||||||
+ "attribute vec4 a_position;"
|
+ "attribute vec4 a_position;"
|
||||||
+ "void main() {"
|
+ "void main() {"
|
||||||
@ -87,12 +87,34 @@ public final class Shaders {
|
|||||||
+ "}";
|
+ "}";
|
||||||
|
|
||||||
final static String polygonFragmentShader = ""
|
final static String polygonFragmentShader = ""
|
||||||
+ "precision mediump float;"
|
+ "precision highp float;"
|
||||||
+ "uniform vec4 u_color;"
|
+ "uniform vec4 u_color;"
|
||||||
+ "void main() {"
|
+ "void main() {"
|
||||||
+ " gl_FragColor = u_color;"
|
+ " gl_FragColor = u_color;"
|
||||||
+ "}";
|
+ "}";
|
||||||
|
|
||||||
|
final static String polygonVertexShaderZ = ""
|
||||||
|
+ "precision highp float;"
|
||||||
|
+ "uniform mat4 u_mvp;"
|
||||||
|
+ "attribute vec4 a_position;"
|
||||||
|
+ "varying float z;"
|
||||||
|
+ "void main() {"
|
||||||
|
+ " gl_Position = u_mvp * a_position;"
|
||||||
|
+ " z = gl_Position.z;"
|
||||||
|
+ "}";
|
||||||
|
final static String polygonFragmentShaderZ = ""
|
||||||
|
+ "precision highp float;"
|
||||||
|
+ "uniform vec4 u_color;"
|
||||||
|
+ "varying float z;"
|
||||||
|
+ "void main() {"
|
||||||
|
+ "if (z < 0.0)"
|
||||||
|
+ " gl_FragColor = vec4(z * -1.0, 0.0, 0.0, 1.0)*0.8;"
|
||||||
|
+ "else if (z < 1.0)"
|
||||||
|
+ " gl_FragColor = vec4(0.0, 0.0, z, 1.0)*0.8;"
|
||||||
|
+ "else"
|
||||||
|
+ " gl_FragColor = vec4(0.0, z - 1.0, 0.0, 1.0)*0.8;"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
final static String textVertexShader = ""
|
final static String textVertexShader = ""
|
||||||
+ "precision highp float; "
|
+ "precision highp float; "
|
||||||
+ "attribute vec4 vertex;"
|
+ "attribute vec4 vertex;"
|
||||||
@ -107,11 +129,11 @@ public final class Shaders {
|
|||||||
+ "void main() {"
|
+ "void main() {"
|
||||||
+ " vec4 pos;"
|
+ " vec4 pos;"
|
||||||
+ " if (mod(vertex.x, 2.0) == 0.0){"
|
+ " if (mod(vertex.x, 2.0) == 0.0){"
|
||||||
+ " pos = u_proj * (u_mv * vec4(vertex.xy + vertex.zw * u_scale, 0.0, 1.0));"
|
+ " pos = u_proj * (u_mv * vec4(vertex.xy + vertex.zw * u_scale, 0.02, 1.0));"
|
||||||
+ " } else {"
|
+ " } else {"
|
||||||
// // place as billboard
|
// // place as billboard
|
||||||
+ " vec4 dir = u_mv * vec4(vertex.xy, 0.0, 1.0);"
|
+ " vec4 dir = u_mv * vec4(vertex.xy, 0.0, 1.0);"
|
||||||
+ " pos = u_proj * (dir + vec4(vertex.zw * (coord_scale * u_swidth), 0.0, 0.0));"
|
+ " pos = u_proj * (dir + vec4(vertex.zw * (coord_scale * u_swidth), 0.02, 0.0));"
|
||||||
+ " }"
|
+ " }"
|
||||||
+ " gl_Position = pos;"
|
+ " gl_Position = pos;"
|
||||||
+ " tex_c = tex_coord * div;"
|
+ " tex_c = tex_coord * div;"
|
||||||
@ -170,4 +192,29 @@ public final class Shaders {
|
|||||||
// + "void main() {"
|
// + "void main() {"
|
||||||
// + " gl_FragColor = u_color * 0.5;"
|
// + " gl_FragColor = u_color * 0.5;"
|
||||||
// + "}";
|
// + "}";
|
||||||
|
|
||||||
|
// final static String buildingVertexShader = ""
|
||||||
|
// + "precision mediump float;"
|
||||||
|
// + "uniform mat4 u_mvp;"
|
||||||
|
// + "uniform vec4 u_color;"
|
||||||
|
// + "uniform int u_mode;"
|
||||||
|
// + "uniform float u_scale;"
|
||||||
|
// + "attribute vec4 a_position;"
|
||||||
|
// + "attribute float a_light;"
|
||||||
|
// + "varying vec4 color;"
|
||||||
|
// + "const float ff = 256.0;"
|
||||||
|
// + "const float ffff = 65536.0;"
|
||||||
|
// + "void main() {"
|
||||||
|
// + " gl_Position = u_mvp * vec4(a_position.xy, a_position.z/u_scale, 1.0);"
|
||||||
|
// + " if (u_mode == 0)"
|
||||||
|
// // roof / depth pass
|
||||||
|
// + " color = u_color;"
|
||||||
|
// + " else if (u_mode == 1)"
|
||||||
|
// // sides 1 - use 0xff00
|
||||||
|
// + " color = vec4(u_color.rgb * (a_light / ffff), 0.9);"
|
||||||
|
// + " else"
|
||||||
|
// // sides 2 - use 0x00ff
|
||||||
|
// + " color = vec4(u_color.rgb * fract(a_light/ff), 0.9);"
|
||||||
|
// + "}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user