Everything here is spatial or per-frame. No history buffers, no reprojection, no temporal accumulation.
All options are RenderSettings fields, so they work from settings files (renderScale 0.75), the params bus, setRenderSetting, the Look panel (Shadows and Screen space sections) and palette commands.
Scene depth is reversed Z (near 1, far 0, GREATER_EQUAL, float D32) so 50-100 km views stay usable (docs/LargeWorld.md). Shaders test sky with isSkyDepth; the camera Hi-Z keeps the minimum, the shadow Hi-Z (standard Z) the maximum. Cascade and local shadow maps stay standard Z (clear 1, LESS_EQUAL in the surface shadow PSO); using the scene's GREATER_EQUAL there leaves every shadow map empty.
- Cascades are texel-snapped in world space (stable under camera motion and floating-origin rebases) with per-texel Vogel rotation, so the noise sticks to the shadow map rather than the screen.
- Normal-offset bias scales with cascade texel size and a clamped slope term (no huge offsets at grazing angles).
- PCSS blocker search plus a variable filter radius (
pcss,shadowSoftness). Far cascades (2 and up) use half the PCF taps. - Portal views share the main camera's cascades when those cover the view (
Lighting::useCascades;cellParams.z > 0makessunShadowpick the finest cascade containing the point instead of using the view-depth splits, no cross-fade). See docs/Portals.md, "Shared sun cascades". shadowCascadeBlend(0..0.5): fraction of each cascade range that smoothly cross-fades into the next cascade (smoothstep). 0 disables the blend.- Contact shadows (
contactShadows,shadowContactLengthin metres): 12-step screen-space march toward the sun in the current depth buffer, thickness-limited, fading toward the ray end. Cheap blocker-search style detail for small casters the cascade cannot resolve.
- Half-resolution bitmask GTAO (defaults: 3 slices, 8 steps per side). Occluders fade out smoothly between
aoRadiusand twice that (the occluded arc shrinks toward the open end of the slice) instead of a hard cut at 2R, which used to draw a halo band around objects. - GI and colour bleed are a separate pass after lighting that gathers this frame's lit colour (see ColorBleeding.md).
ssgiIntensitydefault is 1 (physically one bounce); it was 2.5 when the bounce was a fake sunlit albedo. aoDenoise(0..3): separable bilateral blur radius 0, 2, 4, 6 taps per side. Weights combine a Gaussian, a depth tolerance and a local depth-slope plane fit, so slanted floors blur without halos and edges stay sharp. The same weights filter the bent normal.bentNormals: the GTAO pass writes a cosine-weighted average of unoccluded sector directions (RGBA8, half resolution). The lighting pass upsamples it with the depth-aware AO upsample, then- diffuse IBL samples the SH irradiance along the bent normal instead of the surface normal,
- specular occlusion intersects the visible cone (from AO) with the specular cone (from roughness) around the bent normal (Jimenez-style) and blends it with the Lagarde term.
LightComponenthassourceRadiusandsourceLength(metres). Radius 0 and length 0 keep the old punctual behaviour. Radius > 0 is a sphere light; length > 0 makes a tube along the entity forward axis. Point lights only (spot lights keep their cone parameters). Both fields are serialised (older files load with zeros) and editable in the Inspector.- Shading uses the representative-point method: the closest point on the sphere or segment to the reflection ray gives the light vector, the GGX roughness is widened by
radius / (2 d)and the lobe is energy-normalised by(alpha / alpha')^2. Distance attenuation addsradius^2to d^2 so near-field intensity stays finite. areaLightstoggles it globally (palette: render.areaLights).- Packing: for non-spot lights
GpuLight.params.x= radius,params.y= half length,directionCos.xyz= tube axis.
- Up to 32768 point/spot/area/tube lights per frame (
kMaxLights, collector capkMaxSceneLightsinEngine.cpp), uploaded to one GPU light buffer. light_cull.compruns per view (main and every portal view, with that view's clipped frustum planes): a per-light pass frustum-culls with a tight cone bounding sphere for spots and compacts view-space spheres, then one 64-thread group per froxel cluster (32 x 18 screen tiles x 32 exponential depth slices) tests them against the cluster AABB and appends up to 512 indices to a variable-length list (4M index capacity).ClusterBufferlayout is documented inlights.glsl(clusterRange).- Debug view 10 shows lights per cluster (heatmap, 32 = red).
- Portal cells: lights are filtered per view by cell (
cellParams.x), and lights of a neighbouring cell reach a cell through its portals as images with an aperture (lightAperture()inlights.glsl, apertures afterkMaxLightsin the light buffer, VSM faces clipped at the portal plane). See docs/Portals.md, "Light through portals". - Cell grade:
SceneUniforms::cellTintmultiplies ambient (SH irradiance, prefiltered environment, reflection fallbacks) and the sun illuminance of a portal cell's views (docs/Portals.md, "Cell lighting grade").
virtualShadows (default on, palette render.virtualShadows) shadows every local light; off falls back to the ranked localShadowCount cube/spot maps. Code: LightingVirtualShadows.cpp, shaders lighting/vsm_*.comp|vert, include/vsm.glsl.
- Faces: a spot light owns one perspective face, a point light six cube faces (32768 face slots). Each face has virtual mips of 64..1024 texels (
vsmMaxMip0..4) cut into 64x64 pages (341 page-table entries per face). - Stable slots: the CPU matches each light to last frame's light with identical parameters (cache stays valid) or, for a moving light, to the nearest previous light of the same colour/range/type within 4 m (slot kept, face marked dirty). Lights in the main frustum are assigned first, then the rest in distance order (portal views see shadows of nearby off-screen lights).
- Per view, after its depth pass (same frame, no history):
vsm_requestwalks the cluster lights of one pixel per 2x2 block (footprint widened by the block) and marks the page at the mip where one shadow texel is no larger than one screen pixel (vsmResolutionScalescales that), widened by the filter footprint, plus mip 0 of the face as a fallback. Pages are stamped with the frame; the first stamp appends them to a request list. - Page management (
vsm_pages.comp): physical pages not requested in this or the previous frame return to a free stack; requested pages without valid content are queued for rendering. Overflow is deterministic: every face gets one of 8 priority tiers on the CPU (rank by projected sizerange / distance, lights outside the main frustum last, ties by light index);HISTcounts the requests that still need a page per (mip, tier),PLANgrants whole groups, coarse mips first and by tier within a mip, while free pages last, andALLOCATEpops pages only for granted groups. Ungranted pages count as overflow and lookups fall back to coarser mips (then unshadowed), so the finest pages of the least important faces go missing first, independent of thread order. vsmAutoScale(default on) multipliesvsmResolutionScaleby a factor from the visible light count versus the pool (pool pages / 32lights at 1, +0.5 per doubling, clamped to 4);VirtualShadowStats::resolutionScalereports the effective value.- Cache invalidation is scheduled, not image-based: the first view of a frame compares every object's bounds, transform, renderable word (mesh, material, shader, flags) and deform stamp with a copy from the previous frame; the swept sphere of every changed object dirties overlapping faces, as does a moved or new light. The deform stamp is a per-entity counter written by
skin_bounds.compwhenever a dynamic mesh's pose, morphs or deform rewrote its vertices, so a skinned or deformed mesh invalidates pages even when its refit bounds stay the same (see Skinning.md).vsmCache 0re-renders every requested page every frame. - Rendering: one group per queued page culls object spheres against the page sub-frustum, instances are bucketed per mesh LOD (prefix sum + scatter) and drawn with one indirect multi-draw into the D32 atlas (
vsmPoolSize2048/4096/8192 = 1024/4096/16384 pages). The vertex shader maps the face projection onto the page's atlas tile in clip space and cuts the rest with four clip distances; pages are cleared with one quad each. - Lookup: the page table at the pixel's mip (falling back to the finest coarser resident page), 4 rotated bilinear-compare taps (neighbouring pages looked up per tap), normal-offset and slope bias scaled with the texel size,
localShadowSoftnesswidens the kernel. - Stats:
Lighting::virtualShadowStats();LIT_VSM_STATS=1logs faces, requests, rendered/resident pages, overflow, caster instances and moved objects every 30 frames. - Limits: casters have no custom vertex code or alpha test in virtual shadows; dynamic (skinned, morphed, deformed) meshes are drawn from their per-instance vertex range in the shared vertex buffer, which the skinning pass rewrites before any shadow pass, so they cast their current pose. Cluster LOD meshes are drawn from their triangle LOD chain (the renderer keeps an unpatched mesh info buffer for this; cluster LOD itself zeroes those slots for the main views). Sun cascades and the ranked local shadow maps do draw clusters, with the cut chosen from shadow-texel error (
clusterShadowTexelLod,clusterShadowErrorTexels, ClusterLod.md). Point-sprite LODs are drawn as the coarsest mesh LOD, transparent surfaces use whatever pages opaque pixels requested (mip 0 at least), the sun keeps its cascades (not paged, redrawn every frame so they follow deformation).
LitShot --testscene light_stress --lights 4096 builds a 160 m field of 900 pillars, 256 bobbing spheres (moving casters) and N moving lights (3/4 point, 1/4 spot) at night; animation is driven by the frame index.
GTX 1650, 1266x1022, GPU shared with other processes (numbers are noisy), 4096 lights all moving, 256 moving casters:
virtualShadows 1: 19456 faces, 65k page requests, pool (16384 pages) saturated, 16.3k pages and ~85k caster instances rendered per frame; Shadows 19 ms, Lighting 25 ms.vsmResolutionScale 2: 22.5k requests, 6.2k overflow; Shadows 19 ms, Lighting 17 ms.virtualShadows 0(ranked, 4 lights): Shadows 0.75 ms, Lighting 14 ms. Static lights and casters re-render nothing (showcase: 1025 resident pages, 0 rendered per frame once cached). UsevsmResolutionScale2..4 for thousands of visible shadowed lights.
- The in-scattered term of height fog and aerial perspective is scaled by the receiver's sky openness (
mix(skyVisibility, 1, 0.15)), so rooms under a roof are not veiled by the full outdoor sky colour. Extinction is unchanged.
- A ray that only passes behind geometry is a miss (probe / environment fallback). It used to return the occluder's colour at 45 %, which drew dim ghosts and streaks of foreground objects into reflections.
cloudAerialStrength(0..2) scales the distance haze that blends cloud layers into the horizon sky colour (aerial perspective for clouds). Terrain uses the existing aerial-perspective froxel LUT (fog,aerialDistanceScale).
renderScale(0.5..1.0, quantised to 0.05) renders the scene (G-buffer, depth, Hi-Z, lighting, post) atscale * windowand presents at window size.- Compute passes (
post/easu.comp,post/rcas.comp, FSR1-style, own implementation): edge-adaptive 4x4 Lanczos-like resample with local min/max clamp (no ringing), then contrast-adaptive sharpening driven byupscaleSharpness(0 disables). FXAA then runs at output resolution on the sharpened image. WithrenderScale = 1the passes are skipped entirely. - Editor overlay lines and the profiling HUD draw at window resolution; while scaled they use a separate window-sized depth buffer, so debug lines are not depth-tested against the scene.
qualityGovernor(default off),targetFrameMs(4..100),governorMinScale(0.5..1).- Input: total GPU ms when GPU timings are on (full profiling), otherwise the CPU frame time. Exponential smoothing (0.12).
- Ladder (levels 0..8): each level lowers
renderScaleby 0.05 down togovernorMinScale; reflection quality drops from level 3; shadow resolution halves from level 4 (never below 512). Values are relative to the user baseline; editing any governed setting while active re-baselines. Disabling the governor restores the baseline. - Anti-oscillation: step down only after 1.5 s continuously above 106 % of the target; step up only after 6 s continuously below 72 % (dead band); 2.5 s cooldown after every change; if a step up is followed by a step down within 12 s the up-hold doubles (up to 4x). One level per decision.
- Code:
src/Engine/Render/QualityGovernor.cppm(pure CPU, deterministic), driven fromRenderer::updateQualityScale(RendererQuality.cpp). Tests:tests/QualityTests.cpp.
render.contactShadows, render.bentNormals, render.areaLights, render.governor, render.scale (cycles 1.0, 0.9, ... 0.5), render.virtualShadows, render.vsmCache, render.vsmPool.
Shaders validate with glslangValidator -V --auto-map-bindings --target-env vulkan1.1 -Iresources/shaders/include (the cull/scatter/compaction shaders use subgroup ops, which need SPIR-V 1.3; the runtime compiles for Vulkan 1.1+). GPU output is inspected with LitShot --testscene <name> screenshots.