Created
April 15, 2020 14:28
-
-
Save astojilj/abd2fd384e084ec5233cc09e59deab76 to your computer and use it in GitHub Desktop.
depth-development-support.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/render/painter.js b/src/render/painter.js | |
index 55fabcf62..4cb3fdeb1 100644 | |
--- a/src/render/painter.js | |
+++ b/src/render/painter.js | |
@@ -645,7 +645,7 @@ class Painter { | |
const key = `${name}${programConfiguration ? programConfiguration.cacheKey : ''}${this._showOverdrawInspector ? '/overdraw' : ''} | |
${terrain ? '/terrain' : ''}${rtt ? '/rtt' : ''}`; | |
if (!this.cache[key]) { | |
- this.cache[key] = new Program(this.context, shaders[name], programConfiguration, programUniforms[name], this._showOverdrawInspector, terrain, rtt); | |
+ this.cache[key] = new Program(this.context, shaders[name], programConfiguration, programUniforms[name], this._showOverdrawInspector, terrain, rtt, name === 'terrainRaster'); | |
} | |
return this.cache[key]; | |
} | |
diff --git a/src/render/program.js b/src/render/program.js | |
index fce581ee0..81eb4f319 100644 | |
--- a/src/render/program.js | |
+++ b/src/render/program.js | |
@@ -38,7 +38,8 @@ class Program<Us: UniformBindings> { | |
fixedUniforms: (Context, UniformLocations) => Us, | |
showOverdrawInspector: boolean, | |
terrain: ?boolean, | |
- renderingToTexture: ?boolean) { | |
+ renderingToTexture: ?boolean, | |
+ debugDepth: ?boolean) { | |
const gl = context.gl; | |
this.program = gl.createProgram(); | |
@@ -52,6 +53,9 @@ class Program<Us: UniformBindings> { | |
if (renderingToTexture) { | |
defines.push('#define RENDER_TO_TEXTURE;'); | |
} | |
+ if (debugDepth) { | |
+ defines.push('#define DEBUG_DEPTH;'); | |
+ } | |
const fragmentSource = defines.concat(prelude.fragmentSource, source.fragmentSource).join('\n'); | |
const vertexSource = defines.concat(prelude.vertexSource, preludeTerrain.vertexSource, source.vertexSource).join('\n'); | |
diff --git a/src/shaders/terrain_raster.fragment.glsl b/src/shaders/terrain_raster.fragment.glsl | |
index 10029f61c..594bf0e0b 100644 | |
--- a/src/shaders/terrain_raster.fragment.glsl | |
+++ b/src/shaders/terrain_raster.fragment.glsl | |
@@ -1,9 +1,16 @@ | |
uniform sampler2D u_image0; | |
varying vec2 v_pos0; | |
+#ifdef DEBUG_DEPTH | |
+varying vec4 v_color; | |
+#endif | |
+ | |
void main() { | |
gl_FragColor = texture2D(u_image0, v_pos0); | |
#ifdef OVERDRAW_INSPECTOR | |
gl_FragColor = vec4(1.0); | |
#endif | |
+#ifdef DEBUG_DEPTH | |
+ gl_FragColor = v_color; | |
+#endif | |
} | |
diff --git a/src/shaders/terrain_raster.vertex.glsl b/src/shaders/terrain_raster.vertex.glsl | |
index 9ea9396c2..b5eb0e264 100644 | |
--- a/src/shaders/terrain_raster.vertex.glsl | |
+++ b/src/shaders/terrain_raster.vertex.glsl | |
@@ -8,10 +8,26 @@ varying vec2 v_pos0; | |
const float skirtOffset = 24575.0; | |
+varying float v_depth; | |
+ | |
+#ifdef DEBUG_DEPTH | |
+varying vec4 v_color; | |
+#endif | |
+ | |
void main() { | |
v_pos0 = a_texture_pos / 8192.0; | |
float skirt = float(a_pos.x >= skirtOffset); | |
float elevation = elevation(a_texture_pos) - skirt * u_skirt_height; | |
vec2 decodedPos = a_pos - vec2(skirt * skirtOffset, 0.0); | |
gl_Position = u_matrix * vec4(decodedPos, elevation, 1.0); | |
+ v_depth = gl_Position.z / gl_Position.w; | |
+ | |
+#ifdef DEBUG_DEPTH | |
+ vec3 coord = gl_Position.xyz / gl_Position.w; | |
+ if (!isOccluded(gl_Position)) { | |
+ v_color = texture2D(u_depth, (coord.xy + 1.0) * 0.5); | |
+ } else { | |
+ v_color = vec4(0.0); | |
+ } | |
+#endif | |
} | |
diff --git a/src/terrain/draw_terrain_raster.js b/src/terrain/draw_terrain_raster.js | |
index 23be49365..c164e3900 100644 | |
--- a/src/terrain/draw_terrain_raster.js | |
+++ b/src/terrain/draw_terrain_raster.js | |
@@ -46,7 +46,7 @@ function drawTerrainRaster(painter: Painter, terrain: Terrain, sourceCache: Sour | |
tile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST); | |
const uniformValues = terrainRasterUniformValues(coord.posMatrix, painter.transform.zoom); | |
- terrain.setupElevationDraw(tile, program); | |
+ terrain.setupElevationDraw(tile, program, true); | |
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.backCCW, | |
uniformValues, "terrain_raster", terrain.gridBuffer, terrain.gridIndexBuffer, terrain.gridSegments); | |
diff --git a/src/ui/map.js b/src/ui/map.js | |
index c05c5f48e..053140eba 100755 | |
--- a/src/ui/map.js | |
+++ b/src/ui/map.js | |
@@ -109,7 +109,7 @@ const defaultMaxZoom = 22; | |
// the default values, but also the valid range | |
const defaultMinPitch = 0; | |
-const defaultMaxPitch = 60; | |
+const defaultMaxPitch = 83; | |
const defaultOptions = { | |
center: [0, 0], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment