WIP: feat(vk): ray tracing: lights from glowing materials, guide buffers and alpha in the rays without micromaps (on #727) #1151
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1151
Loading…
Reference in a new issue
No description provided.
Delete branch "Drommedhar/Longshot:feat/path-tracing"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: feat · Risk: medium · Tested on: Windows 11, Radeon RX 9070 XT · Needs: an NVIDIA RTX card (the path with micromaps), Intel Arc, Linux
On top of #727. This branch is rebased onto #727's as it moves (now
19f973b0), so until #727 merges the diff here shows its commits too. Ours are the last 70, nearly all in files of our own; in #727's files we add marked hook lines and#ifdefblocks. #727 has since taken its own versions of three things that started here (cut-outs tested in the ray loop, the mesh-shader cards' bits, the bottom levels' budget from the video memory): those are its commits now, and ours build on them. What we found on the way that concerns #727 itself is in #727 (comment).Why
With #727 the sun, the sky and the game's few lamps are ray traced. But in a town at night nearly everything that glows, every lantern and every lit window, is a glowing material with no lamp behind it: it lights nothing and casts no shadow, and the warm light round it is baked ambient. And on a card without opacity micromaps (every AMD card today) leaves and fences were solid in the rays, so a tree's shadow was a blob, and Kakariko lay under a sheet of shadow at night.
This is also the groundwork for a path-traced mode: lights that exist as lights, the game's own colour at a ray's hit, and the guide buffers a denoiser or Ray Reconstruction needs.
What changed
Lanterns, lantern glass and windows become real lights with ray-traced shadows, highlights and normal-map detail; rays respect alpha where the device has no micromaps; a ray's hit knows the game's texture colour. All of it is off unless its row or switch is on.
vk_rt_emit.cpp,vk_rt_emitters.cpp,rt_emitters_policy.h,rt_emit_islands.h): a program's emission read from its SPIR-V; sphere and area lights from lantern bulbs, lantern glass and window panes, a batched draw split into its islands; kept in a world light grid (rt_light_grid.h), so which lights reach a surface depends on the surface's place, never the camera's.RX_VK_RTbit 32, row "Ray-traced lantern lights": Off / Low / Medium / High / Ultra;vk_rt_di.cpp,shaders/rt_di_def.comp): a pass after the lit draws with the diffuse term and a GGX highlight. It traces a shadow ray only for the lights that matter at a pixel (a light under 5 or 10 % of the pixel's unshadowed lantern light is not traced and takes the traced ones' mean visibility), skips pixels where lantern light is under half a percent of their own colour (by day nearly all), and works at half size in the two lower steps.rt_guide_spirv.h,vk_rt_guides.cpp): the lit programs store the shading normal (normal map included), roughness, albedo and F0, by a SPIR-V patch like #727's own; every guide in 77.8 % of the cache's lit stages.RX_VK_RTbit 16;vk_rt_lights.cpp,vk_rt_lamps.cpp,rt_lamp_spirv.h): the lamp list's layout is from #815.RX_VK_RT_ALPHA=1, whose baked opacity bits in the candidate loop are #727's now; ours on top invk_rt_alphax.cpp,vk_rt_holes.cpp): the game's texture sampled at the hit for a covered cell, terrain patches open at the game's holes, and thekBlockerclass (the game's low-detail shadow models) left out of a sun ray whose receiver is within 50 m of the camera, by the ray's instance mask (#727's falling leaves keep casting).RX_VK_RT_HIT=1;vk_rt_hitrec.cpp,vk_rt_recipe.cpp,shaders/rt_recipe_eval.glsl): a lit program's base colour as a recipe folded per draw, with records for the ground and the mesh-shader cards; so far used by debug pictures only.rt_views.h,rt_look.h,vk_rt_show.cpp,vk_menu.cpp): F8 flips between the game's own picture and the traced one, F7 shows one part or one guide buffer alone, F4 to F6 step through and change nine look settings (a collapsible group in the menu, saved with the options).vk_rt_scene_big.cpp,vk_rt_scene_who.cpp, the emission census): the biggest instances, a leave list, and sun probes that name what a pixel's sun ray meets.Everything is described in
docs/ray-tracing.md.Measurements
Verdict: pending. The numbers below are single headless runs without a frame rate cap (1707x960 internal, FSR 4.1.2, AO Medium, reflections at the Low roughness step), made while building with the desktop in use: the same scene ran up to 1.5 times faster or slower between hours, so only numbers within one line compare. Interleaved medians follow before this leaves WIP.
Baseline: #727 at
f70c348d, not main: this branch sits on it.Hardware: Windows 11, Radeon RX 9070 XT 16 GB (driver 26.11.1), FSR 4.1.2 Quality to 1440p.
Scene: the Market at a shop door and at a pine by night, Kakariko by night, Kokiri Forest; 1707x960 scaled to 2560x1440, no frame generation, no frame rate cap.
Method: one headless run each through the control bridge, 30 to 120 s, the player standing still; brightness as the mean of a fixed crop of the "Sun shadows" view's picture, frame rate from the bridge's status, pass times from
RX_VK_GPU_PROFILE=1, the hits' share from the log'srt hit: primary raysline. Not medians.How to reproduce: a save at each spot,
RX_VK_RT=63 RX_VK_RT_ALPHA=1, and the part's own live switch for the before column (exact=0 blockernear=0andholes=0inRX_VK_RT_ALPHA_CTL,di=0inRX_VK_RT_LAMPS_CTL).f86523bff86523bfFlags and settings
New menu rows and switches; every one is documented in
docs/ray-tracing.md, the rows also in the README's option table.RX_VK_RTbit 16, row "Ray-traced lamp shadows"RX_VK_RTbit 32, row "Ray-traced lantern lights" (Off / Low / Medium / High / Ultra;RX_VK_RT_DI_SIZE,RX_VK_RT_DI_CUT,RX_VK_RT_DI_FLOORgo over the step)RX_VK_RT_GUIDESRX_VK_RT_ALPHA_EXACT(with #727'sRX_VK_RT_ALPHA=1)RX_VK_RT_ALPHARX_VK_RT_BLOCKER_NEARkBlockerRX_VK_RT_ALPHA)RX_VK_RT_HITTesting
Tested: Windows 11, Radeon RX 9070 XT (no
VK_EXT_opacity_micromap): headless runs through the control bridge from saves in Kokiri Forest, the Market, Kakariko and Hyrule Field, by day and night, with every part on and each on its own, no device loss or Vulkan error in the logs (the validation layers were not on); and several hours of play by the branch's owner in the same areas. The transform feedback capture, on by default again at #727's19f973b0, ran in two real sessions in the Market by day on this card without a device loss (it lost the device there before #727's9a818a6a). Game-free checks:python -I -B tests/run_all.py --jobs 8 rt_ emit program_cache menu gain look readme audio linux_pressure: 86 pass, 1 fails (test_menu_save_atomic, which fails on #727 alone). The full suite fails 17 or 18 checks on this PC that fail the same on #727 alone (among themtest_env_on,test_release,test_walk_key,test_vk_occlusion_queries,test_menu_save_atomic,test_cpp_preflight,test_linux_preflight,test_options_budget_once).Not tested: any device with opacity micromaps (NVIDIA): there our alpha path is off, but the lights, the guide buffers, the deferred pass and the hooks in #727's files run and never have on such a card. Intel Arc. Linux (not even built). Frame generation with the rows on. Areas other than the four above for the lights.
Must be tested:
RX_VK_RT=63in the Market by night, expecting lanterns and windows to light their surroundings with shadows and no error in the log (by hand: the Market's lanterns by night and the log; not asked yet).Risks
What could break: with the guide buffers on, every lit program's module changes: a driver that rejects a patched module would leave those draws out (accepted on the RX 9070 XT). The hooks in #727's scene and mask code run on every device once ray tracing is on.
Turning it off: every part has its row or switch and is off by default;
RX_VK_RT_GUIDES=0returns the lit programs to #727's own.Compatibility:
longshot_options.inigains the look settings' keys and two rows; aray-traced_lantern_lights=1saved by an earlier state of this branch now reads Low. The first start with the guide buffers on makes the lit pipelines again (about a minute with parts of the picture missing).MKWVK_API_VERSIONis unchanged (vk_api.huntouched).Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks. Not ticked yet: Measurements verdict is still pending, so the lantern lights' frame cost is not stated.
main. (On #727's branch, which it follows.)python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (The failures named above fail on #727 alone; not yet compared with main.)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md). (With the measurements.)tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
The game draws its 12288 x 12288 static shadow map (D16) once, while an area loads: some 2000 to 3600 depth-only draws in a frame or two, with no scene yet, so the cascades' rule ("no scene this frame: a cascade of nothing we trace") left them all out, and what the camera never shows and no cascade reaches was in no top level (the mound's shade by Link's house, the cliff's across Kakariko's terraces: mask's lost shadow). They are now noted as the cascades' draws are (models by their object block, the height-field patches) and kept in a set of the area's own, placed every frame as kBlocker / kCaster like a cascade's draw, a caster once by its geometry and place. The set is let go when the map is drawn again after a pause (another area). Their mesh draws (24 to 56 a batch) are not captured. RX_VK_RT_STATIC_MAP=0: not taken. The status line says the batch: its draws, the casters kept. Kakariko: 1966 draws, 1830 casters kept (109 terrain patches), none left out but 24 mesh draws. Kokiri: 3629 draws, 3560 kept. Kokiri spawn: agreement with the game's depth unchanged (89.4 %), 4561 instances a frame (1197 without), 116 MB of bottom levels (43). Co-Authored-By: Claude Opus 5.5 <[email protected]>79d6d5350af86523bf67Rebased onto #727 at
19f973b0and pushed:f86523bf, 70 commits of ours on top. Still WIP.What changed
What the new measurements show
In a crowded place the cost is mostly on the CPU and mostly not ours: the Market's square by day runs 69 fps with ray tracing off, 30 to 35 with #727 alone and 28 to 32 with this branch. The render thread rebuilds the top level every frame at about 1.3 microseconds an instance (1.7 with our hooks), and a walk through the square fills the scene to 11,000 instances. Next here: a scene that keeps what has not changed, then reflections traced in one pass instead of in every lit program (facing water they are the largest GPU cost above the Low roughness step).
Checks:
rt_ emit program_cache menu gain look readme audio linux_pressure: 86 pass, 1 fails (test_menu_save_atomic, which fails on #727 alone). The transform feedback capture, on by default again in #727, ran in two real sessions in the Market on the RX 9070 XT without a device loss.Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.