@@ -8,7 +8,7 @@ import StencilMode from '../../src/gl/stencil_mode';
88import { getMetersPerPixelAtLatitude } from '../../src/geo/mercator_coordinate' ;
99import { Debug } from '../../src/util/debug' ;
1010import { DevTools } from '../../src/ui/devtools' ;
11- import { drawGroundEffect as fillExtrusionDrawGroundEffect , GroundEffectProperties , frustumCullShadowCaster } from '../../src/render/draw_fill_extrusion' ;
11+ import { drawGroundEffect as fillExtrusionDrawGroundEffect , GroundEffectProperties , frustumCullShadowCaster , computeFrontCutoffParams } from '../../src/render/draw_fill_extrusion' ;
1212import Color from '../../src/style-spec/util/color' ;
1313import ColorMode from '../../src/gl/color_mode' ;
1414import { PerformanceUtils } from '../../src/util/performance' ;
@@ -55,6 +55,14 @@ function drawTiles(params: DrawParams) {
5555 defines = defines . concat ( 'RENDER_CUTOFF' ) ;
5656 }
5757
58+ const frontCutoffArray = layer . paint . get ( 'building-front-cutoff' ) ;
59+ const frontCutoffEnabled = frontCutoffArray [ 2 ] < 1.0 && ! painter . terrain ;
60+ const frontCutoffParams = computeFrontCutoffParams ( painter . transform . pitch , frontCutoffArray , ! ! painter . terrain ) ;
61+ if ( frontCutoffEnabled ) {
62+ defines = defines . concat ( 'RENDER_FRONT_CUTOFF' ) ;
63+ painter . maxFrontCutoffRawStart = Math . max ( painter . maxFrontCutoffRawStart , frontCutoffArray [ 0 ] ) ;
64+ }
65+
5866 if ( params . floodLightIntensity > 0.0 ) {
5967 defines = defines . concat ( 'FLOOD_LIGHT' ) ;
6068 }
@@ -120,7 +128,7 @@ function drawTiles(params: DrawParams) {
120128 mercCameraPos . z * tiles * EXTENT
121129 ] ;
122130
123- uniformValues = buildingUniformValues ( matrix , normalMatrix , params . opacity , params . facadeAOIntensity , cameraPos , bucket . tileToMeter , params . facadeEmissiveChance , params . floodLightColor , params . floodLightIntensity ) ;
131+ uniformValues = buildingUniformValues ( matrix , normalMatrix , params . opacity , params . facadeAOIntensity , cameraPos , bucket . tileToMeter , params . facadeEmissiveChance , params . floodLightColor , params . floodLightIntensity , frontCutoffParams ) ;
124132
125133 programWithoutFacades = painter . getOrCreateProgram ( 'building' ,
126134 { config : programConfiguration , defines, overrideFog : false } ) ;
@@ -225,7 +233,7 @@ class DrawBuildingsDebugParams {
225233 }
226234}
227235
228- function drawGroundEffect ( painter : Painter , source : SourceCache , layer : BuildingStyleLayer , coords : Array < OverscaledTileID > , aoPass : boolean , opacity : number , aoIntensity : number , aoRadius : number , floodLightIntensity : number , floodLightColor : [ number , number , number ] , attenuationFactor : number , replacementActive : boolean , renderNeighbors : boolean ) {
236+ function drawGroundEffect ( painter : Painter , source : SourceCache , layer : BuildingStyleLayer , coords : Array < OverscaledTileID > , aoPass : boolean , opacity : number , aoIntensity : number , aoRadius : number , floodLightIntensity : number , floodLightColor : [ number , number , number ] , attenuationFactor : number , replacementActive : boolean , renderNeighbors : boolean , frontCutoffParams ?: [ number , number , number ] ) {
229237 const lerp = ( a : number , b : number , t : number ) => { return ( 1 - t ) * a + t * b ; } ;
230238
231239 const gl = painter . context . gl ;
@@ -242,15 +250,15 @@ function drawGroundEffect(painter: Painter, source: SourceCache, layer: Building
242250 const stencilSdfPass = new StencilMode ( { func : gl . ALWAYS , mask : 0xFF } , 0xFF , 0xFF , gl . KEEP , gl . KEEP , gl . REPLACE ) ;
243251 const colorSdfPass = new ColorMode ( [ gl . ONE , gl . ONE , gl . ONE , gl . ONE ] , Color . transparent , [ false , false , false , true ] , gl . MIN ) ;
244252
245- fillExtrusionDrawGroundEffect ( groundEffectProps , painter , source , layer , coords , depthMode , stencilSdfPass , colorSdfPass , CullFaceMode . disabled , aoPass , 'sdf' , opacity , aoIntensity , aoRadius , floodLightIntensity , floodLightColor , attenuation , conflateLayer , false ) ;
253+ fillExtrusionDrawGroundEffect ( groundEffectProps , painter , source , layer , coords , depthMode , stencilSdfPass , colorSdfPass , CullFaceMode . disabled , aoPass , 'sdf' , opacity , aoIntensity , aoRadius , floodLightIntensity , floodLightColor , attenuation , conflateLayer , false , undefined , frontCutoffParams ) ;
246254 }
247255
248256 {
249257 // Draw the effects.
250258 const stencilColorPass = showOverdraw ? StencilMode . disabled : new StencilMode ( { func : gl . EQUAL , mask : 0xFF } , 0xFF , 0xFF , gl . KEEP , gl . DECR , gl . DECR ) ;
251259 const colorColorPass = showOverdraw ? painter . colorModeForRenderPass ( ) : new ColorMode ( [ gl . ONE_MINUS_DST_ALPHA , gl . DST_ALPHA , gl . ONE , gl . ONE ] , Color . transparent , [ true , true , true , true ] ) ;
252260
253- fillExtrusionDrawGroundEffect ( groundEffectProps , painter , source , layer , coords , depthMode , stencilColorPass , colorColorPass , CullFaceMode . disabled , aoPass , 'color' , opacity , aoIntensity , aoRadius , floodLightIntensity , floodLightColor , attenuation , conflateLayer , false ) ;
261+ fillExtrusionDrawGroundEffect ( groundEffectProps , painter , source , layer , coords , depthMode , stencilColorPass , colorColorPass , CullFaceMode . disabled , aoPass , 'color' , opacity , aoIntensity , aoRadius , floodLightIntensity , floodLightColor , attenuation , conflateLayer , false , undefined , frontCutoffParams ) ;
254262 }
255263}
256264
@@ -422,11 +430,14 @@ function draw(painter: Painter, source: SourceCache, layer: BuildingStyleLayer,
422430 floodLightColor
423431 } ) ;
424432
433+ const geFrontCutoffArray = layer . paint . get ( 'building-front-cutoff' ) ;
434+ const geFrontCutoffParams = computeFrontCutoffParams ( painter . transform . pitch , geFrontCutoffArray , ! ! painter . terrain ) ;
435+
425436 if ( aoEnabled ) {
426- drawGroundEffect ( painter , source , layer , coords , true , opacity , aoIntensity , aoRadius , floodLightIntensity , floodLightColor , aoGroundAttenuation , conflateLayer , false ) ;
437+ drawGroundEffect ( painter , source , layer , coords , true , opacity , aoIntensity , aoRadius , floodLightIntensity , floodLightColor , aoGroundAttenuation , conflateLayer , false , geFrontCutoffParams ) ;
427438 }
428439 if ( floodLightEnabled ) {
429- drawGroundEffect ( painter , source , layer , coords , false , opacity , aoIntensity , aoRadius , floodLightIntensity , floodLightColor , floodLightGroundAttenuation , conflateLayer , false ) ;
440+ drawGroundEffect ( painter , source , layer , coords , false , opacity , aoIntensity , aoRadius , floodLightIntensity , floodLightColor , floodLightGroundAttenuation , conflateLayer , false , geFrontCutoffParams ) ;
430441 }
431442 } else if ( painter . renderPass === 'light-beam' && drawLayer ) {
432443 const definesForPass : Array < DynamicDefinesType > = [
0 commit comments