Skip to content

Commit

Permalink
fix: ssgi outlines and terrain occlusion slow update (doodlum#350)
Browse files Browse the repository at this point in the history
* fix: ssgi outlines

* chore: doubling terrain shadow update length
  • Loading branch information
Pentalimbed authored Jul 23, 2024
1 parent c34fc04 commit d7cd1d0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion features/Screen Space GI/Shaders/ScreenSpaceGI/gi.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void CalculateGI(
const static bool useHistory = false;
#endif

float2 uv = (pxCoord + .5f) * RcpFrameDim;
float2 uv = (pxCoord + .5) * RcpFrameDim;
uint eyeIndex = GetEyeIndexFromTexCoord(uv);

float viewspaceZ = srcWorkingDepth[pxCoord];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ groupshared float g_scratchDepths[8][8];
const uint2 pixCoord = baseCoord * 2;
const float2 uv = (pixCoord + .5) * RcpFrameDim;

float4 depths4 = srcNDCDepth.GatherRed(samplerPointClamp, uv * frameScale, int2(1, 1));
float4 depths4 = srcNDCDepth.GatherRed(samplerPointClamp, uv * frameScale);
float depth0 = ClampDepth(ScreenToViewDepth(depths4.w));
float depth1 = ClampDepth(ScreenToViewDepth(depths4.z));
float depth2 = ClampDepth(ScreenToViewDepth(depths4.x));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ float2 GetInterpolatedHeightRW(float2 pxCoord, bool isVertical)
return heightA;
}

#define NTHREADS 64
#define NTHREADS 128
groupshared float2 g_shadowHeight[NTHREADS];

[numthreads(NTHREADS, 1, 1)] void main(const uint gtid
Expand Down
10 changes: 7 additions & 3 deletions src/Features/TerrainOcclusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ void TerrainOcclusion::UpdateShadow()
if (!IsHeightMapReady())
return;

// don't forget to change NTHREADS in shader!
constexpr uint updateLength = 128u;
constexpr uint logUpdateLength = std::bit_width(128u) - 1; // integer log2, https://stackoverflow.com/questions/994593/how-to-do-an-integer-log2-in-c

auto& context = State::GetSingleton()->context;
auto accumulator = RE::BSGraphics::BSShaderAccumulator::GetCurrentAccumulator();
auto sunLight = skyrim_cast<RE::NiDirectionalLight*>(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get());
Expand Down Expand Up @@ -454,12 +458,12 @@ void TerrainOcclusion::UpdateShadow()
stepMult = 1.f / abs(dirLightPxDir.x);
edgePxCoord = dirLightPxDir.x > 0 ? 0 : (width - 1);
signDir = dirLightPxDir.x > 0 ? 1 : -1;
maxUpdates = ((width - 1) >> 6) + 1;
maxUpdates = (width + updateLength - 1) >> logUpdateLength;
} else {
stepMult = 1.f / abs(dirLightPxDir.y);
edgePxCoord = dirLightPxDir.y > 0 ? 0 : height - 1;
signDir = dirLightPxDir.y > 0 ? 1 : -1;
maxUpdates = ((height - 1) >> 6) + 1;
maxUpdates = (height + updateLength - 1) >> logUpdateLength;
}
dirLightPxDir *= stepMult;

Expand All @@ -474,7 +478,7 @@ void TerrainOcclusion::UpdateShadow()
shadowUpdateCBData.LightDeltaZ = -(lenUV / invScale.z * stepMult) * float2{ std::tan(upperAngle), std::tan(lowerAngle) };
}

shadowUpdateCBData.StartPxCoord = edgePxCoord + signDir * shadowUpdateIdx * 64u;
shadowUpdateCBData.StartPxCoord = edgePxCoord + signDir * shadowUpdateIdx * updateLength;
shadowUpdateCBData.PxSize = { 1.f / texNormalisedHeight->desc.Width, 1.f / texNormalisedHeight->desc.Height };

shadowUpdateCB->Update(shadowUpdateCBData);
Expand Down

0 comments on commit d7cd1d0

Please sign in to comment.