Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cesium-post-process/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Cesium runs the stages in the order they are added and cannot insert one elsewhe

Its `snow`, from 0 to 1, turns the rain to snow in one population, so that nothing in between looks like two kinds of precipitation falling together: the drops slow down from 9 m/s to 1 m/s (geometrically, so 3 m/s at 0.5, as in sleet), their streak, the motion over the exposure, shortens until they are round flakes, their thin sharp line grows into a soft flake that flutters across its cell at its own rate, the nearest layer out of focus as in Andrew Baldwin's "Just snow" (Shadertoy), and there are more of them, as there are in a snowfall; the haze goes from the rain's to the snow's, thicker, from 20 km of visibility to 500 m, with lighter shafts and a brighter light the flakes scatter. Each drop is a capsule from a point in its cell to the end of its trail. The cells of the grid are taller than wide in the rain and square in the snow, so that a trail stays within the cell above the pixel's: animating `snow` stretches the whole field smoothly along the fall, and the scroll along the fall is added up from frame to frame, as the speed changes with it. The cost does not depend on `snow`: about 4.3 to 4.8 ms at 1920 x 1024 on an Intel UHD 630, mostly the four layers; the layers' constants are computed once per frame on the CPU, and each pixel first rejects the drops that are nowhere near it. Wang and Wade's precipitation for Flight Simulator 2004 ("Rendering Falling Rain and Snow", 2004) also draws both with one technique. Several may be active at once: the one with the most rain at the camera dims the scene and turns the shadows off, the last one deactivated restores them.

`RainRings` lays the ground out in cells of a local frame, east-north-up about `origin`, and in each lands a drop, as often as `intensity` says, where the cell's hash puts it: a thin ring grows from it over about 0.6 s and fades, on what is flatter than `maxSlope`, wider and slower where the surface is within a quarter meter of `waterLevel`. It finds the surfaces from the depth, so it rings the ground, the roofs and the water alike and nothing in the air, and tells the slope from the normal rebuilt from the neighboring pixels. The cells are in a local frame with the globe's offset cancelled in double precision on the CPU (`localFromEye`), so they stay where they are as the camera moves and do not step by half a meter with the single-precision world coordinates a shader gets. A ring never grows past 0.3 cell, so that its cell's edge does not clip it, and fades out where a pixel is wider than 8 to 20 cm on the ground, where it would only be a speckle. It renders the scene 30 times a second while active with an intensity, also in `requestRenderMode`. Without an `openSky` it has no sense of what is under a roof: rain does not fall there, and the rings do.
`RainRings` lays the ground out in cells of a local frame, east-north-up about `origin`, and in each lands a drop, as often as `intensity` says, where the cell's hash puts it: a ripple grows from it over about 0.6 s, its radius with the square root of its age, fast then slowing as a ripple's front, fading in over its first tenth and out as it grows, on what is flatter than `maxSlope`, wider and slower where the surface is within a quarter meter of `waterLevel`. It finds the surfaces from the depth, so it rings the ground, the roofs and the water alike and nothing in the air, and tells the slope from the normal rebuilt from the neighboring pixels. The cells are in a local frame with the globe's offset cancelled in double precision on the CPU (`localFromEye`), so they stay where they are as the camera moves and do not step by half a meter with the single-precision world coordinates a shader gets. Its crest is a Gaussian bump shaded by its slope toward the light along the ground, the side facing the light lighter and the other darker, as a crest added to the surface's normal would be lit, so it reads as relief rather than a painted circle, flat once the sun is under the horizon; `color` tints it and sets how strongly it shows. Each pixel sums the rings of its cell and of the neighboring cells a ring can reach it from, so a ring crosses its cell's edge, its crest never reaching past a cell; a pixel too wide, covered or too steep skips them all. A ring across the water's edge changes its pace and reach there: each pixel's own wetness sets them. On an Intel UHD 630 at 1201 x 647, 4 m above the ground, the rings take 3.2 ms of the frame. A ring fades out where a pixel is wider than 8 to 20 cm on the ground, where it would only be a speckle. It renders the scene 30 times a second while active with an intensity, also in `requestRenderMode`. Without an `openSky` it has no sense of what is under a roof: rain does not fall there, and the rings do.

`Clouds` fills a slab above the cloud base from a map of the rain, from which it derives a map of the clouds on the CPU, about 60 ms for the 1024 x 768 radar map, once for each map: a radar sees the rain rather than the clouds, so the rain is dilated by 5 km and softened into a cloud shield wider than it, broken over dry ground and full over the rain, and the rain rate sets the clouds' type, from a flat deck 1500 m thick over drizzle to towers up to `cloudTop` from 10 mm/h, `remap(log(R), log(0.5), log(10), 0, 1)`, the precipitation turning the map "to cumulonimbus clouds" as in Schneider's "The Real-Time Volumetric Cloudscapes of Horizon Zero Dawn" (2015). Neither their bases nor their tops are flat: the base of each column rises and falls by 300 m with a 2 km noise and lies up to 250 m lower under the heaviest rain, the noise carving the lowest eighth of the column into an uneven underside; the deck is full up to half its height and thins out to a top that rises and falls by 30 % of its depth with the coverage's noise, higher where the clouds are fuller; the slab the march and the shadow map cover reaches as low and as high. The towers thin out upward in the convective envelope of Schneider's "Nubis, Evolved" (2022) and spreading an anvil near their top, as in his "Nubis: Authoring Real-Time Volumetric Cloudscapes" (2017); the map is read jittered by a third of a cell of noise, so its 1 km squares do not show, and the coverage varies by 40 % with an 8 km noise that is not the billows' (Högfeldt 2016), both from a 256 x 256 square of noise made once that tiles every 64 cells of the map, read once rather than computed at each sample. Their shape is a noise made once on the CPU, about a third of a second for the page: a 64³ cube that repeats every 16 km, with billows of Perlin-Worley noise for the base shape and Worley noise at two finer scales for the details, which erode the edges of the cloud but not its core, as wisps at its base and billows above; on the upper part of the towers, the 1 km billows with the finest details on them also push the surface out, into cauliflower lobes (Schneider 2022's billowy composite), the decks left flat, fading out from about 8 to 15 km away at 1280 pixels across, where a pixel is marched too seldom to build their shading; and a 32³ cube of Worley noise that repeats every 2 km for the finest details, 62.5 m voxels, read only on the edges and only where a pixel is smaller than 250 m, so far views and the shadow map do not pay for it: on an Intel UHD 630 it adds nothing measurable to the frame. The height profile times the coverage carves the noise rather than scaling it, `saturate(noise - (1 - profile))` (Schneider 2022), so the core stays solid and only the highest billows reach the top, ramping up over a softness that grows with the distance rather than sharpened by a power as in "Nubis Cubed" (2023), which between the march's steps would show as contour lines. It is a 3D texture read with its mipmaps at the footprint of the pixels, and a second, four times larger read of it breaks up the repetition of the tile in far views; the details fade out and the edges soften with the distance, so the far clouds do not alias. The clouds are raymarched for one pixel of each block of 4 x 4 at each frame, a 16th of the pixels, in the order of a Bayer matrix, along each view ray in 64 fine steps, short near the camera and longer with the distance: across the empty air a coarse step spans four of them, and where it finds a cloud the march steps back and goes on fine, lighting each sample, until four fine samples in a row find none (the cheap and expensive samples of Schneider 2015), at most 48 samples a ray; once a fifth of what lies behind is hidden, a sample is lit from the shadow map alone; and the clouds fade out over the last 40 % of the march, so its end is not an edge: each ray first probes a map of the highest rain around 4 km blocks at 8 points, so the march starts at the tallest cloud it can meet, rather than in the empty air above the clouds, and is skipped where it meets none; each step's light is integrated over it, its start along the ray random for each pixel and moved at each of its marches; the march's light, transmittance and the distance of the clouds it sees, weighted by the light they hide, are packed in one texture of 32-bit floats. A pass at the full resolution builds the clouds from them over the frames, as Schneider's (2015) temporal reprojection: the pixel marched this frame blends its new sample into its history, the others take their history, reprojected through the clouds' distance (Sakmary 2022), read through a Catmull-Rom filter so that it does not blur a little more at each frame, and while the view moves, clamped around the fresh samples upsampled to the pixel; while it is still, a pixel's n-th sample weighs 1 / n, down to a fifth, a running mean of its own samples. A pixel whose scene is nearer than where its ray enters the slab has no cloud in front of it, so a ridge keeps its outline against the clouds. The sun lights them through two samples toward it, 700 m at most, three among the lobes, 60, 180 and 500 m away, the first through the lobes with a cumulus' edge extinction of 0.01 per meter, so that a lobe shades the crevice behind it, and deep in a cloud through as much cloud as the shadow map finds on the whole way to it, so it does not shine through a thin spot of a thick deck, with the light scattered more than once as two octaves (Hillaire 2016) and a Henyey-Greenstein phase function with a broad forward lobe and a narrow one, its eccentricity 0.87 at a third of the strength, for the silver lining of the thin edges near the sun (Schneider 2015); the sun's light on them takes the hue of its way through Cesium's atmosphere, its Rayleigh and Mie extinction over the air mass at its elevation, three quarters of it, white overhead and warm toward the horizon, as bright as a sun overhead until a few degrees above the horizon, where it dims; the sky lights them in the color of Cesium's sky overhead and the ground from below, less in their core than at their edges and least at their base, the sun and the clear sky on the top of the clouds also reach their lower parts scattered many times, by the transmission of the clouds above them, 1 / (1 + 0.75 (1 - g) tau) in the two-stream approximation less the direct beam, their optical depth read from the shadow map, so an overcast is gray from below, lighter under its thin parts and darker under its thick ones; and the clouds over heavy rain absorb two fifths of their light, so their tops are white from above. At night the moon lights them from its direction, a tenth of the sun's light in a faintly cool tint, as it rises above the horizon, through the same samples toward it and phase function. The far clouds fade into the sky behind them by Cesium's fog factor, by distance as the terrain does, rather than a haze thinning with the height, which would set them apart from the terrain at the horizon. The shadow map holds, across a square around the camera seen from the sun, 80 km wide or four times as wide as the camera is high up to 800 km, fading out toward its edges, the clouds' optical depth from the top of the slab down to each quarter of its height, 512 x 512 texels marched 16 steps each, but for those whose rays meet no clouds, drawn again only when the camera moves a 40th of its width, the clock moves the light by more than a minute or the clouds change, at most 4 times a second: the clouds cast their shadows on the terrain and light `Precipitation`'s haze through their gaps. Seen from far above they are cloud tops; coming down, the camera flies into them and the view turns to fog; activated before `Precipitation`, its drops, shafts and haze are drawn over the clouds, so from below the cloud base they are seen through the rain; from above, `Precipitation` leaves the rain under the cloud base to them, its shafts and haze hidden while clouds are active in the scene. Use the same `map` and `cloudBase` as `Precipitation`. Both crossfade from their `map` to a `nextMap` over the same rectangle and of the same size by `mapBlend`, 0 to 1, as the radar from one hour to the next: one more read of the map for each of its lookups. Without a map there are no clouds. The clouds stand still where the map puts them; they move with the map's crossfade to its `nextMap`. After the camera or the clouds change, or the clock moves the light by more than a minute, the scene renders at 30 frames per second for two seconds, four samples of each pixel, for the accumulation to settle, also with `requestRenderMode`, then rests; a clock playing at its own pace, and a `mapBlend` moving with it by less than a 60th, change nothing between frames, the running mean following them. Each ray is marched at most 40 km into the slab: farther, a grazing ray's steps would be longer than the billows and the clouds on the horizon would turn to streaks. On an Intel UHD 630 at 1280 x 629, measured by the GPU's timer queries, they add about 4.6 to 5.8 ms to the frame seen from 14 km above, 4.5 ms at an angle from 7 km, 6.3 ms inside the clouds, 3.8 ms from below them, 3.4 ms toward clouds on the horizon and 7.6 ms beside towers a few kilometers away, about 1 ms of it for their lobes; drawing the shadow map again, while the map crossfades, adds no more than a few milliseconds to those frames.

