Repository navigation
Feature/sky prefabs - #115
Merged
Merged
Conversation
Five prefabs that each work on their own and build on each other when several are in the scene, through a shared skySystem that advances them every rendered frame: - Sun: the time of day (and day of year, latitude, north) moves the sun, the moon and the stars, and drives the world's sun light (colour through the air, shadow square around the camera) and an ambient light. After dark the moon takes over, as bright as its phase. dayLength lets the day go by on its own - Sky: a physically based dome (Hillaire's sky-view LUT with multiple scattering), the sun's disc, the moon lit by the sun, stars turning around the pole. Lights the scene with an environment map of itself, made again as the sun moves, and turns on ACES tone mapping when the scene had none. Without a Sun it follows the world's sun light - Atmosphere: the air's haze, blue and sea level, and the aerial perspective on every material with fog; a distance scale gives small scenes haze - Wind: a velocity with gusts and a wandering direction; an arrow shows it in the editor - Clouds: the volumetric cumulus layer from base-jump, lit by the sun or moon, drifting with the Wind, hazed by the Atmosphere and shading the ground through the sun light's shadow node; flat and off modes They're scene object types (prefab:Sun, ...) that save their settings, and prefabs in the editor's asset list with their properties in its panel. One of each per scene; removing one puts back what it changed.
…gic graph nodes The Sun's clock, the Wind and the Clouds' layer are game state now (skyState), the same code on both sides, apart from what draws them: - single player and the editor: the client runs it itself, as before - with a server: the server builds the Sun, Wind and Clouds from the scene (no WebGPU there), advances them every tick and sends a snapshot when a player connects, when it changes and every 10 s (Server.broadcast, the new peerConnected event). Clients carry the clock and the gusts on between snapshots and follow the server once one arrives; they ask for it when they start listening, and go back to running it themselves on a disconnect. The editor always previews its own - the clouds' noise and their density on the CPU (cloudNoise) work on the server too, for "inside a cloud" checks Logic graph nodes, on both sides: Time of Day, Set Time of Day, Set Day Length, Sun, Moon, On Sunrise, On Sunset, On Hour, Wind, Set Wind, Set Cloud Coverage, Cloud Density At. A client following a server logs why it doesn't set anything. Client only: Set Haze, Set Sky Brightness. Events reach every running graph through triggerGraphEvent.
…tion brushes Both prefabs from scratch, as scene object types that save their settings, each working on its own and taking in the other systems only when they're in the scene. Grass: - blades made in code (no gltf models), placed from a painted density map over a square, in 16 m chunks around the camera: full detail near, fewer and wider blades past the detail distance, thinning out at the max distance - stands on any Terrain under it and follows it when it's sculpted or moved; at its own height without one - doesn't grow under Water - bends with the Wind (skyState's velocity, gusts rolling across the field); only a little sway of its own without - lit like the ground (Lambert, normal up): the Sun, the Sky's light, cloud shadows and the Atmosphere's haze reach it - pushed aside by anything in the world with getPushPoints() (PushSource), found every frame Vegetation: - prefabs get a category; Grass is 'vegetation' and registers its kind (Prefab/vegetation) - Vegetation brushes, Paint and Erase: paint the picked kind's density. Painting where there's no layer makes one, over the whole terrain on a terrain. Undo takes back the density, and a layer the stroke made Water: - Gerstner waves, their normal worked out per pixel so detail doesn't depend on the mesh; ripples and rings around push points - a physical surface: reflects the scene's environment (the Sky's) and the sun light - the scene shows through, bent by the waves and tinted by how deep it is there (scene depth), fading to the deep colour; foam where it meets the ground or anything in it - the Wind (with followWind) sets the waves' direction, height and length; followCamera makes it an ocean WaterManager, GrassAffectingEntity and the editor's special cases for them are gone. PushPoints.set empties the slots past the points given; its forEach also hands over each point. Terrain.version tells when heights changed.
The shader placed each wave by wavenumber x speed x elapsed time, and with a Wind the waves' length and direction came from its gusting velocity every frame: each small change moved the crests by an amount that grew with the time, so the sea jumped back and forth. Each wave's phase is now added up on the CPU frame by frame, and the waves follow the Wind's mean speed and direction (not its gusts), easing into a change over a few seconds.
The surface was one evenly divided plane (at most 256 segments a side), so a large water was coarse everywhere, next to the camera too. It's now one mesh of rings around the camera, 'detail' m apart next to it and further apart the further out (51k vertices whatever the size, one draw call, no seams between levels like the old water's sections had), clipped to the water's extent in the shader. Waves too short for the mesh where it's coarse no longer lift it, so the distance doesn't shimmer; their light is still worked out per pixel. Width and length now go up to 40 km and change without rebuilding anything.
…e surface shows from below - underwater.ts: while the camera is below a Water's surface (waves included), a post effect blurs the picture, makes it waver, fades what's further away into the water's colour (red going first) and darkens it with depth and at night; it's in the renderer's chain only while the camera is under - the surface is drawn from below too: the sky through a bright window overhead (Snell's), the water's own colour further out - Water.heightAt(x, z): the surface's height with the waves as they are, for floating things
The underwater effect is now the camera's at the water: each pixel's spot on the lens (25 cm out, like a dome port) is above or below the waves there, the same waves the water is drawn with, so the view splits along a waterline that rolls with them. Along it water clings to the lens: the picture bent and stretched, dark on the line's underside with a bright rim. Below it, the underwater look as before. Coming out (the whole lens, not each wave lapping at it), a sheet of water drains down the lens in soft fingers, bending what's seen through it. Where it has gone the water is left in irregular beads and runs, each bending the picture by the slope of its own surface, darker at its thin edges with a highlight, shrinking and breaking up as it dries over about 12 s. wetLens() wets it on demand, e.g. for a splash.
…ain mirrored in it The outline: - a water is now a polygon of points (props.shape, x and z from its position) instead of a width and length; the surface is cut to it per pixel, and surfaceAt (grass not growing under it, the camera under it) follows it - in the editor each point is a handle: drag it with the move gizmo; in its properties add a point after it (halfway to the next) or remove it; Delete removes it too (not the water; at least three stay). On the water itself: add a point on the longest edge, or reset to a square - IEditor has deselect() and activeItem, which the handles use to keep the move gizmo off ones they replace Reflections: - reflectClouds (on): the clouds, from their sheet along each pixel's reflected ray, while there are Clouds in the scene (Clouds exports cloudReflection and cloudsShown) - reflectTerrain (off): a mirror pass at half resolution that draws only the terrains (put on layer 29) - both take the sky's reflection's place where they cover it, by the Fresnel term, along a calmer normal than the light's so they waver rather than break into speckles
…e in it The terrain's mirror pass drew the scene's background too (a background colour or environment map), which filled the whole mirror: the water took it for terrain everywhere and showed it in place of the sky's reflection and the clouds'. The pass now draws the terrains over nothing, so they show where they are and the rest of the reflection stays.
Terrains take surface effects from other things in the scene (Terrain/terrainSurface: each changes the material's colour and roughness; terrains build their material again when one comes or goes, so without water nothing changes). Each Water adds one: inside its outline and near its waterline, the ground is wet where the waves cover it now and where they reached in the last few seconds (the waves looked at a few moments back), drying the longer ago that was, so a wet band follows each wave back down the shore; damp up to about where the crests reach. Wet ground is darker and glossier. The outline test is now a function the water's and the shore's shaders share (insideOutline), and the water's uniforms carry each wave's speed and the calm level.
It was the waves of the last 2.6 s, about one wave, so the wet band ran back down almost as fast as the water. It now remembers where they reached over the last ten seconds, in nine steps drying off as they go: the ground stays wet over several waves and the band creeps back slowly, with a softer edge.
…ach wave Wetness was the highest any wave had reached lately, so every new wave lifted the band at once. It's now how often the waves have covered a spot over the last 20 s or so, the recent more: soaked where they reach often, damp where only now and then, so a single wave hardly moves it and the band drifts slowly up and down.
Wetness from where the waves were at a dozen past moments shrank back to about the water's edge (the samples missed most crests), so the dark band looked like more water. The shore is now soaked up to a wet line: as high as the waves reach (their heights added up), a little higher or lower along the shore, fading just above. It rises at once when the waves grow and dries down slowly when they calm (about a minute), so the band stays dark while the waves come and go over it.
The wetness only went down to half a metre under the calm level, so the ground deeper down came out lighter, with a hard line between. Ground under the water is wet all the way down.
…triangles at the water's edge - the Sun's shadow had no depth bias, so the ground shadowed itself in stripes (acne), and its square followed the camera in steps of world axes, not of the map's texels, so the stripes crawled as the camera moved: a flicker that showed most on the wet shore and through shallow water. It now has a bias and a normal offset of about a texel, and moves in whole texels along the light's own axes (the light's bias is put back with the rest when the Sun goes) - the water's ring mesh was clamped to the outline's bounds, folding the triangles it squashed over each other right at the water's edge; it's clamped a couple of cells further out, where the surface is cut away - under water the fog is mostly the deep colour and dimmer, and what's seen is dimmed more
The gusts rolled across the field at about three times the wind's speed over 16 m patches, so a blade was hit twice a second, and the grass followed every change of the wind at once. The gusts now roll at about 0.7 of its speed over 25 m patches, and the grass eases into a change over about 1.5 s. Their position is added up frame by frame: as direction x time, the whole pattern jumped whenever the wind turned a little.
…s in it, and a debug heatmap The wind was one velocity for the whole scene, and the grass's gust patches a fixed value-noise pattern sliding over it. Now: - the wind field (Prefab/Sky/windField.ts): three octaves of gradient noise over the ground and time scale the Wind's velocity (by its gustiness) and turn it (by its veer), so some places gust harder and others are sheltered; the patches drift downwind with the air and change shape as they go - skyState.windAt(x, z): the wind at a place, on the client and the server, from the synced state - the grass reads the same field, drawn once a frame into a 128² texture around the camera (windFieldTexture): one lookup a blade instead of layers of noise; it eases into a Wind coming or going - the noise hashes its lattice with integer maths, so the GPU and the CPU give the same field (within half-float precision, checked against a read-back); classic Perlin's mod-289 hashing rounds differently on some GPUs - Wind's debug checkbox: the field as a heatmap (blue sheltered, green as the Wind, red gusting) with streaks along its direction, over the terrain or, without one, on a plane at the Wind's height
Below the horizon the air's model shows the planet's ground: one flat colour from the scene's edge out to a hard horizon line. On screen the sky at the horizon now carries on down, a little darker the lower, so the scene's edge fades into the haze. The environment map the Sky lights the scene with keeps the ground, so light from below stays dimmer than from above.
With an HDR environment map (and the Sky not lighting the scene) the clouds' sky light comes from the map: its average light from above for their tops and around the horizon for their undersides (findSky, beside findSun, the sun's own spot left out: the sun light is the sun's), times the map's intensity. So they take its colours, a sunset's or an overcast day's. Without one, or with the Sky lighting the scene, their light is the Sky and Sun's as before. Their sunlight was already the HDRI's where the scene settings aim the sun light at its sun.
…ting bends its models down the wind field, more towards their tops, with a flutter of their own
…el, dragged in from the assets, each with how it grows, saved as vegetation/<name>.vegetation.json; painting one grows its models in a Foliage layer, chunked and instanced around the camera, on the terrain, out of the water and bending in the wind
…color as the PNG, though its glTF leaves alphaMode out (grass_bermuda_01 drew whole black cards)
…clumps grows as plants of their own, each picked at random; the editor asks when a model of several pieces is added
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.