From b685fe06617e9e6ea620bbdb5d294d2098c5129e Mon Sep 17 00:00:00 2001 From: doodlum <15017472+doodlum@users.noreply.github.com> Date: Tue, 21 Apr 2026 17:01:34 +0100 Subject: [PATCH] Revert "perf(terrain shadows): half res and 4x faster updates (#2163)" This reverts commit 7661ba7e0c1ac840233b2c46b83b507e6d498578. --- .../TerrainShadows/ShadowUpdate.cs.hlsl | 22 ++++++------------- src/Features/TerrainShadows.cpp | 21 ++++-------------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/features/Terrain Shadows/Shaders/TerrainShadows/ShadowUpdate.cs.hlsl b/features/Terrain Shadows/Shaders/TerrainShadows/ShadowUpdate.cs.hlsl index f4f162cf40..c434a1e09d 100644 --- a/features/Terrain Shadows/Shaders/TerrainShadows/ShadowUpdate.cs.hlsl +++ b/features/Terrain Shadows/Shaders/TerrainShadows/ShadowUpdate.cs.hlsl @@ -63,15 +63,8 @@ float2 GetInterpolatedHeightRW(float2 pxCoord, bool isVertical) groupshared float2 g_shadowHeight[NTHREADS]; [numthreads(NTHREADS, 1, 1)] void main(const uint gtid : SV_GroupThreadID, const uint gid : SV_GroupID) { - // Two independent coordinate spaces are used here: the heightmap sampling - // space (TexHeight) and the shadow-pixel space (RWTexShadowHeights). The - // CPU path may resize the height texture independently of the shadow - // resolution, so sampling and resizing can be done separately for each - // space. LightPxDir and PxSize are expressed in shadow-pixel units. - uint2 heightDims; - TexHeight.GetDimensions(heightDims.x, heightDims.y); - uint2 shadowDims; - RWTexShadowHeights.GetDimensions(shadowDims.x, shadowDims.y); + uint2 dims; + TexHeight.GetDimensions(dims.x, dims.y); bool isVertical = abs(LightPxDir.y) > abs(LightPxDir.x); float2 lightUVDir = LightPxDir * PxSize; @@ -84,19 +77,18 @@ groupshared float2 g_shadowHeight[NTHREADS]; bool isValid = isVertical ? isUVinRange.y : isUVinRange.x; float2 threadUV = rawThreadUV - floor(rawThreadUV); // wraparound - float2 heightPxCoord = threadUV * heightDims; - float2 shadowPxCoord = threadUV * shadowDims; + float2 threadPxCoord = threadUV * dims; float2 pastHeights = 0.0; if (isValid) { - pastHeights = RWTexShadowHeights[uint2(shadowPxCoord)]; + pastHeights = RWTexShadowHeights[uint2(threadPxCoord)]; // bifilter - float2 heights = GetInterpolatedHeight(heightPxCoord, isVertical).xx; + float2 heights = GetInterpolatedHeight(threadPxCoord, isVertical).xx; // fetch last dispatch if (gtid == 0 && all(floor(rawThreadUV - lightUVDir) == floor(rawThreadUV))) { - float2 sampleHeights = GetInterpolatedHeightRW(shadowPxCoord - LightPxDir, isVertical) + LightDeltaZ; + float2 sampleHeights = GetInterpolatedHeightRW(threadPxCoord - LightPxDir, isVertical) + LightDeltaZ; heights = heights.x > sampleHeights.x ? heights : sampleHeights; } @@ -121,6 +113,6 @@ groupshared float2 g_shadowHeight[NTHREADS]; // save if (isValid) { - RWTexShadowHeights[uint2(shadowPxCoord)] = lerp(pastHeights, g_shadowHeight[gtid], 0.5f); + RWTexShadowHeights[uint2(threadPxCoord)] = lerp(pastHeights, g_shadowHeight[gtid], 0.5f); } } \ No newline at end of file diff --git a/src/Features/TerrainShadows.cpp b/src/Features/TerrainShadows.cpp index 413158f60f..df9efb40d9 100644 --- a/src/Features/TerrainShadows.cpp +++ b/src/Features/TerrainShadows.cpp @@ -224,17 +224,7 @@ void TerrainShadows::LoadHeightmap() std::filesystem::path path{ target_heightmap.dir }; path /= target_heightmap.filename; - DirectX::ScratchImage rawImage; - DX::ThrowIfFailed(LoadFromDDSFile(path.c_str(), DirectX::DDS_FLAGS_NONE, nullptr, rawImage)); - - // Downscale heightmap to 1/2 resolution per axis to match the - // shadow texture and speed up full shadow updates by ~4x. - auto& rawMeta = rawImage.GetMetadata(); - size_t newWidth = std::max(1, rawMeta.width / 2); - size_t newHeight = std::max(1, rawMeta.height / 2); - DX::ThrowIfFailed(DirectX::Resize( - rawImage.GetImages(), rawImage.GetImageCount(), rawMeta, - newWidth, newHeight, DirectX::TEX_FILTER_LINEAR, image)); + DX::ThrowIfFailed(LoadFromDDSFile(path.c_str(), DirectX::DDS_FLAGS_NONE, nullptr, image)); } catch (const DX::com_exception& e) { logger::error("{}", e.what()); return; @@ -343,11 +333,8 @@ void TerrainShadows::UpdateShadow() TracyD3D11Zone(globals::state->tracyCtx, "Terrain Occlusion - Update Shadows"); /* ---- UPDATE CB ---- */ - // Shadow texture is 1/2 heightmap resolution per axis; ray stepping, - // dispatch and PxSize all operate in shadow-pixel space, while the - // shader still samples the full-res heightmap via UV. - uint width = texShadowHeight->desc.Width; - uint height = texShadowHeight->desc.Height; + uint width = texHeightMap->desc.Width; + uint height = texHeightMap->desc.Height; // only update direction at the start of each cycle static uint edgePxCoord; @@ -393,7 +380,7 @@ void TerrainShadows::UpdateShadow() } shadowUpdateCBData.StartPxCoord = edgePxCoord + signDir * shadowUpdateIdx * updateLength; - shadowUpdateCBData.PxSize = { 1.f / width, 1.f / height }; + shadowUpdateCBData.PxSize = { 1.f / texHeightMap->desc.Width, 1.f / texHeightMap->desc.Height }; shadowUpdateCBData.PosRange = { cachedHeightmap->pos0.z, cachedHeightmap->pos1.z }; shadowUpdateCBData.ZRange = cachedHeightmap->zRange;