Skip to content

Commit 030be26

Browse files
committed
Centralize dummy map
1 parent 3810cb1 commit 030be26

2 files changed

Lines changed: 25 additions & 34 deletions

File tree

modules/extensions/src/terrain/shader-module.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export type TerrainModuleProps = {
1717
isPicking: boolean;
1818
heightMap: Texture | null;
1919
heightMapBounds?: Bounds | null;
20-
dummyHeightMap: Texture;
2120
terrainCover?: TerrainCover | null;
2221
drawToTerrainHeightMap?: boolean;
2322
useTerrainHeightMap?: boolean;
@@ -119,23 +118,27 @@ if ((terrain.mode == TERRAIN_MODE_USE_COVER) || (terrain.mode == TERRAIN_MODE_US
119118
},
120119
// eslint-disable-next-line complexity
121120
getUniforms: (opts: Partial<TerrainModuleProps> = {}) => {
122-
if ('dummyHeightMap' in opts) {
121+
const dummyHeightMap = terrainModule.dummyHeightMap;
122+
if (!dummyHeightMap) {
123+
// TerrainEffect has not been set up yet
124+
return {};
125+
}
126+
127+
if ('terrainSkipRender' in opts || 'drawToTerrainHeightMap' in opts) {
123128
const {
124129
drawToTerrainHeightMap,
125130
heightMap,
126131
heightMapBounds,
127-
dummyHeightMap,
128132
terrainCover,
129133
useTerrainHeightMap,
130134
terrainSkipRender
131135
} = opts;
132-
133136
const projectUniforms = project.getUniforms(opts.project) as ProjectUniforms;
134137
const {commonOrigin} = projectUniforms;
135138

136139
let mode: number = terrainSkipRender ? TERRAIN_MODE.SKIP : TERRAIN_MODE.NONE;
137140
// height map if case USE_HEIGHT_MAP, terrain cover if USE_COVER, otherwise empty
138-
let sampler: Texture | undefined = dummyHeightMap as Texture;
141+
let sampler: Texture = dummyHeightMap;
139142
// height map bounds if case USE_HEIGHT_MAP, terrain cover bounds if USE_COVER, otherwise null
140143
let bounds: number[] | null = null;
141144
if (drawToTerrainHeightMap) {
@@ -150,15 +153,15 @@ if ((terrain.mode == TERRAIN_MODE_USE_COVER) || (terrain.mode == TERRAIN_MODE_US
150153
const fbo = opts.isPicking
151154
? terrainCover.getPickingFramebuffer()
152155
: terrainCover.getRenderFramebuffer();
153-
sampler = fbo?.colorAttachments[0].texture;
156+
const coverTexture = fbo?.colorAttachments[0].texture;
154157
if (opts.isPicking) {
155158
mode = TERRAIN_MODE.SKIP;
156159
}
157-
if (sampler) {
160+
if (coverTexture) {
161+
sampler = coverTexture;
158162
mode = mode === TERRAIN_MODE.SKIP ? TERRAIN_MODE.USE_COVER_ONLY : TERRAIN_MODE.USE_COVER;
159163
bounds = terrainCover.bounds;
160164
} else {
161-
sampler = dummyHeightMap!;
162165
if (opts.isPicking && !terrainSkipRender) {
163166
// terrain+draw layer without cover FBO: render own picking colors
164167
mode = TERRAIN_MODE.NONE;
@@ -181,22 +184,20 @@ if ((terrain.mode == TERRAIN_MODE_USE_COVER) || (terrain.mode == TERRAIN_MODE_US
181184
: [0, 0, 0, 0]
182185
};
183186
}
184-
// When terrain props are not provided (e.g. mask pass), provide the dummy
185-
// texture to satisfy the terrain_map binding and prevent draw abort.
186-
// dummyHeightMap is stored on the module by TerrainEffect.setup.
187-
if (terrainModule.dummyHeightMap) {
188-
return {
189-
mode: TERRAIN_MODE.NONE,
190-
terrain_map: terrainModule.dummyHeightMap,
191-
bounds: [0, 0, 0, 0]
192-
};
193-
}
194-
return {};
187+
// No terrain-specific props provided (e.g. mask pass or other non-terrain render pass).
188+
// Provide the dummy texture to satisfy the terrain_map binding.
189+
return {
190+
mode: TERRAIN_MODE.NONE,
191+
terrain_map: dummyHeightMap,
192+
bounds: [0, 0, 0, 0]
193+
};
195194
},
196195
uniformTypes: {
197196
mode: 'f32',
198197
bounds: 'vec4<f32>'
199198
},
200-
/** Dummy texture stored by TerrainEffect.setup, used as fallback terrain_map binding */
199+
/** Dummy texture created by TerrainEffect.setup, used as default terrain_map binding */
201200
dummyHeightMap: null as Texture | null
202-
} as ShaderModule<TerrainModuleProps, TerrainModuleUniforms, TerrainModuleBindings> & {dummyHeightMap: Texture | null};
201+
} as ShaderModule<TerrainModuleProps, TerrainModuleUniforms, TerrainModuleBindings> & {
202+
dummyHeightMap: Texture | null;
203+
};

modules/extensions/src/terrain/terrain-effect.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: MIT
33
// Copyright (c) vis.gl contributors
44

5-
import {Texture} from '@luma.gl/core';
65
import {log} from '@deck.gl/core';
76

87
import {terrainModule, TerrainModuleProps} from './shader-module';
@@ -23,8 +22,6 @@ export class TerrainEffect implements Effect {
2322
private isPicking: boolean = false;
2423
/** true if should use in the current pass */
2524
private isDrapingEnabled: boolean = false;
26-
/** An empty texture as placeholder */
27-
private dummyHeightMap?: Texture;
2825
/** A texture encoding the ground elevation, updated once per redraw. Used by layers with offset mode */
2926
private heightMap?: HeightMapBuilder;
3027
private terrainPass!: TerrainPass;
@@ -33,14 +30,11 @@ export class TerrainEffect implements Effect {
3330
private terrainCovers: Map<string, TerrainCover> = new Map();
3431

3532
setup({device, deck}: EffectContext) {
36-
this.dummyHeightMap = device.createTexture({
33+
terrainModule.dummyHeightMap = device.createTexture({
3734
width: 1,
3835
height: 1,
3936
data: new Uint8Array([0, 0, 0, 0])
4037
});
41-
// Store on the module so it can provide a fallback terrain_map binding
42-
// when rendered in passes that don't provide terrain effect props (e.g. mask pass)
43-
terrainModule.dummyHeightMap = this.dummyHeightMap;
4438

4539
this.terrainPass = new TerrainPass(device, {id: 'terrain'});
4640
this.terrainPickingPass = new TerrainPickingPass(device, {id: 'terrain-picking'});
@@ -115,7 +109,6 @@ export class TerrainEffect implements Effect {
115109
isPicking: this.isPicking,
116110
heightMap: this.heightMap?.getRenderFramebuffer()?.colorAttachments[0].texture || null,
117111
heightMapBounds: this.heightMap?.bounds,
118-
dummyHeightMap: this.dummyHeightMap!,
119112
terrainCover,
120113
useTerrainHeightMap: terrainDrawMode === 'offset',
121114
terrainSkipRender: terrainDrawMode === 'drape' || !layer.props.operation.includes('draw')
@@ -124,9 +117,8 @@ export class TerrainEffect implements Effect {
124117
}
125118

126119
cleanup({deck}: EffectContext): void {
127-
if (this.dummyHeightMap) {
128-
this.dummyHeightMap.delete();
129-
this.dummyHeightMap = undefined;
120+
if (terrainModule.dummyHeightMap) {
121+
terrainModule.dummyHeightMap.delete();
130122
terrainModule.dummyHeightMap = null;
131123
}
132124

@@ -160,7 +152,6 @@ export class TerrainEffect implements Effect {
160152
shaderModuleProps: {
161153
terrain: {
162154
heightMapBounds: this.heightMap.bounds,
163-
dummyHeightMap: this.dummyHeightMap,
164155
drawToTerrainHeightMap: true
165156
},
166157
project: {
@@ -221,7 +212,6 @@ export class TerrainEffect implements Effect {
221212
layers: drapeLayers,
222213
shaderModuleProps: {
223214
terrain: {
224-
dummyHeightMap: this.dummyHeightMap,
225215
terrainSkipRender: false
226216
},
227217
project: {

0 commit comments

Comments
 (0)