Skip to content

Commit

Permalink
Fix problems with models and depth precision in ortho camera (interna…
Browse files Browse the repository at this point in the history
…l-2152)

This PR fixes two problems with ortho projection, one when models are close to the camera and the precision was being lost, and the other when using transparent models being culled, (mostly visible with terrain enabled).
  • Loading branch information
jtorresfabra authored and underoot committed Feb 13, 2025
1 parent f5f4b1d commit 9f9249b
Show file tree
Hide file tree
Showing 6 changed files with 463 additions and 6 deletions.
9 changes: 4 additions & 5 deletions 3d-style/render/draw_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,10 @@ function prepareMeshes(transform: Transform, node: ModelNode, modelMatrix: mat4,
}

const centroidPos = vec3.transformMat4([] as any, mesh.centroid, worldViewProjection);
// Filter meshes behind the camera
if (centroidPos[2] > 0.0) {
const transparentMesh: SortedMesh = {mesh, depth: centroidPos[2], modelIndex, worldViewProjection, nodeModelMatrix};
transparentMeshes.push(transparentMesh);
}
// Filter meshes behind the camera if in perspective mode
if (!transform.isOrthographic && centroidPos[2] <= 0.0) continue;
const transparentMesh: SortedMesh = {mesh, depth: centroidPos[2], modelIndex, worldViewProjection, nodeModelMatrix};
transparentMeshes.push(transparentMesh);
}
}
if (node.children) {
Expand Down
4 changes: 3 additions & 1 deletion src/geo/projection/far_z.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function farthestPixelDistanceOnPlane(tr: Transform, pixelsPerMeter: numb
// Due to precision of sources with low maxZoom, content is prone to flickering on zoom above 18.
// Use larger furthest distance also on pitch before the horizon, especially on higher zoom to limit
// the performance and depth range resolution impact.
if (!tr.elevation || tr.elevation.exaggeration() === 0) {
// In case of orthographic projection we don't want to extend the far clip plane as the
// depth is linear and we would be effectively decreasing precision.
if (!tr.isOrthographic && (!tr.elevation || tr.elevation.exaggeration() === 0)) {
furthestDistance *= (1.0 + Math.max(tr.zoom - 17, 0));
}
return Math.min(furthestDistance * 1.01, horizonDistance);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{
"version": 8,
"metadata": {
"test": {
"operations": [
[
"wait",
600
]
],
"width": 512,
"height": 512,
"allowed": 0.0008
}
},
"terrain": {
"source": "mapbox-dem",
"exaggeration": 1
},
"lights": [
{
"type": "ambient",
"id": "environment",
"properties": {
"color": "rgba(255.0, 255.0, 255.0, 1.0)",
"intensity": 0.5
}
},
{
"type": "directional",
"id": "sun_light",
"properties": {
"color": "rgba(255.0, 255.0, 255.0, 1.0)",
"intensity": 0.5,
"cast-shadows": false
}
}
],
"sources": {
"mapbox-dem": {
"type": "raster-dem",
"maxzoom": 14,
"tileSize": 512,
"tiles": ["local://models/dem/14-8847-5550.terrain-512.png"]
},
"mapbox": {
"type": "vector",
"maxzoom": 16,
"tiles": [
"local://tiles/{z}-{x}-{y}.mvt"
]
},
"model": {
"type": "model",
"models": {
"model-1" : {
"uri": "local://models/cubes-depth.gltf",
"position": [14.3946, 50.0834],
"orientation": [0, 0, 0]
}
}
}
},
"pitch": 0,
"zoom": 18.0,
"bearing": 0,
"center": [
14.3946,
50.0834
],
"camera": {
"camera-projection": "orthographic"
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "lightgray"
}
},
{
"id": "land",
"type": "fill",
"source": "mapbox",
"source-layer": "water",
"paint": {
"fill-color": "lightblue"
}
},
{
"id": "road",
"type": "line",
"source": "mapbox",
"source-layer": "road",
"paint": {
"line-color": "lightyellow",
"line-width": 10
}
},
{
"id": "extrusion",
"type": "fill-extrusion",
"source": "mapbox",
"source-layer": "building",
"paint": {
"fill-extrusion-color": "white",
"fill-extrusion-height": ["get", "height"]
}
},
{
"filter": [
"match",
[
"get",
"class"
],
[
"motorway",
"primary",
"secondary",
"street",
"street_limited",
"tertiary",
"trunk"
],
true,
false
],
"id": "road-label-simple",
"layout": {
"symbol-placement": "line",
"text-field": [
"format",
[
"coalesce",
[
"get",
"name_en"
],
[
"get",
"name"
]
],
{}
],
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
],
"text-letter-spacing": 0.009999999776482582,
"text-max-angle": 30.0,
"text-padding": 1.0,
"text-pitch-alignment": "viewport",
"text-rotation-alignment": "map",
"text-size": [
"interpolate",
[
"linear"
],
[
"zoom"
],
10.0,
[
"match",
[
"get",
"class"
],
[
"motorway",
"primary",
"secondary",
"tertiary",
"trunk"
],
10.0,
9.0
],
18.0,
[
"match",
[
"get",
"class"
],
[
"motorway",
"primary",
"secondary",
"tertiary",
"trunk"
],
16.0,
14.0
]
]
},
"minzoom": 12.0,
"paint": {
"text-color": [
"rgba",
154.0,
121.00000762939453,
55.000003814697269,
1.0
],
"text-halo-color": [
"rgba",
255.0,
255.0,
255.0,
1.0
],
"text-halo-width": 1.0
},
"source": "mapbox",
"source-layer": "road",
"type": "symbol"
},
{
"id": "model",
"type": "model",
"source": "model",
"paint" : {
"model-scale" : [4, 4, 4]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9f9249b

Please sign in to comment.