Expand Down
12 changes: 7 additions & 5 deletions packages/cesium-post-process/src/rain-rings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const TIME_PERIOD = 3600;
const NO_WATER = 1e9;

/**
* Rings where the rain lands: on the ground, the roofs and the water, in each cell of a local frame a drop landing, a thin ring growing from it
* and fading, wider and slower on water. For a view of a place from far enough that the drops themselves are too small to see; or under
* Rings where the rain lands: on the ground, the roofs and the water, in each cell of a local frame a drop landing, a ripple growing from it
* and fading, shaded as a crest by the light, wider and slower on water. For a view of a place from far enough that the drops themselves are too small to see; or under
* `Precipitation`, the drops falling and these where they land. Found from the depth, with the surface's slope from the normal rebuilt from the
* neighboring pixels: nothing lies in the air.
*/
Expand All @@ -45,7 +45,7 @@ export default class RainRings extends Effect {
* @param {CesiumWidget} viewer
* @param {{name?: string, intensity?: number, cell?: number, reach?: number, waterLevel?: number, maxSlope?: number, rate?: number,
* color?: Color, origin?: Cartesian3, clock?: () => number, openSky?: OpenSky}} [options] The share of the cells that have a drop, 0 to 1; the cell's size
* and the ring's growth on the ground, in meters (the ring on water is clipped at 0.3 cell); the water's height above the ellipsoid, in
* and the ring's growth on the ground, in meters (its crest never past a cell); the water's height above the ellipsoid, in
* meters, or undefined for none; the steepest slope that takes a ring, in degrees; rings a second in a cell; the ring's color, its alpha how
* strongly it shows; the point of the world the cells are laid about; the time the rings run by, in seconds (the wall clock's by default;
* one that stands still keeps them still, for a viewer who asks for less motion); what is open to the sky, the rest taking none (all
Expand Down Expand Up @@ -147,7 +147,8 @@ export default class RainRings extends Effect {
}

/**
* How far a ring grows on the ground, in meters: over water, 1.7 times as far, but never past 0.3 cell, or the edge of its cell would clip it.
* How far a ring grows on the ground, in meters: over water, 1.7 times as far, but its crest never past a cell, the farthest the
* neighboring cells a pixel sums reach.
*/
get reach() {
return this.#reach;
Expand Down Expand Up @@ -196,7 +197,8 @@ export default class RainRings extends Effect {
}

/**
* The ring's color, its alpha how strongly it shows. Slate on a light ground, pale on a dark one.
* The ring's color, its alpha how strongly it shows: the crest tinted by half of it, and lit and shaded by its slope toward the light by
* up to 0.8 of it. Slate on a light ground, pale on a dark one.
*/
get color() {
return this.#color;
Expand Down
9 changes: 8 additions & 1 deletion packages/cesium-post-process/src/rain-rings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ test('without an origin, they are laid about where the camera was when the effec
test('a cell has a drop only if its hash is under the intensity: a hash of exactly 0, the origin cell\'s, is no drop at no rain', () => {
const viewer = fakeViewer();
const {fragmentShader} = new RainRings(viewer).createStage_(viewer.scene);
assert.match(fragmentShader, /float\(hash\(id\) < intensity\)/);
assert.match(fragmentShader, /hash\(id\) >= intensity\) \{\s*continue;/);
assert.doesNotMatch(fragmentShader, /step\(hash\(id\)/);
});

test('a ring grows with the square root of its age, is shaded by the light along the ground', () => {
const viewer = fakeViewer();
const {fragmentShader} = new RainRings(viewer).createStage_(viewer.scene);
assert.match(fragmentShader, /sqrt\(age\)/);
assert.match(fragmentShader, /czm_lightDirectionEC/);
});

test('the stage shares the depth effects\' chunks: the eye from the depth, the height, the rebuilt normal', () => {
const viewer = fakeViewer();
const {fragmentShader} = new RainRings(viewer).createStage_(viewer.scene);
Expand Down
Loading