Skip to content

Commit 4e986a7

Browse files
dcojgithub-actions[bot]
authored andcommitted
move snow and rain shaders to HD
GitOrigin-RevId: 7b052244ac81fc73c208b526eca7602b9aa6b33a
1 parent 21c8879 commit 4e986a7

6 files changed

Lines changed: 53 additions & 25 deletions

File tree

modules/hd_main.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
import {drawBuilding, shaders} from './hd_main_imports';
1+
import {drawBuilding, drawRasterParticle, prepareRasterParticle, shaders, Rain, Snow, precipitationShaders} from './hd_main_imports';
22

3-
export const HD = {drawBuilding, shaders};
3+
export const HD = {
4+
building: {
5+
draw: drawBuilding,
6+
},
7+
particles: {
8+
draw: drawRasterParticle,
9+
prepare: prepareRasterParticle,
10+
},
11+
precipitation: {
12+
Rain,
13+
Snow,
14+
},
15+
shaders,
16+
precipitationShaders
17+
};
418

519
export async function prepareHD() { return Promise.resolve(); }

modules/hd_main_esm.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export const HD = {};
55
export async function prepareHD() {
66
try {
77
Object.assign(HD, await import('./hd_main_imports'));
8-
98
} catch (error) {
109
warnOnce('Could not load HD module.');
1110
}

modules/hd_main_imports.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
export {default as drawBuilding} from '../3d-style/render/draw_building';
2+
export {default as drawRasterParticle, prepare as prepareRasterParticle} from '../src/render/draw_raster_particle';
23
export {default as shaders} from '../3d-style/shaders/shaders_hd';
4+
export {Rain} from '../src/precipitation/draw_rain';
5+
export {Snow} from '../src/precipitation/draw_snow';
6+
export {default as precipitationShaders} from '../src/shaders/shaders_precipitation';

src/render/painter.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import fillExtrusion from './draw_fill_extrusion';
3131
import {HD, prepareHD} from '../../modules/hd_main';
3232
import hillshade from './draw_hillshade';
3333
import raster, {prepare as prepareRaster} from './draw_raster';
34-
import rasterParticle, {prepare as prepareRasterParticle} from './draw_raster_particle';
3534
import background from './draw_background';
3635
import {default as drawDebug, drawDebugPadding, drawDebugQueryGeometry} from './draw_debug';
3736
import custom from './draw_custom';
@@ -53,8 +52,6 @@ import {WireframeDebugCache} from './wireframe_cache';
5352
import {FOG_OPACITY_THRESHOLD} from '../style/fog_helpers';
5453
import Framebuffer from '../gl/framebuffer';
5554
import {OcclusionParams} from './occlusion_params';
56-
import {Rain} from '../precipitation/draw_rain';
57-
import {Snow} from '../precipitation/draw_snow';
5855
import {PerformanceUtils} from '../util/performance';
5956

6057
import type ImageManager from './image_manager';
@@ -144,7 +141,7 @@ const draw: Record<string, DrawStyleLayer> = {
144141
'fill-extrusion': fillExtrusion,
145142
hillshade,
146143
raster,
147-
'raster-particle': rasterParticle,
144+
'raster-particle': null,
148145
background,
149146
sky,
150147
custom,
@@ -155,7 +152,7 @@ const prepare = {
155152
line: prepareLine,
156153
model: modelPrepare,
157154
raster: prepareRaster,
158-
'raster-particle': prepareRasterParticle
155+
'raster-particle': null
159156
};
160157

161158
const depthPrepass = {
@@ -167,7 +164,9 @@ const groundShadowMask = {
167164

168165
async function setupHD() {
169166
await prepareHD();
170-
draw.building = HD.drawBuilding;
167+
draw.building = HD.building.draw;
168+
draw['raster-particle'] = HD.particles.draw;
169+
prepare['raster-particle'] = HD.particles.prepare;
171170
}
172171

173172
/**
@@ -230,8 +229,8 @@ class Painter {
230229
loadTimeStamps: Array<number>;
231230
_backgroundTiles: Record<number, Tile>;
232231
_atmosphere: Atmosphere | null | undefined;
233-
_rain?: Rain;
234-
_snow?: Snow;
232+
_rain?: InstanceType<typeof HD.precipitation.Rain>;
233+
_snow?: InstanceType<typeof HD.precipitation.Snow>;
235234
replacementSource: ReplacementSource;
236235
conflationActive: boolean;
237236
firstLightBeamLayer: number;
@@ -1093,16 +1092,21 @@ class Painter {
10931092
const snow = this._debugParams.forceEnablePrecipitation || !!(this.style && this.style.snow);
10941093
const rain = this._debugParams.forceEnablePrecipitation || !!(this.style && this.style.rain);
10951094

1096-
if (snow && !this._snow) {
1097-
this._snow = new Snow(this);
1095+
// Load HD for precipitation functionality
1096+
if ((snow || rain) && (!HD.precipitation || !HD.precipitation.Rain || !HD.precipitation.Snow)) {
1097+
void prepareHD();
1098+
}
1099+
1100+
if (snow && !this._snow && HD.precipitation && HD.precipitation.Snow) {
1101+
this._snow = new HD.precipitation.Snow(this);
10981102
}
10991103
if (!snow && this._snow) {
11001104
this._snow.destroy();
11011105
delete this._snow;
11021106
}
11031107

1104-
if (rain && !this._rain) {
1105-
this._rain = new Rain(this);
1108+
if (rain && !this._rain && HD.precipitation && HD.precipitation.Rain) {
1109+
this._rain = new HD.precipitation.Rain(this);
11061110
}
11071111
if (!rain && this._rain) {
11081112
this._rain.destroy();
@@ -1731,7 +1735,7 @@ class Painter {
17311735
const globalDefines = this.currentGlobalDefines(name, overrideFog, overrideRtt);
17321736
const allDefines = globalDefines.concat(defines);
17331737

1734-
const shaderSource = shaders[name as keyof typeof shaders] || HD.shaders[name as keyof typeof HD.shaders];
1738+
const shaderSource = shaders[name as keyof typeof shaders] || (HD.shaders && HD.shaders[name as keyof typeof HD.shaders]) || (HD.precipitationShaders && HD.precipitationShaders[name as keyof typeof HD.precipitationShaders]);
17351739
const key = Program.cacheKey(shaderSource, name, allDefines, config);
17361740

17371741
if (!this.cache[key]) {

src/shaders/shaders.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ import atmosphereFrag from './atmosphere.fragment.glsl';
7272
import atmosphereVert from './atmosphere.vertex.glsl';
7373
import starsFrag from './stars.fragment.glsl';
7474
import starsVert from './stars.vertex.glsl';
75-
import snowFrag from './snow_particle.fragment.glsl';
76-
import snowVert from './snow_particle.vertex.glsl';
77-
import rainFrag from './rain_particle.fragment.glsl';
78-
import rainVert from './rain_particle.vertex.glsl';
79-
import vignetteFrag from './vignette.fragment.glsl';
80-
import vignetteVert from './vignette.vertex.glsl';
8175
import occlusionFrag from './occlusion.fragment.glsl';
8276
import occlusionVert from './occlusion.vertex.glsl';
8377
import elevatedStructuresDepthReconstructFrag from '../../3d-style/shaders/elevated_structures_depth_reconstruct.fragment.glsl';
@@ -201,9 +195,6 @@ export default {
201195
model: compile(modelFrag, modelVert),
202196
modelDepth: compile(modelDepthFrag, modelDepthVert),
203197
stars: compile(starsFrag, starsVert),
204-
snowParticle: compile(snowFrag, snowVert),
205-
rainParticle: compile(rainFrag, rainVert),
206-
vignette: compile(vignetteFrag, vignetteVert),
207198
occlusion: compile(occlusionFrag, occlusionVert)
208199
} as const;
209200

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
2+
/// <reference path="../types/glsl.d.ts" />
3+
4+
import snowFrag from './snow_particle.fragment.glsl';
5+
import snowVert from './snow_particle.vertex.glsl';
6+
import rainFrag from './rain_particle.fragment.glsl';
7+
import rainVert from './rain_particle.vertex.glsl';
8+
import vignetteFrag from './vignette.fragment.glsl';
9+
import vignetteVert from './vignette.vertex.glsl';
10+
import {compile} from './shaders';
11+
12+
export default {
13+
snowParticle: compile(snowFrag, snowVert),
14+
rainParticle: compile(rainFrag, rainVert),
15+
vignette: compile(vignetteFrag, vignetteVert)
16+
};

0 commit comments

Comments
 (0)