From 91d5070dcbde72f2ed81bf4b0bce2310272ea9de Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Thu, 10 Oct 2024 15:11:10 +0200 Subject: [PATCH 01/10] Improve types --- modules/core/src/index.ts | 11 ++- modules/core/src/lib/layer.ts | 4 +- modules/core/src/passes/layers-pass.ts | 70 ++++++++++++------- .../src/terrain/terrain-picking-pass.ts | 8 ++- 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/modules/core/src/index.ts b/modules/core/src/index.ts index b76c565f2dd..ff1d8be3d6b 100644 --- a/modules/core/src/index.ts +++ b/modules/core/src/index.ts @@ -23,7 +23,10 @@ export {default as _SunLight} from './effects/lighting/sun-light'; export {default as PostProcessEffect} from './effects/post-process-effect'; // Passes -export {default as _LayersPass} from './passes/layers-pass'; +export { + default as _LayersPass, + isDrawableLayerParameters as _isDrawableLayerParameters +} from './passes/layers-pass'; export {default as _PickLayersPass} from './passes/pick-layers-pass'; // Experimental Pure JS (non-React) bindings @@ -120,7 +123,11 @@ export type { TextureSource, Material } from './types/layer-props'; -export type {FilterContext} from './passes/layers-pass'; +export type { + DrawableLayerParameters, + DrawLayerParameters, + FilterContext +} from './passes/layers-pass'; export type {PickingInfo, GetPickingInfoParams} from './lib/picking/pick-info'; export type {ConstructorOf as _ConstructorOf} from './types/types'; export type {BinaryAttribute} from './lib/attribute/attribute'; diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index f67bc6be166..3aba211e22d 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -3,7 +3,7 @@ // Copyright (c) vis.gl contributors /* eslint-disable react/no-direct-mutation-state */ -import {Buffer, TypedArray} from '@luma.gl/core'; +import {Buffer, RenderPipelineParameters, TypedArray} from '@luma.gl/core'; import {WebGLDevice} from '@luma.gl/webgl'; import {COORDINATE_SYSTEM} from './constants'; import AttributeManager from './attribute/attribute-manager'; @@ -1042,7 +1042,7 @@ export default abstract class Layer extends Component< renderPass: RenderPass; shaderModuleProps: any; uniforms: any; - parameters: any; + parameters: RenderPipelineParameters; }): void { this._updateAttributeTransition(); diff --git a/modules/core/src/passes/layers-pass.ts b/modules/core/src/passes/layers-pass.ts index 816a1705337..4a099deef58 100644 --- a/modules/core/src/passes/layers-pass.ts +++ b/modules/core/src/passes/layers-pass.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import type {Device, RenderPassParameters} from '@luma.gl/core'; +import type {Device, RenderPassParameters, RenderPipelineParameters} from '@luma.gl/core'; import type {Framebuffer, RenderPass} from '@luma.gl/core'; import Pass from './pass'; @@ -38,13 +38,28 @@ export type LayersPassRenderOptions = { preRenderStats?: Record; }; -type DrawLayerParameters = { - shouldDrawLayer: boolean; - layerRenderIndex?: number; - shaderModuleProps?: any; - layerParameters?: any; +export type DrawableLayerParameters = { + shouldDrawLayer: true; + layerRenderIndex: number; + shaderModuleProps: any; + layerParameters: RenderPipelineParameters; }; +export type DrawLayerParameters = + | { + shouldDrawLayer: true; + layerRenderIndex: number; + shaderModuleProps: any; + layerParameters: RenderPipelineParameters; + } + | {shouldDrawLayer: false}; + +export function isDrawableLayerParameters( + parameters: DrawLayerParameters +): parameters is DrawableLayerParameters { + return parameters.shouldDrawLayer; +} + export type FilterContext = { layer: Layer; viewport: Viewport; @@ -182,25 +197,25 @@ export default class LayersPass extends Pass { layerFilterCache ); - const layerParam: DrawLayerParameters = { - shouldDrawLayer - }; + let layerParam: DrawLayerParameters; if (shouldDrawLayer && !evaluateShouldDrawOnly) { - // This is the "logical" index for ordering this layer in the stack - // used to calculate polygon offsets - // It can be the same as another layer - layerParam.layerRenderIndex = indexResolver(layer, shouldDrawLayer); - - layerParam.shaderModuleProps = this._getShaderModuleProps( - layer, - effects, - pass, - shaderModuleProps - ); - layerParam.layerParameters = { - ...layer.context.deck?.props.parameters, - ...this.getLayerParameters(layer, layerIndex, viewport) + layerParam = { + shouldDrawLayer: true, + // This is the "logical" index for ordering this layer in the stack + // used to calculate polygon offsets + // It can be the same as another layer + layerRenderIndex: indexResolver(layer, shouldDrawLayer), + + shaderModuleProps: this._getShaderModuleProps(layer, effects, pass, shaderModuleProps), + layerParameters: { + ...layer.context.deck?.props.parameters, + ...this.getLayerParameters(layer, layerIndex, viewport) + } + }; + } else { + layerParam = { + shouldDrawLayer: false }; } drawLayerParams[layerIndex] = layerParam; @@ -215,7 +230,7 @@ export default class LayersPass extends Pass { private _drawLayersInViewport( renderPass: RenderPass, {layers, shaderModuleProps: globalModuleParameters, pass, target, viewport, view}, - drawLayerParams + drawLayerParams: DrawLayerParameters[] ): RenderStats { const glViewport = getGLViewport(this.device, { shaderModuleProps: globalModuleParameters, @@ -248,8 +263,8 @@ export default class LayersPass extends Pass { // render layers in normal colors for (let layerIndex = 0; layerIndex < layers.length; layerIndex++) { const layer = layers[layerIndex] as Layer; - const {shouldDrawLayer, layerRenderIndex, shaderModuleProps, layerParameters} = - drawLayerParams[layerIndex]; + const drawLayerParameters = drawLayerParams[layerIndex]; + const {shouldDrawLayer} = drawLayerParameters; // Calculate stats if (shouldDrawLayer && layer.props.pickable) { @@ -258,7 +273,8 @@ export default class LayersPass extends Pass { if (layer.isComposite) { renderStatus.compositeCount++; } - if (layer.isDrawable && shouldDrawLayer) { + if (layer.isDrawable && isDrawableLayerParameters(drawLayerParameters)) { + const {layerRenderIndex, shaderModuleProps, layerParameters} = drawLayerParameters; // Draw the layer renderStatus.visibleCount++; diff --git a/modules/extensions/src/terrain/terrain-picking-pass.ts b/modules/extensions/src/terrain/terrain-picking-pass.ts index 4db5f56f46a..f2309ad535f 100644 --- a/modules/extensions/src/terrain/terrain-picking-pass.ts +++ b/modules/extensions/src/terrain/terrain-picking-pass.ts @@ -6,7 +6,8 @@ import { Layer, Viewport, LayersPassRenderOptions, - _PickLayersPass as PickLayersPass + _PickLayersPass as PickLayersPass, + _isDrawableLayerParameters as isDrawableLayerParameters } from '@deck.gl/core'; import type {TerrainCover} from './terrain-cover'; @@ -32,9 +33,10 @@ export class TerrainPickingPass extends PickLayersPass { const drawParamsByIndex = this._getDrawLayerParams(viewport, opts); for (let i = 0; i < layers.length; i++) { const layer = layers[i]; - if (!layer.isComposite && drawParamsByIndex[i].shouldDrawLayer) { + const drawLayerParameters = drawParamsByIndex[i]; + if (!layer.isComposite && isDrawableLayerParameters(drawLayerParameters)) { result.push(layer); - this.drawParameters[layer.id] = drawParamsByIndex[i].layerParameters; + this.drawParameters[layer.id] = drawLayerParameters.layerParameters; } } From e70db91d774c0ad4c49e050b4c26b46784abb3db Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Thu, 10 Oct 2024 15:17:56 +0200 Subject: [PATCH 02/10] Types in passes --- modules/core/src/passes/layers-pass.ts | 9 +++++++-- modules/core/src/passes/pick-layers-pass.ts | 4 ++-- modules/core/src/passes/shadow-pass.ts | 8 ++++++-- .../src/collision-filter/collision-filter-pass.ts | 4 ++-- modules/extensions/src/mask/mask-pass.ts | 14 ++++++++++++-- modules/extensions/src/terrain/terrain-pass.ts | 8 ++++++-- .../extensions/src/terrain/terrain-picking-pass.ts | 3 ++- 7 files changed, 37 insertions(+), 13 deletions(-) diff --git a/modules/core/src/passes/layers-pass.ts b/modules/core/src/passes/layers-pass.ts index 4a099deef58..fa030b03de6 100644 --- a/modules/core/src/passes/layers-pass.ts +++ b/modules/core/src/passes/layers-pass.ts @@ -2,7 +2,12 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import type {Device, RenderPassParameters, RenderPipelineParameters} from '@luma.gl/core'; +import type { + Device, + Parameters, + RenderPassParameters, + RenderPipelineParameters +} from '@luma.gl/core'; import type {Framebuffer, RenderPass} from '@luma.gl/core'; import Pass from './pass'; @@ -320,7 +325,7 @@ export default class LayersPass extends Pass { return null; } - protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): any { + protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): Parameters { return layer.props.parameters; } diff --git a/modules/core/src/passes/pick-layers-pass.ts b/modules/core/src/passes/pick-layers-pass.ts index a2802840bb5..a28664a4323 100644 --- a/modules/core/src/passes/pick-layers-pass.ts +++ b/modules/core/src/passes/pick-layers-pass.ts @@ -3,7 +3,7 @@ // Copyright (c) vis.gl contributors import LayersPass, {LayersPassRenderOptions, RenderStats, Rect} from './layers-pass'; -import type {Framebuffer, RenderPipelineParameters} from '@luma.gl/core'; +import type {Framebuffer, Parameters, RenderPipelineParameters} from '@luma.gl/core'; import log from '../utils/log'; import type {Effect} from '../lib/effect'; @@ -130,7 +130,7 @@ export default class PickLayersPass extends LayersPass { }; } - protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): any { + protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): Parameters { const pickParameters: any = { // TODO - When used as a custom layer in older Mapbox versions, context // state was dirty. Mapbox fixed that; we should test and remove the workaround. diff --git a/modules/core/src/passes/shadow-pass.ts b/modules/core/src/passes/shadow-pass.ts index d560b859231..4e3cf5488d2 100644 --- a/modules/core/src/passes/shadow-pass.ts +++ b/modules/core/src/passes/shadow-pass.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {Device, Framebuffer, Texture} from '@luma.gl/core'; +import {Device, Framebuffer, Parameters, Texture} from '@luma.gl/core'; import type Layer from '../lib/layer'; import type Viewport from '../viewports/viewport'; import LayersPass from './layers-pass'; @@ -77,7 +77,11 @@ export default class ShadowPass extends LayersPass { super.render({...params, clearColor, target, pass: 'shadow'}); } - protected getLayerParameters(layer: Layer<{}>, layerIndex: number, viewport: Viewport) { + protected getLayerParameters( + layer: Layer<{}>, + layerIndex: number, + viewport: Viewport + ): Parameters { return {...layer.props.parameters, blend: false, depthRange: [0, 1], depthTest: true}; } diff --git a/modules/extensions/src/collision-filter/collision-filter-pass.ts b/modules/extensions/src/collision-filter/collision-filter-pass.ts index 0b4dcf6f7b7..7cfc34d25dc 100644 --- a/modules/extensions/src/collision-filter/collision-filter-pass.ts +++ b/modules/extensions/src/collision-filter/collision-filter-pass.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {Framebuffer} from '@luma.gl/core'; +import {Framebuffer, Parameters} from '@luma.gl/core'; import {Layer, _LayersPass as LayersPass, LayersPassRenderOptions, Viewport} from '@deck.gl/core'; type CollisionFilterPassRenderOptions = LayersPassRenderOptions & {}; @@ -16,7 +16,7 @@ export default class CollisionFilterPass extends LayersPass { this.render({...options, clearColor, scissorRect, target, pass: 'collision'}); } - protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): any { + protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): Parameters { return {...layer.props.parameters, blend: false, depthRange: [0, 1], depthTest: true}; } diff --git a/modules/extensions/src/mask/mask-pass.ts b/modules/extensions/src/mask/mask-pass.ts index 51bdd196ab3..578b3fca215 100644 --- a/modules/extensions/src/mask/mask-pass.ts +++ b/modules/extensions/src/mask/mask-pass.ts @@ -2,7 +2,13 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import type {Device, Framebuffer, RenderPipelineParameters, Texture} from '@luma.gl/core'; +import type { + Device, + Framebuffer, + Parameters, + RenderPipelineParameters, + Texture +} from '@luma.gl/core'; import {Layer, _LayersPass as LayersPass, LayersPassRenderOptions, Viewport} from '@deck.gl/core'; type MaskPassRenderOptions = LayersPassRenderOptions & { @@ -54,7 +60,11 @@ export default class MaskPass extends LayersPass { super.render({...options, clearColor, colorMask, target: this.fbo, pass: 'mask'}); } - protected getLayerParameters(layer: Layer<{}>, layerIndex: number, viewport: Viewport) { + protected getLayerParameters( + layer: Layer<{}>, + layerIndex: number, + viewport: Viewport + ): Parameters { return { ...layer.props.parameters, blend: true, diff --git a/modules/extensions/src/terrain/terrain-pass.ts b/modules/extensions/src/terrain/terrain-pass.ts index da45506dd42..4f14da29c61 100644 --- a/modules/extensions/src/terrain/terrain-pass.ts +++ b/modules/extensions/src/terrain/terrain-pass.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {RenderPipelineParameters} from '@luma.gl/core'; +import {Parameters, RenderPipelineParameters} from '@luma.gl/core'; import {Layer, Viewport, _LayersPass as LayersPass, LayersPassRenderOptions} from '@deck.gl/core'; import type {HeightMapBuilder} from './height-map-builder'; import type {TerrainCover} from './terrain-cover'; @@ -79,7 +79,11 @@ export class TerrainPass extends LayersPass { }); } - protected getLayerParameters(layer: Layer<{}>, layerIndex: number, viewport: Viewport) { + protected getLayerParameters( + layer: Layer<{}>, + layerIndex: number, + viewport: Viewport + ): Parameters { return { ...layer.props.parameters, blend: true, diff --git a/modules/extensions/src/terrain/terrain-picking-pass.ts b/modules/extensions/src/terrain/terrain-picking-pass.ts index f2309ad535f..36ea7ff3d2e 100644 --- a/modules/extensions/src/terrain/terrain-picking-pass.ts +++ b/modules/extensions/src/terrain/terrain-picking-pass.ts @@ -10,6 +10,7 @@ import { _isDrawableLayerParameters as isDrawableLayerParameters } from '@deck.gl/core'; import type {TerrainCover} from './terrain-cover'; +import {Parameters} from '@luma.gl/core'; export type TerrainPickingPassRenderOptions = LayersPassRenderOptions & { pickZ: boolean; @@ -74,7 +75,7 @@ export class TerrainPickingPass extends PickLayersPass { }); } - protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): any { + protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): Parameters { let parameters: any; if (this.drawParameters[layer.id]) { parameters = this.drawParameters[layer.id]; From 800846fdaebc6481e83f9b702ec911d8e46efd86 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Thu, 10 Oct 2024 15:21:20 +0200 Subject: [PATCH 03/10] Adjust type --- modules/core/src/lib/layer.ts | 4 ++-- modules/core/src/passes/layers-pass.ts | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index 3aba211e22d..c73bb3c9517 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -3,7 +3,7 @@ // Copyright (c) vis.gl contributors /* eslint-disable react/no-direct-mutation-state */ -import {Buffer, RenderPipelineParameters, TypedArray} from '@luma.gl/core'; +import {Buffer, Parameters, TypedArray} from '@luma.gl/core'; import {WebGLDevice} from '@luma.gl/webgl'; import {COORDINATE_SYSTEM} from './constants'; import AttributeManager from './attribute/attribute-manager'; @@ -1042,7 +1042,7 @@ export default abstract class Layer extends Component< renderPass: RenderPass; shaderModuleProps: any; uniforms: any; - parameters: RenderPipelineParameters; + parameters: Parameters; }): void { this._updateAttributeTransition(); diff --git a/modules/core/src/passes/layers-pass.ts b/modules/core/src/passes/layers-pass.ts index fa030b03de6..c7f267bf9f1 100644 --- a/modules/core/src/passes/layers-pass.ts +++ b/modules/core/src/passes/layers-pass.ts @@ -2,12 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import type { - Device, - Parameters, - RenderPassParameters, - RenderPipelineParameters -} from '@luma.gl/core'; +import type {Device, Parameters, RenderPassParameters} from '@luma.gl/core'; import type {Framebuffer, RenderPass} from '@luma.gl/core'; import Pass from './pass'; @@ -47,7 +42,7 @@ export type DrawableLayerParameters = { shouldDrawLayer: true; layerRenderIndex: number; shaderModuleProps: any; - layerParameters: RenderPipelineParameters; + layerParameters: Parameters; }; export type DrawLayerParameters = @@ -55,7 +50,7 @@ export type DrawLayerParameters = shouldDrawLayer: true; layerRenderIndex: number; shaderModuleProps: any; - layerParameters: RenderPipelineParameters; + layerParameters: Parameters; } | {shouldDrawLayer: false}; From d20ca5d67191996f28243ddd6ada08d695a6239d Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Thu, 10 Oct 2024 15:22:57 +0200 Subject: [PATCH 04/10] Resolve clash --- modules/core/src/lib/layer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index c73bb3c9517..196eb79cfef 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -3,7 +3,7 @@ // Copyright (c) vis.gl contributors /* eslint-disable react/no-direct-mutation-state */ -import {Buffer, Parameters, TypedArray} from '@luma.gl/core'; +import {Buffer, Parameters as LumaParameters, TypedArray} from '@luma.gl/core'; import {WebGLDevice} from '@luma.gl/webgl'; import {COORDINATE_SYSTEM} from './constants'; import AttributeManager from './attribute/attribute-manager'; @@ -1042,7 +1042,7 @@ export default abstract class Layer extends Component< renderPass: RenderPass; shaderModuleProps: any; uniforms: any; - parameters: Parameters; + parameters: LumaParameters; }): void { this._updateAttributeTransition(); From 207e7b65be21f84cc2d2f4e640a812b9ac51aacb Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Fri, 11 Oct 2024 09:45:09 +0200 Subject: [PATCH 05/10] Remove depthRange --- modules/core/src/passes/pick-layers-pass.ts | 1 - modules/core/src/passes/shadow-pass.ts | 2 +- .../extensions/src/collision-filter/collision-filter-pass.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/core/src/passes/pick-layers-pass.ts b/modules/core/src/passes/pick-layers-pass.ts index a28664a4323..3d98c490121 100644 --- a/modules/core/src/passes/pick-layers-pass.ts +++ b/modules/core/src/passes/pick-layers-pass.ts @@ -137,7 +137,6 @@ export default class PickLayersPass extends LayersPass { // https://github.com/mapbox/mapbox-gl-js/issues/7801 depthMask: true, depthTest: true, - depthRange: [0, 1], ...layer.props.parameters }; const {pickable, operation} = layer.props; diff --git a/modules/core/src/passes/shadow-pass.ts b/modules/core/src/passes/shadow-pass.ts index 4e3cf5488d2..c35ad5d9846 100644 --- a/modules/core/src/passes/shadow-pass.ts +++ b/modules/core/src/passes/shadow-pass.ts @@ -82,7 +82,7 @@ export default class ShadowPass extends LayersPass { layerIndex: number, viewport: Viewport ): Parameters { - return {...layer.props.parameters, blend: false, depthRange: [0, 1], depthTest: true}; + return {...layer.props.parameters, blend: false, depthTest: true}; } shouldDrawLayer(layer) { diff --git a/modules/extensions/src/collision-filter/collision-filter-pass.ts b/modules/extensions/src/collision-filter/collision-filter-pass.ts index 7cfc34d25dc..eea28acc515 100644 --- a/modules/extensions/src/collision-filter/collision-filter-pass.ts +++ b/modules/extensions/src/collision-filter/collision-filter-pass.ts @@ -17,7 +17,7 @@ export default class CollisionFilterPass extends LayersPass { } protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): Parameters { - return {...layer.props.parameters, blend: false, depthRange: [0, 1], depthTest: true}; + return {...layer.props.parameters, blend: false, depthTest: true}; } getShaderModuleProps() { From 6bd9dfcfc95cf8c704675f00f5ba927f8679b409 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Fri, 11 Oct 2024 09:56:41 +0200 Subject: [PATCH 06/10] Replace depthTest with depthCompare/depthWriteEnabled --- modules/carto/src/api/layer-map.ts | 2 +- modules/core/src/passes/pick-layers-pass.ts | 7 ++----- modules/core/src/passes/shadow-pass.ts | 2 +- .../src/collision-filter/collision-filter-pass.ts | 2 +- modules/extensions/src/mask/mask-pass.ts | 2 +- modules/extensions/src/terrain/terrain-pass.ts | 2 +- modules/extensions/src/terrain/terrain-picking-pass.ts | 2 +- modules/mapbox/src/deck-utils.ts | 5 +++-- 8 files changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/carto/src/api/layer-map.ts b/modules/carto/src/api/layer-map.ts index dfdd2950619..469ba3af0eb 100644 --- a/modules/carto/src/api/layer-map.ts +++ b/modules/carto/src/api/layer-map.ts @@ -197,7 +197,7 @@ export function getLayer( Layer: GeoJsonLayer, propMap: { columns: { - altitude: x => ({parameters: {depthTest: Boolean(x)}}) + altitude: x => ({parameters: {depthWriteEnabled: Boolean(x)}}) }, visConfig: {outline: 'stroked'} } diff --git a/modules/core/src/passes/pick-layers-pass.ts b/modules/core/src/passes/pick-layers-pass.ts index 3d98c490121..3af2b768e1a 100644 --- a/modules/core/src/passes/pick-layers-pass.ts +++ b/modules/core/src/passes/pick-layers-pass.ts @@ -131,12 +131,8 @@ export default class PickLayersPass extends LayersPass { } protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): Parameters { + // TODO use Parameters type const pickParameters: any = { - // TODO - When used as a custom layer in older Mapbox versions, context - // state was dirty. Mapbox fixed that; we should test and remove the workaround. - // https://github.com/mapbox/mapbox-gl-js/issues/7801 - depthMask: true, - depthTest: true, ...layer.props.parameters }; const {pickable, operation} = layer.props; @@ -146,6 +142,7 @@ export default class PickLayersPass extends LayersPass { } else if (pickable && operation.includes('draw')) { Object.assign(pickParameters, PICKING_BLENDING); pickParameters.blend = true; + // TODO: blendColor no longer part of luma.gl API pickParameters.blendColor = encodeColor(this._colorEncoderState, layer, viewport); } diff --git a/modules/core/src/passes/shadow-pass.ts b/modules/core/src/passes/shadow-pass.ts index c35ad5d9846..773a0e71314 100644 --- a/modules/core/src/passes/shadow-pass.ts +++ b/modules/core/src/passes/shadow-pass.ts @@ -82,7 +82,7 @@ export default class ShadowPass extends LayersPass { layerIndex: number, viewport: Viewport ): Parameters { - return {...layer.props.parameters, blend: false, depthTest: true}; + return {...layer.props.parameters, blend: false, depthCompare: 'always'}; } shouldDrawLayer(layer) { diff --git a/modules/extensions/src/collision-filter/collision-filter-pass.ts b/modules/extensions/src/collision-filter/collision-filter-pass.ts index eea28acc515..0e5660a7f92 100644 --- a/modules/extensions/src/collision-filter/collision-filter-pass.ts +++ b/modules/extensions/src/collision-filter/collision-filter-pass.ts @@ -17,7 +17,7 @@ export default class CollisionFilterPass extends LayersPass { } protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): Parameters { - return {...layer.props.parameters, blend: false, depthTest: true}; + return {...layer.props.parameters, blend: false, depthCompare: 'always'}; } getShaderModuleProps() { diff --git a/modules/extensions/src/mask/mask-pass.ts b/modules/extensions/src/mask/mask-pass.ts index 578b3fca215..9bc8fbbaac3 100644 --- a/modules/extensions/src/mask/mask-pass.ts +++ b/modules/extensions/src/mask/mask-pass.ts @@ -68,7 +68,7 @@ export default class MaskPass extends LayersPass { return { ...layer.props.parameters, blend: true, - depthTest: false, + depthCompare: 'always', ...MASK_BLENDING }; } diff --git a/modules/extensions/src/terrain/terrain-pass.ts b/modules/extensions/src/terrain/terrain-pass.ts index 4f14da29c61..37ccd5fa936 100644 --- a/modules/extensions/src/terrain/terrain-pass.ts +++ b/modules/extensions/src/terrain/terrain-pass.ts @@ -87,7 +87,7 @@ export class TerrainPass extends LayersPass { return { ...layer.props.parameters, blend: true, - depthTest: false, + depthCompare: 'always', ...(layer.props.operation.includes('terrain') && TERRAIN_BLENDING) }; } diff --git a/modules/extensions/src/terrain/terrain-picking-pass.ts b/modules/extensions/src/terrain/terrain-picking-pass.ts index 36ea7ff3d2e..b4151c351c5 100644 --- a/modules/extensions/src/terrain/terrain-picking-pass.ts +++ b/modules/extensions/src/terrain/terrain-picking-pass.ts @@ -83,7 +83,7 @@ export class TerrainPickingPass extends PickLayersPass { parameters = super.getLayerParameters(layer, layerIndex, viewport); parameters.blend = true; } - return {...parameters, depthTest: false}; + return {...parameters, depthCompare: 'always'}; } getShaderModuleProps(layer: Layer, effects: any, otherShaderModuleProps: Record) { diff --git a/modules/mapbox/src/deck-utils.ts b/modules/mapbox/src/deck-utils.ts index 8b4d584e62f..97c61adcecd 100644 --- a/modules/mapbox/src/deck-utils.ts +++ b/modules/mapbox/src/deck-utils.ts @@ -118,10 +118,11 @@ export function removeDeckInstance(map: Map & {__deck?: Deck | null}) { export function getInterleavedProps(currProps: DeckProps) { const nextProps: DeckProps = { ...currProps, - // TODO: remove with withParametersWebGL + // TODO: remove 'any' cast parameters: { depthMask: true, - depthTest: true, + depthWriteEnabled: true, + depthCompare: 'less-equal', blend: true, blendFunc: [GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA], polygonOffsetFill: true, From c31dec6b1e0bf48915e29ef6ab63c0e7207fc2ce Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Fri, 11 Oct 2024 12:16:39 +0200 Subject: [PATCH 07/10] Stop being too clever with types --- modules/core/src/index.ts | 11 +--- modules/core/src/passes/layers-pass.ts | 56 +++++++------------ .../src/terrain/terrain-picking-pass.ts | 8 +-- 3 files changed, 26 insertions(+), 49 deletions(-) diff --git a/modules/core/src/index.ts b/modules/core/src/index.ts index ff1d8be3d6b..11a3f8f2cf9 100644 --- a/modules/core/src/index.ts +++ b/modules/core/src/index.ts @@ -23,10 +23,7 @@ export {default as _SunLight} from './effects/lighting/sun-light'; export {default as PostProcessEffect} from './effects/post-process-effect'; // Passes -export { - default as _LayersPass, - isDrawableLayerParameters as _isDrawableLayerParameters -} from './passes/layers-pass'; +export {default as _LayersPass} from './passes/layers-pass'; export {default as _PickLayersPass} from './passes/pick-layers-pass'; // Experimental Pure JS (non-React) bindings @@ -123,11 +120,7 @@ export type { TextureSource, Material } from './types/layer-props'; -export type { - DrawableLayerParameters, - DrawLayerParameters, - FilterContext -} from './passes/layers-pass'; +export type {DrawLayerParameters, FilterContext} from './passes/layers-pass'; export type {PickingInfo, GetPickingInfoParams} from './lib/picking/pick-info'; export type {ConstructorOf as _ConstructorOf} from './types/types'; export type {BinaryAttribute} from './lib/attribute/attribute'; diff --git a/modules/core/src/passes/layers-pass.ts b/modules/core/src/passes/layers-pass.ts index c7f267bf9f1..ba694764956 100644 --- a/modules/core/src/passes/layers-pass.ts +++ b/modules/core/src/passes/layers-pass.ts @@ -38,28 +38,13 @@ export type LayersPassRenderOptions = { preRenderStats?: Record; }; -export type DrawableLayerParameters = { - shouldDrawLayer: true; +export type DrawLayerParameters = { + shouldDrawLayer: boolean; layerRenderIndex: number; shaderModuleProps: any; layerParameters: Parameters; }; -export type DrawLayerParameters = - | { - shouldDrawLayer: true; - layerRenderIndex: number; - shaderModuleProps: any; - layerParameters: Parameters; - } - | {shouldDrawLayer: false}; - -export function isDrawableLayerParameters( - parameters: DrawLayerParameters -): parameters is DrawableLayerParameters { - return parameters.shouldDrawLayer; -} - export type FilterContext = { layer: Layer; viewport: Viewport; @@ -197,27 +182,28 @@ export default class LayersPass extends Pass { layerFilterCache ); - let layerParam: DrawLayerParameters; + const layerParam = {shouldDrawLayer} as DrawLayerParameters; if (shouldDrawLayer && !evaluateShouldDrawOnly) { - layerParam = { - shouldDrawLayer: true, - // This is the "logical" index for ordering this layer in the stack - // used to calculate polygon offsets - // It can be the same as another layer - layerRenderIndex: indexResolver(layer, shouldDrawLayer), - - shaderModuleProps: this._getShaderModuleProps(layer, effects, pass, shaderModuleProps), - layerParameters: { - ...layer.context.deck?.props.parameters, - ...this.getLayerParameters(layer, layerIndex, viewport) - } - }; - } else { - layerParam = { - shouldDrawLayer: false + layerParam.shouldDrawLayer = true; + + // This is the "logical" index for ordering this layer in the stack + // used to calculate polygon offsets + // It can be the same as another layer + layerParam.layerRenderIndex = indexResolver(layer, shouldDrawLayer); + + layerParam.shaderModuleProps = this._getShaderModuleProps( + layer, + effects, + pass, + shaderModuleProps + ); + layerParam.layerParameters = { + ...layer.context.deck?.props.parameters, + ...this.getLayerParameters(layer, layerIndex, viewport) }; } + drawLayerParams[layerIndex] = layerParam; } return drawLayerParams; @@ -273,7 +259,7 @@ export default class LayersPass extends Pass { if (layer.isComposite) { renderStatus.compositeCount++; } - if (layer.isDrawable && isDrawableLayerParameters(drawLayerParameters)) { + if (layer.isDrawable && drawLayerParameters.shouldDrawLayer) { const {layerRenderIndex, shaderModuleProps, layerParameters} = drawLayerParameters; // Draw the layer renderStatus.visibleCount++; diff --git a/modules/extensions/src/terrain/terrain-picking-pass.ts b/modules/extensions/src/terrain/terrain-picking-pass.ts index b4151c351c5..95cf5f53079 100644 --- a/modules/extensions/src/terrain/terrain-picking-pass.ts +++ b/modules/extensions/src/terrain/terrain-picking-pass.ts @@ -6,8 +6,7 @@ import { Layer, Viewport, LayersPassRenderOptions, - _PickLayersPass as PickLayersPass, - _isDrawableLayerParameters as isDrawableLayerParameters + _PickLayersPass as PickLayersPass } from '@deck.gl/core'; import type {TerrainCover} from './terrain-cover'; import {Parameters} from '@luma.gl/core'; @@ -34,10 +33,9 @@ export class TerrainPickingPass extends PickLayersPass { const drawParamsByIndex = this._getDrawLayerParams(viewport, opts); for (let i = 0; i < layers.length; i++) { const layer = layers[i]; - const drawLayerParameters = drawParamsByIndex[i]; - if (!layer.isComposite && isDrawableLayerParameters(drawLayerParameters)) { + if (!layer.isComposite && drawParamsByIndex[i].shouldDrawLayer) { result.push(layer); - this.drawParameters[layer.id] = drawLayerParameters.layerParameters; + this.drawParameters[layer.id] = drawParamsByIndex[i].layerParameters; } } From 75ef5a2e05a4d439d26b8c1eeceab19623857eac Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Fri, 11 Oct 2024 12:20:18 +0200 Subject: [PATCH 08/10] Test fix --- test/modules/mapbox/fixtures.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/modules/mapbox/fixtures.ts b/test/modules/mapbox/fixtures.ts index d1ffc822605..f1eb3846ede 100644 --- a/test/modules/mapbox/fixtures.ts +++ b/test/modules/mapbox/fixtures.ts @@ -6,7 +6,8 @@ import {GL} from '@luma.gl/constants'; export const DEFAULT_PARAMETERS = { depthMask: true, - depthTest: true, + depthWriteEnabled: true, + depthCompare: 'less-equal', blend: true, blendFunc: [GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA], polygonOffsetFill: true, From 12b07e1ef3bb61466028bd8393d1e40ea984b154 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Fri, 11 Oct 2024 12:25:25 +0200 Subject: [PATCH 09/10] Test fix --- test/modules/mapbox/mapbox-overlay.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/modules/mapbox/mapbox-overlay.spec.ts b/test/modules/mapbox/mapbox-overlay.spec.ts index 79d2b1adbf7..efb29994cc9 100644 --- a/test/modules/mapbox/mapbox-overlay.spec.ts +++ b/test/modules/mapbox/mapbox-overlay.spec.ts @@ -281,7 +281,7 @@ test('MapboxOverlay#interleavedNoInitialLayers', t => { t.ok(map.getLayer('cities'), 'MapboxLayer is added'); t.ok( - objectEqual(overlay._deck.props.parameters, {...DEFAULT_PARAMETERS, depthTest: false}), + objectEqual(overlay._deck.props.parameters, {...DEFAULT_PARAMETERS, depthMask: false}), 'Parameters are updated correctly' ); t.ok( From 4b4371dcd7fcd27dd3bc0f639e4ccbc3d7249eca Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Fri, 11 Oct 2024 13:03:45 +0200 Subject: [PATCH 10/10] Correct parameters --- modules/core/src/passes/shadow-pass.ts | 7 ++++++- .../src/collision-filter/collision-filter-pass.ts | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/core/src/passes/shadow-pass.ts b/modules/core/src/passes/shadow-pass.ts index 773a0e71314..8b7c523497d 100644 --- a/modules/core/src/passes/shadow-pass.ts +++ b/modules/core/src/passes/shadow-pass.ts @@ -82,7 +82,12 @@ export default class ShadowPass extends LayersPass { layerIndex: number, viewport: Viewport ): Parameters { - return {...layer.props.parameters, blend: false, depthCompare: 'always'}; + return { + ...layer.props.parameters, + blend: false, + depthWriteEnabled: true, + depthCompare: 'less-equal' + }; } shouldDrawLayer(layer) { diff --git a/modules/extensions/src/collision-filter/collision-filter-pass.ts b/modules/extensions/src/collision-filter/collision-filter-pass.ts index 0e5660a7f92..639ffa250f1 100644 --- a/modules/extensions/src/collision-filter/collision-filter-pass.ts +++ b/modules/extensions/src/collision-filter/collision-filter-pass.ts @@ -17,7 +17,12 @@ export default class CollisionFilterPass extends LayersPass { } protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): Parameters { - return {...layer.props.parameters, blend: false, depthCompare: 'always'}; + return { + ...layer.props.parameters, + blend: false, + depthWriteEnabled: true, + depthCompare: 'less-equal' + }; } getShaderModuleProps() {