@@ -8,13 +8,15 @@ import SceneMode from "./SceneMode.js";
88function GlobeSurfaceShader (
99 numberOfDayTextures ,
1010 flags ,
11+ flags2 ,
1112 material ,
1213 shaderProgram ,
1314 clippingShaderState ,
14- clippingPolygonShaderState ,
15+ clippingPolygonShaderState
1516) {
1617 this . numberOfDayTextures = numberOfDayTextures ;
1718 this . flags = flags ;
19+ this . flags2 = flags2 ;
1820 this . material = material ;
1921 this . shaderProgram = shaderProgram ;
2022 this . clippingShaderState = clippingShaderState ;
@@ -134,6 +136,7 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
134136 const hasExaggeration = options . hasExaggeration ;
135137 const showUndergroundColor = options . showUndergroundColor ;
136138 const translucent = options . translucent ;
139+ const splitTerrain = options . splitTerrain ;
137140
138141 let quantization = 0 ;
139142 let quantizationDefine = "" ;
@@ -165,39 +168,40 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
165168 // Flags beyond bit 31 use arithmetic to avoid silent wrap-around
166169 // (x << 32 === x << 0 in JavaScript).
167170 const flags =
168- ( ( sceneMode |
169- ( applyBrightness << 2 ) |
170- ( applyContrast << 3 ) |
171- ( applyHue << 4 ) |
172- ( applySaturation << 5 ) |
173- ( applyGamma << 6 ) |
174- ( applyAlpha << 7 ) |
175- ( hasWaterMask << 8 ) |
176- ( showReflectiveOcean << 9 ) |
177- ( showOceanWaves << 10 ) |
178- ( enableLighting << 11 ) |
179- ( dynamicAtmosphereLighting << 12 ) |
180- ( dynamicAtmosphereLightingFromSun << 13 ) |
181- ( showGroundAtmosphere << 14 ) |
182- ( perFragmentGroundAtmosphere << 15 ) |
183- ( hasVertexNormals << 16 ) |
184- ( useWebMercatorProjection << 17 ) |
185- ( enableFog << 18 ) |
186- ( quantization << 19 ) |
187- ( applySplit << 20 ) |
188- ( enableClippingPlanes << 21 ) |
189- ( enableClippingPolygons << 22 ) |
190- ( cartographicLimitRectangleFlag << 23 ) |
191- ( imageryCutoutFlag << 24 ) |
192- ( colorCorrect << 25 ) |
193- ( highlightFillTile << 26 ) |
194- ( colorToAlpha << 27 ) |
195- ( hasGeodeticSurfaceNormals << 28 ) |
196- ( hasExaggeration << 29 ) |
197- ( showUndergroundColor << 30 ) |
198- ( translucent << 31 ) ) >>>
199- 0 ) +
200- ( applyDayNightAlpha ? 0x100000000 : 0 ) ;
171+ sceneMode |
172+ ( applyBrightness << 2 ) |
173+ ( applyContrast << 3 ) |
174+ ( applyHue << 4 ) |
175+ ( applySaturation << 5 ) |
176+ ( applyGamma << 6 ) |
177+ ( applyAlpha << 7 ) |
178+ ( hasWaterMask << 8 ) |
179+ ( showReflectiveOcean << 9 ) |
180+ ( showOceanWaves << 10 ) |
181+ ( enableLighting << 11 ) |
182+ ( dynamicAtmosphereLighting << 12 ) |
183+ ( dynamicAtmosphereLightingFromSun << 13 ) |
184+ ( showGroundAtmosphere << 14 ) |
185+ ( perFragmentGroundAtmosphere << 15 ) |
186+ ( hasVertexNormals << 16 ) |
187+ ( useWebMercatorProjection << 17 ) |
188+ ( enableFog << 18 ) |
189+ ( quantization << 19 ) |
190+ ( applySplit << 20 ) |
191+ ( enableClippingPlanes << 21 ) |
192+ ( enableClippingPolygons << 22 ) |
193+ ( cartographicLimitRectangleFlag << 23 ) |
194+ ( imageryCutoutFlag << 24 ) |
195+ ( colorCorrect << 25 ) |
196+ ( highlightFillTile << 26 ) |
197+ ( colorToAlpha << 27 ) |
198+ ( hasGeodeticSurfaceNormals << 28 ) |
199+ ( hasExaggeration << 29 ) |
200+ ( showUndergroundColor << 30 ) |
201+ ( translucent << 31 ) ;
202+
203+ // More bit flags that don't fit in the first `flag`
204+ const flags2 = applyDayNightAlpha | ( splitTerrain << 2 ) ;
201205
202206 let currentClippingShaderState = 0 ;
203207 if ( defined ( clippingPlanes ) && clippingPlanes . length > 0 ) {
@@ -218,6 +222,7 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
218222 defined ( surfaceShader ) &&
219223 surfaceShader . numberOfDayTextures === numberOfDayTextures &&
220224 surfaceShader . flags === flags &&
225+ surfaceShader . flags2 === flags2 &&
221226 surfaceShader . material === this . material &&
222227 surfaceShader . clippingShaderState === currentClippingShaderState &&
223228 surfaceShader . clippingPolygonShaderState ===
@@ -232,7 +237,12 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
232237 shadersByFlags = this . _shadersByTexturesFlags [ numberOfDayTextures ] = [ ] ;
233238 }
234239
235- surfaceShader = shadersByFlags [ flags ] ;
240+ let shadersByFlags2 = shadersByFlags [ flags ] ;
241+ if ( ! defined ( shadersByFlags2 ) ) {
242+ shadersByFlags2 = shadersByFlags [ flags2 ] = [ ] ;
243+ }
244+
245+ surfaceShader = shadersByFlags2 [ flags2 ] ;
236246 if (
237247 ! defined ( surfaceShader ) ||
238248 surfaceShader . material !== this . material ||
@@ -247,7 +257,7 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
247257 // Need to go before GlobeFS
248258 if ( currentClippingShaderState !== 0 ) {
249259 fs . sources . unshift (
250- getClippingFunction ( clippingPlanes , frameState . context ) ,
260+ getClippingFunction ( clippingPlanes , frameState . context )
251261 ) ;
252262 }
253263
@@ -261,7 +271,7 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
261271 fs . defines . push (
262272 `TEXTURE_UNITS ${ numberOfDayTextures } ` ,
263273 cartographicLimitRectangleDefine ,
264- imageryCutoutDefine ,
274+ imageryCutoutDefine
265275 ) ;
266276
267277 if ( applyBrightness ) {
@@ -359,10 +369,10 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
359369 }
360370
361371 fs . defines . push (
362- `CLIPPING_POLYGON_REGIONS_LENGTH ${ clippingPolygons . extentsCount } ` ,
372+ `CLIPPING_POLYGON_REGIONS_LENGTH ${ clippingPolygons . extentsCount } `
363373 ) ;
364374 vs . defines . push (
365- `CLIPPING_POLYGON_REGIONS_LENGTH ${ clippingPolygons . extentsCount } ` ,
375+ `CLIPPING_POLYGON_REGIONS_LENGTH ${ clippingPolygons . extentsCount } `
366376 ) ;
367377 }
368378
@@ -382,6 +392,10 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
382392 vs . defines . push ( "EXAGGERATION" ) ;
383393 }
384394
395+ if ( splitTerrain ) {
396+ fs . defines . push ( "SPLIT_TERRAIN" ) ;
397+ }
398+
385399 let computeDayColor =
386400 "\
387401 vec4 computeDayColor(vec4 initialColor, vec3 textureCoordinates, float nightBlend)\n\
@@ -447,22 +461,25 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
447461 attributeLocations : terrainEncoding . getAttributeLocations ( ) ,
448462 } ) ;
449463
450- surfaceShader = shadersByFlags [ flags ] = new GlobeSurfaceShader (
464+ surfaceShader = new GlobeSurfaceShader (
451465 numberOfDayTextures ,
452466 flags ,
467+ flags2 ,
453468 this . material ,
454469 shader ,
455470 currentClippingShaderState ,
456- currentClippingPolygonsShaderState ,
471+ currentClippingPolygonsShaderState
457472 ) ;
473+
474+ shadersByFlags2 [ flags2 ] = surfaceShader ;
458475 }
459476
460477 surfaceTile . surfaceShader = surfaceShader ;
461478 return surfaceShader . shaderProgram ;
462479} ;
463480
464481GlobeSurfaceShaderSet . prototype . destroy = function ( ) {
465- let flags ;
482+ let flags , flags2 ;
466483 let shader ;
467484
468485 const shadersByTexturesFlags = this . _shadersByTexturesFlags ;
@@ -475,9 +492,14 @@ GlobeSurfaceShaderSet.prototype.destroy = function () {
475492
476493 for ( flags in shadersByFlags ) {
477494 if ( shadersByFlags . hasOwnProperty ( flags ) ) {
478- shader = shadersByFlags [ flags ] ;
479- if ( defined ( shader ) ) {
480- shader . shaderProgram . destroy ( ) ;
495+ const shadersByFlags2 = shadersByFlags [ flags ] ;
496+ for ( flags2 in shadersByFlags2 ) {
497+ if ( shadersByFlags2 . hasOwnProperty ( flags2 ) ) {
498+ shader = shadersByFlags2 [ flags2 ] ;
499+ if ( defined ( shader ) ) {
500+ shader . shaderProgram . destroy ( ) ;
501+ }
502+ }
481503 }
482504 }
483505 }
0 commit comments