From 48c1e9f87ad5007b021208dfce094b55e251a1ee Mon Sep 17 00:00:00 2001 From: Xiaoji Chen Date: Tue, 19 Mar 2024 08:12:51 -0700 Subject: [PATCH] render tests --- modules/core/src/lib/layer-manager.ts | 23 ++-- modules/core/src/passes/shadow-pass.ts | 5 +- modules/core/src/shaderlib/shadow/shadow.ts | 4 +- .../test-utils/src/snapshot-test-runner.ts | 6 +- test/render/test-cases/effects.js | 6 +- test/render/test-cases/index.js | 2 +- test/render/test-cases/terrain-layer.js | 121 +++++++++--------- 7 files changed, 87 insertions(+), 80 deletions(-) diff --git a/modules/core/src/lib/layer-manager.ts b/modules/core/src/lib/layer-manager.ts index 221f185a3a7..ec5c7c9c45e 100644 --- a/modules/core/src/lib/layer-manager.ts +++ b/modules/core/src/lib/layer-manager.ts @@ -74,6 +74,8 @@ export default class LayerManager { private _needsUpdate: string | false = false; private _nextLayers: LayersList | null = null; private _debug: boolean = false; + // This flag is sepaprate from _needsUpdate because it can be set during an update and should trigger another full update + private _defaultShaderModulesChanged: boolean = false; /** * @param device @@ -154,6 +156,9 @@ export default class LayerManager { // New layers array may be the same as the old one if `setProps` is called by React return 'layers changed'; } + if (this._defaultShaderModulesChanged) { + return 'shader modules changed'; + } return this._needsUpdate; } @@ -245,10 +250,7 @@ export default class LayerManager { const {defaultShaderModules} = this.context; if (!defaultShaderModules.find(m => m.name === module.name)) { defaultShaderModules.push(module); - for (const layer of this.layers) { - layer.setNeedsUpdate(); - layer.setChangeFlags({extensionsChanged: true}); - } + this._defaultShaderModulesChanged = true; } } @@ -258,10 +260,7 @@ export default class LayerManager { const i = defaultShaderModules.findIndex(m => m.name === module.name); if (i >= 0) { defaultShaderModules.splice(i, 1); - for (const layer of this.layers) { - layer.setNeedsUpdate(); - layer.setChangeFlags({extensionsChanged: true}); - } + this._defaultShaderModulesChanged = true; } } @@ -283,6 +282,14 @@ export default class LayerManager { } } + if (this._defaultShaderModulesChanged) { + for (const layer of oldLayers) { + layer.setNeedsUpdate(); + layer.setChangeFlags({extensionsChanged: true}); + } + this._defaultShaderModulesChanged = false; + } + // Allocate array for generated layers const generatedLayers: Layer[] = []; diff --git a/modules/core/src/passes/shadow-pass.ts b/modules/core/src/passes/shadow-pass.ts index 3483e0551c5..2d963260097 100644 --- a/modules/core/src/passes/shadow-pass.ts +++ b/modules/core/src/passes/shadow-pass.ts @@ -55,8 +55,7 @@ export default class ShadowPass extends LayersPass { { depthRange: [0, 1], depthTest: true, - blend: false, - clearColor: [1, 1, 1, 1] + blend: false }, () => { // @ts-expect-error TODO - assuming WebGL context @@ -69,7 +68,7 @@ export default class ShadowPass extends LayersPass { target.resize({width, height}); } - super.render({...params, target, pass: 'shadow'}); + super.render({...params, target, pass: 'shadow', clearColor: [1, 1, 1, 1]}); } ); } diff --git a/modules/core/src/shaderlib/shadow/shadow.ts b/modules/core/src/shaderlib/shadow/shadow.ts index 4af03519264..c92710e4802 100644 --- a/modules/core/src/shaderlib/shadow/shadow.ts +++ b/modules/core/src/shaderlib/shadow/shadow.ts @@ -190,7 +190,9 @@ function createShadowUniforms( if (!shadowEnabled || !opts.shadowMatrices || !opts.shadowMatrices.length) { return { shadow_uDrawShadowMap: false, - shadow_uUseShadowMap: false + shadow_uUseShadowMap: false, + shadow_uShadowMap0: opts.dummyShadowMap, + shadow_uShadowMap1: opts.dummyShadowMap }; } const uniforms = { diff --git a/modules/test-utils/src/snapshot-test-runner.ts b/modules/test-utils/src/snapshot-test-runner.ts index c1f49ba4b09..1d015d1e7d8 100644 --- a/modules/test-utils/src/snapshot-test-runner.ts +++ b/modules/test-utils/src/snapshot-test-runner.ts @@ -64,7 +64,11 @@ const DEFAULT_TEST_CASE: SnapshotTestCase = { // eslint-disable-line }, onAfterRender: ({deck, layers, done}) => { - if (layers.every(layer => layer.isLoaded)) { + if ( + // @ts-expect-error accessing private + !deck.layerManager?.needsUpdate() && + layers.every(layer => layer.isLoaded) + ) { done(); // eslint-disable-line } }, diff --git a/test/render/test-cases/effects.js b/test/render/test-cases/effects.js index 5110cbeeba2..81c9d934a0e 100644 --- a/test/render/test-cases/effects.js +++ b/test/render/test-cases/effects.js @@ -3,8 +3,7 @@ import {zoomBlur, vignette} from '@luma.gl/shadertools'; import {hexagons, points} from 'deck.gl-test/data'; import {ScatterplotLayer, SolidPolygonLayer, ColumnLayer} from '@deck.gl/layers'; -// TODO v9 -// import {SimpleMeshLayer} from '@deck.gl/mesh-layers'; +import {SimpleMeshLayer} from '@deck.gl/mesh-layers'; import {MaskExtension} from '@deck.gl/extensions'; import {CubeGeometry} from '@luma.gl/engine'; @@ -22,8 +21,6 @@ const MASK_POLYGON = [ ]; export default [ - // TODO v9 - /* { name: 'shadow-effect', effects: [ @@ -75,7 +72,6 @@ export default [ ], goldenImage: './test/render/golden-images/shadow-effect.png' }, - */ ...[true, false].map(maskInverted => ({ name: `mask-effect${maskInverted ? '-inverted' : ''}`, viewState: { diff --git a/test/render/test-cases/index.js b/test/render/test-cases/index.js index 85adee65d2b..4fd858e5299 100644 --- a/test/render/test-cases/index.js +++ b/test/render/test-cases/index.js @@ -59,6 +59,6 @@ export default [].concat( effectsTests, transitionTests, terrainLayerTests, - // collisionFilterExtensionTests + collisionFilterExtensionTests, dataFilterExtensionTests ); diff --git a/test/render/test-cases/terrain-layer.js b/test/render/test-cases/terrain-layer.js index ed84de957e7..97ccd90d562 100644 --- a/test/render/test-cases/terrain-layer.js +++ b/test/render/test-cases/terrain-layer.js @@ -33,66 +33,65 @@ export default [ }) ], goldenImage: './test/render/golden-images/terrain-layer.png' + }, + { + name: 'terrain-extension-drape', + viewState: { + longitude: -122.45, + latitude: 37.75, + zoom: 11.5, + pitch: 60, + bearing: 0 + }, + layers: [ + new TerrainLayer({ + elevationData: ELEVATION_DATA, + texture: TEXTURE, + elevationDecoder: DECODER, + operation: 'draw+terrain' + }), + new GeoJsonLayer({ + data: choropleths, + getLineWidth: 50, + getFillColor: (_, {index}) => [(index % 3) * 80, (index % 2) * 128, 128, 200], + extensions: [new TerrainExtension()] + }) + ], + goldenImage: './test/render/golden-images/terrain-extension-drape.png' + }, + { + name: 'terrain-extension-offset', + viewState: { + longitude: -122.45, + latitude: 37.75, + zoom: 11.5, + pitch: 60, + bearing: 0 + }, + layers: [ + new TerrainLayer({ + elevationData: ELEVATION_DATA, + texture: TEXTURE, + elevationDecoder: DECODER, + operation: 'terrain' + }), + new GeoJsonLayer({ + data: choropleths, + getLineWidth: 50, + getFillColor: (_, {index}) => [(index % 3) * 60 + 60, (index % 2) * 64 + 128, 200], + extensions: [new TerrainExtension()] + }), + new IconLayer({ + data: points, + iconAtlas: './test/data/icon-atlas.png', + iconMapping, + sizeScale: 12, + getPosition: d => d.COORDINATES, + getIcon: d => 'marker-warning', + getSize: d => (d.PLACEMENT === 'SW' ? 0 : 2), + extensions: [new TerrainExtension()] + }) + ], + goldenImage: './test/render/golden-images/terrain-extension-offset.png' } - // TODO - v9 TerrainExtension - // { - // name: 'terrain-extension-drape', - // viewState: { - // longitude: -122.45, - // latitude: 37.75, - // zoom: 11.5, - // pitch: 60, - // bearing: 0 - // }, - // layers: [ - // new TerrainLayer({ - // elevationData: ELEVATION_DATA, - // texture: TEXTURE, - // elevationDecoder: DECODER, - // operation: 'draw+terrain' - // }), - // new GeoJsonLayer({ - // data: choropleths, - // getLineWidth: 50, - // getFillColor: (_, {index}) => [(index % 3) * 80, (index % 2) * 128, 128, 200], - // extensions: [new TerrainExtension()] - // }) - // ], - // goldenImage: './test/render/golden-images/terrain-extension-drape.png' - // }, - // { - // name: 'terrain-extension-offset', - // viewState: { - // longitude: -122.45, - // latitude: 37.75, - // zoom: 11.5, - // pitch: 60, - // bearing: 0 - // }, - // layers: [ - // new TerrainLayer({ - // elevationData: ELEVATION_DATA, - // texture: TEXTURE, - // elevationDecoder: DECODER, - // operation: 'terrain' - // }), - // new GeoJsonLayer({ - // data: choropleths, - // getLineWidth: 50, - // getFillColor: (_, {index}) => [(index % 3) * 60 + 60, (index % 2) * 64 + 128, 200], - // extensions: [new TerrainExtension()] - // }), - // new IconLayer({ - // data: points, - // iconAtlas: './test/data/icon-atlas.png', - // iconMapping, - // sizeScale: 12, - // getPosition: d => d.COORDINATES, - // getIcon: d => 'marker-warning', - // getSize: d => (d.PLACEMENT === 'SW' ? 0 : 2), - // extensions: [new TerrainExtension()] - // }) - // ], - // goldenImage: './test/render/golden-images/terrain-extension-offset.png' - // } ];