RT: opacity micromaps (VK_EXT_opacity_micromap) for hardware alpha-tested shadows, shader alpha-test fallback #194

Closed
opened 2026-09-30 03:15:29 +00:00 by sky_line · 3 comments
Owner

Hardware alpha testing for ray-traced shadows via opacity micromaps (VK_EXT_opacity_micromap), with the current shader alpha test kept as the fallback so every RT card still works.

Why

Ray-traced sun shadows (#185) with the per-leaf alpha test cost ~2.4 ms vs cascades on an RTX 5090 (same view: 14.8 -> 17.2 ms); ~1.3 ms of that is the candidate alpha test -- every alpha-mask triangle a ray crosses returns to the shader for a texture fetch (clean_rt_common.glsl traceShadowRay / rtCandidateAlpha). Skipping it at distance (RenderVKRTSunAlphaDist) makes leaf cards shadow as solid rectangles (black rings around canopies). Projector RT shadows and the RT debug views pay the same cost.

Approach

  • Build: for alpha-mask BLAS geometries (the leaf / cut-out slots), bake an opacity micromap per triangle from the base-colour alpha at the material cutoff: 2-state (opaque / transparent) or 4-state (+ unknown-opaque / unknown-transparent near edges). Micro-triangle subdivision level from texel coverage (cap ~8-9). A compute pass samples the texture (resident mip) per micro-triangle; build with vkCmdBuildMicromapsEXT, attach via VkAccelerationStructureTrianglesOpacityMicromapEXT.
  • Trace: the hardware resolves known-opaque / known-transparent micro-triangles itself; only "unknown" ones (4-state edges) still come back as candidates to the existing shader alpha test. Rays over foliage then cost close to opaque rays.
  • Invalidation: rebake when the texture sharpens (discard change), the material cutoff / texture / UV transform changes, or the slot is rebuilt; texture-animated faces (flag 1024) and alpha-blend casters stay on the shader path.
  • Memory: micromap arrays count toward the RT VRAM budget (#164); drop them first under pressure.

Fallback (must keep)

Devices / drivers without VK_EXT_opacity_micromap (RTX 20/30, RX 6000/7000, many Linux drivers) keep today's path: candidate alpha test in the shader, RenderVKRTSunAlphaDist available as the performance knob. Detect at device init; log which path is active; About window notes it alongside the RT status.

Done when

Ray-traced sun shadows with leaf-accurate foliage cost about what opaque-only rays do on OMM hardware, identical images to the shader path, and no regression on non-OMM RT cards.

Related: #185 (RT sun / moon), #85 (denoiser), #164 (RT VRAM budget), #157 (RT build cost).

Hardware alpha testing for ray-traced shadows via **opacity micromaps** (`VK_EXT_opacity_micromap`), with the current shader alpha test kept as the fallback so every RT card still works. ### Why Ray-traced sun shadows (#185) with the per-leaf alpha test cost ~2.4 ms vs cascades on an RTX 5090 (same view: 14.8 -> 17.2 ms); ~1.3 ms of that is the candidate alpha test -- every alpha-mask triangle a ray crosses returns to the shader for a texture fetch (clean_rt_common.glsl `traceShadowRay` / `rtCandidateAlpha`). Skipping it at distance (`RenderVKRTSunAlphaDist`) makes leaf cards shadow as solid rectangles (black rings around canopies). Projector RT shadows and the RT debug views pay the same cost. ### Approach - **Build**: for alpha-mask BLAS geometries (the leaf / cut-out slots), bake an opacity micromap per triangle from the base-colour alpha at the material cutoff: 2-state (opaque / transparent) or 4-state (+ unknown-opaque / unknown-transparent near edges). Micro-triangle subdivision level from texel coverage (cap ~8-9). A compute pass samples the texture (resident mip) per micro-triangle; build with `vkCmdBuildMicromapsEXT`, attach via `VkAccelerationStructureTrianglesOpacityMicromapEXT`. - **Trace**: the hardware resolves known-opaque / known-transparent micro-triangles itself; only "unknown" ones (4-state edges) still come back as candidates to the existing shader alpha test. Rays over foliage then cost close to opaque rays. - **Invalidation**: rebake when the texture sharpens (discard change), the material cutoff / texture / UV transform changes, or the slot is rebuilt; texture-animated faces (flag 1024) and alpha-blend casters stay on the shader path. - **Memory**: micromap arrays count toward the RT VRAM budget (#164); drop them first under pressure. ### Fallback (must keep) Devices / drivers without `VK_EXT_opacity_micromap` (RTX 20/30, RX 6000/7000, many Linux drivers) keep today's path: candidate alpha test in the shader, `RenderVKRTSunAlphaDist` available as the performance knob. Detect at device init; log which path is active; About window notes it alongside the RT status. ### Done when Ray-traced sun shadows with leaf-accurate foliage cost about what opaque-only rays do on OMM hardware, identical images to the shader path, and no regression on non-OMM RT cards. Related: #185 (RT sun / moon), #85 (denoiser), #164 (RT VRAM budget), #157 (RT build cost).
Author
Owner

Status check (verification sweep): opacity micromaps shipped in v0.14.0-beta.1 (f1959b9546). They cover static and worn-rigid alpha-mask geometry, with a startup self-test and the shader alpha test as fallback (RenderVKRTOpacityMicromaps, RenderVKRTOmmMaxLevel). Still open, per the commit: rigged alpha-mask geometry is not covered yet.

Status check (verification sweep): opacity micromaps shipped in v0.14.0-beta.1 (f1959b9546). They cover static and worn-rigid alpha-mask geometry, with a startup self-test and the shader alpha test as fallback (RenderVKRTOpacityMicromaps, RenderVKRTOmmMaxLevel). Still open, per the commit: rigged alpha-mask geometry is not covered yet.
Author
Owner

Status 2026-10-05: shipped for static and worn-rigid alpha-mask geometry (f1959b9546). Left open for the remaining scope: rigged alpha-mask geometry.

Status 2026-10-05: shipped for static and worn-rigid alpha-mask geometry (f1959b9546). Left open for the remaining scope: rigged alpha-mask geometry.
sky_line added this to the Slipstream project 2026-10-06 15:04:15 +00:00
Author
Owner

Done: opacity micromaps are live for RT alpha-tested shadows (shader alpha test kept as fallback). VRAM follow-up: #580.

Done: opacity micromaps are live for RT alpha-tested shadows (shader alpha test kept as fallback). VRAM follow-up: #580.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sky_line/Slipstream#194
No description provided.