Skip to content

Commit

Permalink
[MAPS3D-847] Add support for landmark shadows (#534)
Browse files Browse the repository at this point in the history
* Add shadow support for landmarks

Tests still need conflation to work as expected

* Add shadows render test
  • Loading branch information
jtorresfabra authored May 9, 2023
1 parent 1d15622 commit 6d3549c
Show file tree
Hide file tree
Showing 14 changed files with 1,359 additions and 9 deletions.
18 changes: 9 additions & 9 deletions 3d-style/render/draw_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,15 @@ function prepareMeshes(transform: Transform, node: Node, modelMatrix: Mat4, proj
}
}

function drawShadowCaster(sortedMesh: SortedMesh, painter: Painter, layer: ModelStyleLayer) {
function drawShadowCaster(mesh: Mesh, matrix: Mat4, painter: Painter, layer: ModelStyleLayer) {
const shadowRenderer = painter.shadowRenderer;
if (!shadowRenderer) return;
const depthMode = shadowRenderer.getShadowPassDepthMode();
const colorMode = shadowRenderer.getShadowPassColorMode();
const shadowMatrix = shadowRenderer.calculateShadowPassMatrixFromMatrix(sortedMesh.nodeModelMatrix);
const shadowMatrix = shadowRenderer.calculateShadowPassMatrixFromMatrix(matrix);
const uniformValues = modelDepthUniformValues(shadowMatrix);
const definesValues = ['DEPTH_TEXTURE'];
const program = painter.useProgram('modelDepth', null, ((definesValues: any): DynamicDefinesType[]));
const mesh = sortedMesh.mesh;
const context = painter.context;
program.draw(context, context.gl.TRIANGLES, depthMode, StencilMode.disabled, colorMode, CullFaceMode.backCCW,
uniformValues, layer.id, mesh.vertexBuffer, mesh.indexBuffer, mesh.segments, layer.paint, painter.transform.zoom,
Expand Down Expand Up @@ -329,11 +328,11 @@ function drawModels(painter: Painter, sourceCache: SourceCache, layer: ModelStyl

if (painter.renderPass === 'shadow') {
for (const opaqueMesh of opaqueMeshes) {
drawShadowCaster(opaqueMesh, painter, layer);
drawShadowCaster(opaqueMesh.mesh, opaqueMesh.nodeModelMatrix, painter, layer);
}
// Draw transparent sorted meshes
for (const transparentMesh of transparentMeshes) {
drawShadowCaster(transparentMesh, painter, layer);
drawShadowCaster(transparentMesh.mesh, transparentMesh.nodeModelMatrix, painter, layer);
}
// Finish the render pass
return;
Expand Down Expand Up @@ -487,17 +486,18 @@ function drawBatchedNode(node: Node, modelTraits: number, painter: Painter, laye
const definesValues = [];
const dynamicBuffers = [];
setupMeshDraw(definesValues, dynamicBuffers, mesh, painter);
const isShadowPass = painter.renderPass === 'shadow';
if (isShadowPass) {
return;
}

if (!(modelTraits & ModelTraits.HasMapboxMeshFeatures)) {
definesValues.push('DIFFUSE_SHADED');
}

const modelMatrix = [...tileMatrix];
mat4.multiply(modelMatrix, modelMatrix, node.matrix);
const isShadowPass = painter.renderPass === 'shadow';
if (isShadowPass) {
drawShadowCaster(mesh, modelMatrix, painter, layer);
return;
}

let fogMatrixArray = null;
if (painter.style.fog) {
Expand Down
4 changes: 4 additions & 0 deletions test/ignores/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ const skip = [
// terrain model tests are flaky in CI
"render-tests/model-layer/fill-extrusion--default-terrain-opacity",
"render-tests/model-layer/fill-extrusion--default-terrain",

// Conflation needs to be implemented first
"render-tests/model-layer/landmark-part-styling-munich-museum",
"render-tests/model-layer/landmark-part-styling-roughness",
];

export default {todo, skip};
3 changes: 3 additions & 0 deletions test/ignores/webgl1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const skip = [
"render-tests/model-layer/lighting-3d-mode/model-shadow",
"render-tests/model-layer/ground-shadow-fog",
"render-tests/model-layer/landmark-mbx",
"render-tests/model-layer/landmark-mbx-shadows",
"render-tests/model-layer/landmark-emission-strength",
"render-tests/model-layer/landmark-part-styling-munich-museum",
"render-tests/model-layer/landmark-part-styling-roughness",
"render-tests/lighting-3d-mode/fill-extrusion/flood-light/zero-radius",
"render-tests/lighting-3d-mode/fill-extrusion/flood-light/saturation",
"render-tests/lighting-3d-mode/fill-extrusion/flood-light/transparency",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,60 @@
{
"version": 8,
"metadata": {
"test": {
"allowed": 0.00025,
"width": 1024,
"height": 1024
}
},
"lights": [
{
"type": "ambient",
"id": "test_ambient",
"properties": {
"color": "rgba(255, 255, 255, 1)",
"intensity": 0.2
}
},
{
"type": "directional",
"id": "test_directional",
"properties": {
"cast-shadows" : true,
"color": "rgba(255, 255, 255, 1)",
"intensity": 0.7
}
}
],
"sources": {
"file-system-tiles": {
"type": "batched-model",
"maxzoom": 14,
"tiles": [
"local://models/landmark/mbx/{x}-{y}-{z}.b3dm"
]
}
},
"pitch": 70,
"zoom": 17.85,
"bearing": 126,
"center": [
11.5605,
48.1762
],
"layers": [
{
"type": "background",
"paint": {
"background-color": "lightgray"
},
"id": "land"
},
{
"minzoom": 14.0,
"type": "model",
"source": "file-system-tiles",
"id": "landmarks"
}
]
}
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 6d3549c

Please sign in to comment.