five-on-it / apps/client/src/renderer/occluders
apps/client/src/renderer/occluders
Buildings that fade: a tall building that stands between the camera and the car the player drives is drawn see-through while it hides it, so the car stays in sight behind a tower (the user's report: "the car is hidden by a big building when driving behind it"). Only while driving, and only where it makes sense: on foot nothing hides the player but a building the camera stands inside, and a building that is short, or no taller than the car stands plus a few metres, is left as it is.
- Candidates. Every building of the level at least OCCLUDERS
.minHeighttall, counting the walk-in storeys stacked on it (a landmark's upper floors are structures that fade over a player inside:overhead.ts), as a box turned with its placement, kept in a grid of OCCLUDERS.cellmetres. - Each frame, at the wheel. Three rays from the camera to the car (its middle a metre up, and two metres ahead and behind): a building fades when the middle ray, or two of the three, pass through it, and its top stands OCCLUDERS
.clearanceover the car. It stays faded OCCLUDERS.holdseconds after the last ray, so it never flickers; at most OCCLUDERS.mostat once, the nearest to the car first. - The camera inside a building. Right behind a tower taller than the camera stands, the camera's eye is inside it and the screen shows nothing but its walls: in any mode, on foot too, a building whose box holds the eye fades the same way, first of the four.
- Drawn. A building is baked into its cell's batch (
level-batches.ts): fading, it is folded out of the batch and a copy of it drawn instead (made then, from the level's mesh, in the world), easing to OCCLUDERS.fadedwith a depth pass first (its own back walls stay hidden); back at full, the batch draws it again and the copy goes. The copies' material is compiled at load, so the first fade never stalls a frame. A walk-in building's storeys fade with it, throughoverhead.ts, the one writer of their visibility (the smaller of its own and this).
The geometry (the boxes, the rays, which fade when) is pure and tested without Babylon; createOccluderFade draws it.