Repository navigation
Conversation
With Enhanced dynamic lights on, candles, fires and spells used to light the ground through the terrain light grid only, interpolated between vertices a terrain cell apart, so their light showed as square patches. The ground now gets the same smooth pools the models get. - Before the terrain is drawn, the scene pins the brightening lights the frame's point-light selection applies (WorldDynamicLights) and marks the frame's light list. - The terrain's faces, layers, grass and lit terrain decals take a copy of the terrain light without those lights and draw with the new world-lit pipeline set (world_lit.vert/.frag), which adds them back per pixel with the grid's own linear falloff. Lights outside the selection stay in the grid. - The uploaded point lights keep the pinned ones first (DynamicLightsUniform::worldLightCount) and fill the slots left from the lights added after the pin. - The world-lit set is one row of the world pipeline table, in the Enhanced lighting family. Classic and the dynamic-lights switch off draw as before. Fight bench (Noria, 24 monsters, AA 4, alternating runs): 3.65 ms against 3.58 ms on main, within the run-to-run spread.
Character shadows were opaque black, and overlapping shadow triangles would double-darken as soon as they were not. In a frame with world-lit ground (Enhanced dynamic lights) they now darken the ground through a coverage mask: - Body shadows (GPU, CPU fallback and cloth) are recorded inside a ScopedGroundShadow. Before the scene pass they are replayed into an R8 mask at the frame's size with MIN blending, so each pixel darkens once however many triangles or characters overlap, and nearby shadows merge. - The scene passes leave the tagged draws out; world_lit.frag samples the mask and dims only the ground's own light by dynamic.shadowOpacity, so candles, fires and spells still light shadowed ground. - dynamic.shadowOpacity (Look.json, per map, default 60 %) has a "Shadow darkness" slider under Dynamic lights and a `$dynlights shadow <o>` command. - Classic, Dynamic lights off, and passes without the mask draw the shadows as before.
Body shadows always fell towards world -x, while the sun that shades the terrain's slopes shines from +x/-y, so shadows and terrain shading never agreed. With Enhanced dynamic lights the shadow's shear now acts along a per-map direction: - dynamic.shadowAngle (Look.json, per map) is where shadows fall, in degrees counter-clockwise from world +x. The shipped default is 135, directly away from the terrain's sun; the built-in 180 is the Classic direction. - The CPU, cloth and GPU-skinned paths take one mu::ShadowProjection with the shear's axis angle; at angle 0 the shear is Classic's exactly. - A "Shadow direction" slider under Dynamic lights' More settings (new degrees unit) and `$dynlights shadowangle <a>`. - Classic and Dynamic lights off keep the Classic direction.
With post-processing the scene and bloom-source passes drew into textures of the swapchain's 8-bit format, so stacked additive light (overlapping spells, glows) clipped to flat white. They now draw into RGBA16F when the device can render it at the frame's sample count: - Every pipeline those passes replay has a twin built for RGBA16F (s_hdrScenePipelines, built like the single-sample twins, alpha-to-coverage variants paired by slot); s_hdrScenePass makes the replay use them. With anti-aliasing the passes resolve from an RGBA16F multisampled target. - The scene texture's format makes the scene HDR (EnsureTargets); the UI, offscreen captures and readback keep the swapchain format. - post_composite.frag rolls scene channels above 0.9 off towards 1 (the highlight-knee curve), before the bloom and grading, and adds a one-step ordered dither for the 8-bit target. An 8-bit scene composites as before. - Light below 0.9 is unchanged; inverse-colour blending over light above 1 can go negative and composites as black.
…anced ground Candles, fires and spells lit the ground and characters but cast no shadow. With Enhanced dynamic lights a character now casts one more shadow per strong nearby point light, away from it: - SelectLightShadowCasters picks up to dynamic.shadowLights (Look.json, per map, 0-4; shipped 2) of the ground's pinned lights reaching the character, strongest first. Each shadow's strength is the light's share of the point light at the character; a light at the character (its own glow) casts none. - The ground shadow mask is now RG8: sun shadows write red and dim the ground's own light as before, point-light shadows (GroundShadowSource:: PointLight) write green and dim the point lights in world_lit.frag. - Point-light shadows never draw as plain shadows: without the mask they are left out. The mask pipelines are built only when the device can render and sample RG8. - A "Light shadows" slider under Dynamic lights and `$dynlights shadowlights <n>`.
Corners, wall bases and the ground under objects had no contact darkening. With post-processing and one sample per pixel the scene now gets screen-space ambient occlusion from its depth: - SdlGpuAmbientOcclusion renders it at half size: post_ao.frag samples a 12-point hemisphere around the surface (normals and view positions from the depth and the scene's inverse projection, captured with the scene lighting), rotated in a 4x4 pattern; post_ao_blur.frag averages 4x4 texels, leaving out other surfaces, which cancels the pattern without halos. The sky gets none. - post_composite.frag darkens the scene by it before the tone map, and fades it out where the bloom source holds additive light (effects, glows). - The single-sample depth is now sampleable. Anti-aliased frames get no occlusion yet (their depth is multisampled). - ao.strength (0-2, shipped 0.8) and ao.radius (world units, 10-300, 60) in Look.json, the "Contact shadows" sliders, `$ao <v>` and `$ao radius <r>`.
…nced look Skill and spell lights washed out the ground around a fight, and metal armour read too glossy. The shipped Enhanced look now uses the values settled on in play: - dynamic.effectGain 2.5 -> 0.5: effect lights half as bright as their calls ask for. - dynamic.effectRange 3 -> 2: effect lights reach twice their calls' range, less far than before. - lighting.specular.scale 1 -> 0.8.
… order SDL pushes uniform slot N into MSL buffer N, but spirv-cross numbered the MSL buffers in the order the compiled code first uses them. Three fragment shaders read the wrong data on Metal: world_lit and skinned_lit took fog as scene lighting (and so on), basic_textured_fog swapped fog and scene light. - MSL is generated with --msl-decoration-binding, which keeps the declared bindings, for every shader without storage buffers (in mu_add_shader and in the reflection check's own MSL). Storage buffers share the MSL buffer indices and follow the uniform buffers, so the two skinned vertex shaders keep spirv-cross's numbering, which the check already pins. - The reflection check verifies each MSL uniform buffer's index against its binding, as it does for textures and samplers. It reported all three shaders before this change.
Enhanced sun shadows: the scene's solid draws are drawn once more from the sun into a depth map, and the world-lit ground and lit models sample it with a 3x3 comparison filter. Shadows now fall onto slopes, walls and other characters instead of being flattened copies on a plane. On models the shadow takes away only the direct sunlight, not the ambient light. Each draw keeps its recorded matrix: the sun pass multiplies in sun view-projection times the inverse scene view-projection, so nothing is recorded twice. The map covers the ground the camera sees, snapped to whole texels so shadows stay still while walking. The sun stands opposite dynamic.shadowAngle, as high as the flat character shadows were long. BMD, skinned and glTF draws each replay with their own vertex layout. Characters' see-through parts (wings, capes, auras) cast a partial shadow: each texel covers the map with the chance of its alpha, or for glowing parts its brightness, and the filter turns the dither into a lighter shadow. Skill effects cast none. The characters are drawn inside a ScopedCharacterDraws, which marks their draws apart from the world's objects. The lit shaders' sampler slots: 1 per draw (the normal map, or the ground's shadow mask), 2 the sun shadow map, bound once per pass. With sun shadows on, characters cast no flat sun shadow; point-light shadows stay flat. Works with anti-aliasing. Look.json: sun.shadow (1), sun.softness (1), sun.resolution (2048). Console: $sun.
…with the sun - One sun per frame (FrameSun): from dynamic.shadowAngle, with the sun the maps' baked light implies (shadow angle 135). The sun shadows, the terrain's slope shading and the models' light all take it. - The baked vectors follow the sun's turn and rise (FollowSun), each keeping its own offset, so at the baked angle every map looks as before. Classic keeps the fixed vectors. - The terrain light is built again when the sun moves (profiled as TerrainBake); CreateTerrainLight_Part now uses Battle Castle's vector too. - The models' light comes from ModelLightVector(), outside the BMD code, so models of any format can be lit alike. Battle Castle's turned light no longer stays on models after leaving it.
- New look value dynamic.flatSunShadow (0 to 1, Enhanced only): how dark the flat shadow under characters is while sun shadows are off. Classic keeps it as before. - Dungeon, Lost Tower, Kanturu Relics and Refinery Tower set sun.shadow and dynamic.flatSunShadow to 0 in Look.json: no sun there, so only torches and spells cast character shadows. Every other map keeps its look.
…s share their lighting code - UpdateFrameSun() at the start of each frame's update (InitTerrainLight) fills the sun that FrameSun() and FollowFrameSun() return; their static caches go, and every part of a frame sees the same sun. - scene_lighting.hlsli and dynamic_lighting.hlsli hold the uniforms, the Enhanced fog curve, the sun shadow lookup and the point lights' fade that world_lit, skinned_lit and basic_textured_fog each carried a copy of; shader blobs rebuild when an include changes. - SdlGpuSunShadowMap owns the sun shadow map's textures and sampler. - The terrain light arrays say what each holds.
…ows the sun - clouds.hlsli: drifting procedural clouds whose shadows fall slanted by the sun; they dim the sun's light on the ground (world_lit) and the characters (skinned_lit) alike. - sky.fill: shade from shadows and clouds turns towards the sky's blue while sunlit places keep the sun's colour; it replaces the light mood's shadeCool while sun shadows are on. - lighting.rim.sunFollow: the characters' edge light comes from the sun, brighter and sun-coloured on its side, gone in its shadow. - All three only under a sun that casts shadows (none indoors). - clouds.strength/scale/speed/cover, sky.fill, lighting.rim.sunFollow: Look values (off by default) with their controls, $clouds / $sky / $rim sun commands, strings, docs and tests.
Ambient occlusion reads the scene's depth, which a multisampled frame cannot sample: with anti-aliasing on, the scene's solid draws are drawn once more, depth only, into the single-sample pass depth (profiled as SceneDepth). BMD, skinned and glTF draws each replay with their own vertex layout.
…de and a sun rim clouds.strength 0.35, sky.fill 0.5, lighting.rim.sunFollow 1 in the shipped Enhanced look.
…un; maps name their environment - World models follow the frame's sun: the game lights every model with the highlight vector, which skipped it; UI models keep their light. - Enhanced flat shadows fall away from the frame's sun, as long as its slant. - On the ground a cloud takes away direct sunlight only: the terrain bake uploads each cell's direct part (SetTerrainSunLight), which world_lit subtracts under clouds, leaving the painted ambient light and point lights. - A change of the light mood's scales (look values) rebuilds the static light; the sky fill takes over the mood's shadeCool only where the renderer can draw sun shadows. - Shadow dims only the light a model face receives, so shaded far sides no longer come out brighter than lit ones. - Sun shadows filter with a rotated 12-sample Poisson disc and Gaussian weights instead of a 3x3 box, and push further off faces turned from the sun. - AO targets are freed whenever its pass does not run; bloom targets exist only while bloom is on. - Every map names an environment in Look.json: outdoor, outdoorDense, sky, underwater, enclosed or fixed (docs/enhanced-look-map-environments.md); "environments" holds their values, applied between the default and the map's own. Enclosed maps get no sun shadows. - rendering-parity.md: Windows defaults to Vulkan.
The character scope is a recorded legacy call, so characters drawn later keep it. A shadow takes its fall, its strength and its point-light casts when described, so the draw reads only what it carries. The ground light is built in the update, after the lights are pinned, and whether sun shadows are active is taken once per frame. The parity log records the ground shadow, world-lit and character scopes.
nitoygo
force-pushed
the
feat/terrain-lighting
branch
4 times, most recently
from
November 9, 2026 19:39
5ac25ba to
3191662
Compare
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.