From 8dfc56954da773eabf3a0bdcbc7341136322cc71 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Wed, 18 Sep 2024 09:40:37 +0200 Subject: [PATCH 1/7] Remove unneeded updateModuleSettings --- modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts b/modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts index 258c0301e9a..3ea2f082dc9 100644 --- a/modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts +++ b/modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts @@ -615,7 +615,6 @@ export default class HeatmapLayer< const moduleSettings = this.getModuleSettings(); this._setModelAttributes(weightsTransform.model, attributes); weightsTransform.model.setVertexCount(this.getNumInstances()); - weightsTransform.model.updateModuleSettings(moduleSettings); const weightProps: WeightProps = { radiusPixels, From cc4cf288a8608e491e743598daf0adaa5bdaed37 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Wed, 18 Sep 2024 10:02:35 +0200 Subject: [PATCH 2/7] Remove setModuleParameters --- modules/core/src/lib/layer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index 44e3459fc88..c7e800f5762 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -1083,7 +1083,6 @@ export default abstract class Layer extends Component< // Do not pass picking module to avoid crash // TODO remove `setModuleParameters` from codebase const {picking: _, ...rest} = moduleParameters; - this.setModuleParameters(rest); const { // shadow From 29f4f37a6de4e114530f833f35ff6e9aa4661770 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Wed, 18 Sep 2024 14:44:15 +0200 Subject: [PATCH 3/7] Fix test --- modules/core/src/lib/layer.ts | 20 +++++++++----------- test/modules/extensions/fp64.spec.ts | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index c7e800f5762..144e8682b5a 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -1080,10 +1080,6 @@ export default abstract class Layer extends Component< // @ts-expect-error material is not a Layer prop const {material, modelMatrix} = this.props; - // Do not pass picking module to avoid crash - // TODO remove `setModuleParameters` from codebase - const {picking: _, ...rest} = moduleParameters; - const { // shadow shadowEnabled, @@ -1128,6 +1124,14 @@ export default abstract class Layer extends Component< terrainSkipRender }; + const projectProps = { + viewport, + devicePixelRatio, + modelMatrix, + coordinateSystem, + coordinateOrigin + } as ProjectProps; + this.setShaderModuleProps({ // TODO Revisit whether this is necessary once all layers ported to UBO shadow: shadowProps, @@ -1137,13 +1141,7 @@ export default abstract class Layer extends Component< phongMaterial: material, gouraudMaterial: material, picking: {isActive, isAttribute} as PickingProps, - project: { - viewport, - devicePixelRatio, - modelMatrix, - coordinateSystem, - coordinateOrigin - } as ProjectProps + project: projectProps }); } diff --git a/test/modules/extensions/fp64.spec.ts b/test/modules/extensions/fp64.spec.ts index 463aa43ed46..c45d5a7da69 100644 --- a/test/modules/extensions/fp64.spec.ts +++ b/test/modules/extensions/fp64.spec.ts @@ -2,7 +2,7 @@ import test from 'tape-promise/tape'; import {Fp64Extension} from '@deck.gl/extensions'; import {COORDINATE_SYSTEM} from '@deck.gl/core'; import {ScatterplotLayer} from '@deck.gl/layers'; -import {testLayer} from '@deck.gl/test-utils'; +import {getLayerUniforms, testLayer} from '@deck.gl/test-utils'; test('Fp64Extension', t => { const testCases = [ @@ -22,7 +22,7 @@ test('Fp64Extension', t => { extensions: [new Fp64Extension()] }, onAfterUpdate: ({layer}) => { - const {uniforms} = layer.state.model; + const uniforms = getLayerUniforms(layer); t.ok(uniforms.viewProjectionMatrix, 'has fp64 uniforms'); t.ok(uniforms.viewProjectionMatrix64Low, 'has fp64 uniforms'); } From 765ce6b952dd291072ae76601869e0f7157dcd3a Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Wed, 18 Sep 2024 15:26:37 +0200 Subject: [PATCH 4/7] Workaround fp64 not useing UBO --- modules/core/src/lib/layer.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index 144e8682b5a..afa98e6fad8 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -341,7 +341,8 @@ export default abstract class Layer extends Component< /** Update shader module parameters */ setModuleParameters(moduleParameters: any): void { for (const model of this.getModels()) { - model.updateModuleSettings(moduleParameters); + // HACK as fp64 is not yet ported to UBO + model.uniforms = {ONE: 1}; } } @@ -1080,6 +1081,8 @@ export default abstract class Layer extends Component< // @ts-expect-error material is not a Layer prop const {material, modelMatrix} = this.props; + this.setModuleParameters({}); + const { // shadow shadowEnabled, From 92c6091ce885bf187012f990871f67b25a523f13 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Wed, 18 Sep 2024 15:26:52 +0200 Subject: [PATCH 5/7] Don't rely of moduleParameters --- modules/extensions/src/fp64/fp64-extension.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/extensions/src/fp64/fp64-extension.ts b/modules/extensions/src/fp64/fp64-extension.ts index 9912758d9dd..6ba81633e51 100644 --- a/modules/extensions/src/fp64/fp64-extension.ts +++ b/modules/extensions/src/fp64/fp64-extension.ts @@ -42,10 +42,7 @@ export default class Fp64Extension extends LayerExtension { } draw(this: Layer, params: any, extension: this): void { - const {moduleParameters} = params; - if (moduleParameters) { - const {viewport} = moduleParameters; - this.setShaderModuleProps({project64: {viewport}}); - } + const {viewport} = params.context; + this.setShaderModuleProps({project64: {viewport}}); } } From cbf20d87373f53207d0d6c1b6d859f267aec0ae2 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Wed, 18 Sep 2024 15:55:00 +0200 Subject: [PATCH 6/7] Pass through maskProps --- modules/core/src/lib/layer.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index afa98e6fad8..a07363796b9 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -1084,6 +1084,10 @@ export default abstract class Layer extends Component< this.setModuleParameters({}); const { + // mask + maskChannels, + maskMap, + maskSources, // shadow shadowEnabled, drawToShadowMap, @@ -1105,6 +1109,12 @@ export default abstract class Layer extends Component< lightSources } = moduleParameters; + const maskProps = { + maskChannels, + maskMap, + maskSources + }; + const shadowProps = { viewport, shadowEnabled, @@ -1137,6 +1147,7 @@ export default abstract class Layer extends Component< this.setShaderModuleProps({ // TODO Revisit whether this is necessary once all layers ported to UBO + mask: maskProps, shadow: shadowProps, terrain: terrainProps, layer: {opacity}, From 884c9db3c64040506116f45ac4cd1b9c80b4f57a Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Thu, 26 Sep 2024 11:28:40 +0200 Subject: [PATCH 7/7] Use Matrix4Like --- modules/core/src/lib/layer.ts | 2 +- .../shaderlib/project/viewport-uniforms.ts | 21 +++++++++---------- modules/core/src/types/layer-props.ts | 3 ++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index 9a3d75bf354..ed7db558791 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -1155,7 +1155,7 @@ export default abstract class Layer extends Component< lighting: lightSources, phongMaterial: material, gouraudMaterial: material, - picking: {isActive, isAttribute} as PickingProps, + picking: {isActive, isAttribute} as const satisfies PickingProps, project: projectProps }); } diff --git a/modules/core/src/shaderlib/project/viewport-uniforms.ts b/modules/core/src/shaderlib/project/viewport-uniforms.ts index 81e09aa869b..e2797de3f5d 100644 --- a/modules/core/src/shaderlib/project/viewport-uniforms.ts +++ b/modules/core/src/shaderlib/project/viewport-uniforms.ts @@ -19,8 +19,7 @@ // THE SOFTWARE. /* eslint-disable complexity, camelcase */ -import {mat4, vec4} from '@math.gl/core'; -import type {NumberArray16} from '@math.gl/types'; +import {mat4, Matrix4Like, vec4} from '@math.gl/core'; import {COORDINATE_SYSTEM, PROJECTION_MODE} from '../../lib/constants'; @@ -35,8 +34,8 @@ type Vec4 = [number, number, number, number]; // To quickly set a vector to zero const ZERO_VECTOR: Vec4 = [0, 0, 0, 0]; // 4x4 matrix that drops 4th component of vector -const VECTOR_TO_POINT_MATRIX: NumberArray16 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]; -const IDENTITY_MATRIX: NumberArray16 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; +const VECTOR_TO_POINT_MATRIX: Matrix4Like = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]; +const IDENTITY_MATRIX: Matrix4Like = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; const DEFAULT_PIXELS_PER_UNIT2: Vec3 = [0, 0, 0]; const DEFAULT_COORDINATE_ORIGIN: Vec3 = [0, 0, 0]; @@ -127,8 +126,8 @@ function calculateMatrixAndOffset( coordinateSystem: CoordinateSystem, coordinateOrigin: Vec3 ): { - viewMatrix: NumberArray16; - viewProjectionMatrix: NumberArray16; + viewMatrix: Matrix4Like; + viewProjectionMatrix: Matrix4Like; projectionCenter: Vec4; originCommon: Vec4; cameraPosCommon: Vec3; @@ -177,8 +176,8 @@ function calculateMatrixAndOffset( } return { - viewMatrix: viewMatrix as NumberArray16, - viewProjectionMatrix: viewProjectionMatrix as NumberArray16, + viewMatrix: viewMatrix as Matrix4Like, + viewProjectionMatrix: viewProjectionMatrix as Matrix4Like, projectionCenter, originCommon, cameraPosCommon, @@ -209,8 +208,8 @@ export type ProjectUniforms = { scale: number; wrapLongitude: boolean; - viewProjectionMatrix: NumberArray16; - modelMatrix: NumberArray16; + viewProjectionMatrix: Matrix4Like; + modelMatrix: Matrix4Like; // This is for lighting calculations cameraPosition: Vec3; @@ -219,7 +218,7 @@ export type ProjectUniforms = { export type ProjectProps = { viewport: Viewport; devicePixelRatio?: number; - modelMatrix?: NumberArray16 | null; + modelMatrix?: Matrix4Like | null; coordinateSystem?: CoordinateSystem; coordinateOrigin?: Vec3; autoWrapLongitude?: boolean; diff --git a/modules/core/src/types/layer-props.ts b/modules/core/src/types/layer-props.ts index 2d8005561bd..3b015359c12 100644 --- a/modules/core/src/types/layer-props.ts +++ b/modules/core/src/types/layer-props.ts @@ -10,6 +10,7 @@ import type {Texture, TextureProps} from '@luma.gl/core'; import type {Buffer, Parameters} from '@luma.gl/core'; import type {Loader} from '@loaders.gl/loader-utils'; import type {LightingModuleSettings} from '../shaderlib/index'; +import type {Matrix4Like} from '@math.gl/core'; export type LayerData = | Iterable @@ -169,7 +170,7 @@ export type LayerProps = { /** * A 4x4 matrix to transform local coordianates to the world space. */ - modelMatrix?: NumericArray | null; + modelMatrix?: Matrix4Like | null; /** * (Geospatial only) normalize geometries that cross the 180th meridian. Default false. */