diff --git a/crates/victory-gpu/src/ambient.rs b/crates/victory-gpu/src/ambient.rs index 5f821e9..427dd8f 100644 --- a/crates/victory-gpu/src/ambient.rs +++ b/crates/victory-gpu/src/ambient.rs @@ -218,7 +218,8 @@ void place(uint3 at : SV_DispatchThreadID) { float2 size = float2(width, height); float3 p = seen(int2((float2(at.xy) + 0.5) * size / float2(CX, CY)), size); float wz = min(p.z, 50.0); - cells[CELLS + 1 + at.y * CX + at.x] = float4(p, wz * wz); + float3 pc = p * (wz / max(p.z, 1e-6)); + cells[CELLS + 1 + at.y * CX + at.x] = float4(pc, wz * wz); } #endif @@ -464,7 +465,7 @@ pub(crate) struct Views { /// The image the title's program just wrote. pub(crate) image: D3D12_GPU_DESCRIPTOR_HANDLE, /// The scene's depth, for [`Role::Resolve`]. - pub(crate) depth: D3D12_GPU_DESCRIPTOR_HANDLE, + pub(crate) depth: Option, /// The size of the image, the size of the depth texture, and how many slices it has. pub(crate) size: [u32; 2], pub(crate) depth_size: [u32; 2], @@ -522,7 +523,9 @@ pub(crate) fn after(list: &HostList, role: Role, views: &Views) -> bool { uav_barrier(l); l.SetComputeRootSignature(&pass.root); l.SetComputeRoot32BitConstants(0, 16, words.as_ptr().cast(), 0); - l.SetComputeRootDescriptorTable(1, views.depth); + if let Some(depth) = views.depth { + l.SetComputeRootDescriptorTable(1, depth); + } l.SetComputeRootDescriptorTable(2, views.image); l.SetComputeRootUnorderedAccessView(3, pass.cells.GetGPUVirtualAddress()); l.SetComputeRootUnorderedAccessView(4, pass.points.GetGPUVirtualAddress()); diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index 872eb6c..036ae0e 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -3234,19 +3234,23 @@ impl State { Role::Radiance => RADIANCE, Role::Air => AIR, }; - let image = entry(ResourceType::Uav, at); - let depth = match role { - Role::Resolve => entry(ResourceType::Srv, DEPTH), - Role::Radiance | Role::Air => image, - }; - let (Some((of, image)), Some((seen, depth))) = (image, depth) else { + let Some((of, image)) = entry(ResourceType::Uav, at) else { once!(?role, "no stand-in for the indirect light: other tables"); return false; }; + let (depth, depth_size) = if role == Role::Resolve { + let Some((seen, depth)) = entry(ResourceType::Srv, DEPTH) else { + once!(?role, "no stand-in for the indirect light: other tables"); + return false; + }; + (Some(depth), [seen.Width as u32, seen.Height]) + } else { + (None, [of.Width as u32, of.Height]) + }; // (R32_UINT holding R9G9B9E5; R11G11B10_FLOAT.) let format = if role == Role::Resolve { 42 } else { 26 }; let volume = of.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D; - if of.Format.0 != format || seen.Width == 0 || seen.Height == 0 || volume != (role == Role::Air) { + if of.Format.0 != format || depth_size[0] == 0 || depth_size[1] == 0 || volume != (role == Role::Air) { once!(?role, format = of.Format.0, "no stand-in for the indirect light: another image"); return false; } @@ -3254,7 +3258,7 @@ impl State { image, depth, size: [of.Width as u32, of.Height], - depth_size: [seen.Width as u32, seen.Height], + depth_size, slices: u32::from(of.DepthOrArraySize), }) }