Skip to content

perf: optimise shadows#2147

Merged
alandtse merged 1 commit into
devfrom
shadow-opt
Apr 18, 2026
Merged

perf: optimise shadows#2147
alandtse merged 1 commit into
devfrom
shadow-opt

Conversation

@doodlum
Copy link
Copy Markdown
Collaborator

@doodlum doodlum commented Apr 18, 2026

Summary by CodeRabbit

  • Refactor
    • Enhanced shadow filtering implementation by replacing Poisson disk-based sampling with PCF-style shadow filtering, delivering improved performance and more consistent shadow quality.
    • Streamlined dual-paraboloid shadow mapping with optimized filtering helpers.
    • Reduced shader code complexity for faster compilation and smaller file sizes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 18, 2026

📝 Walkthrough

Walkthrough

Refactored shadow visibility filtering in Utility.hlsl by replacing Poisson disk-based GetPoissonDiskFilteredShadowVisibility functions with two new PCF-style helpers: SampleShadowPCF and SampleDualParaboloidShadowPCF. The new functions use 8 unrolled spiral sample offsets with rotation and radius scaling instead of seeded offset generation.

Changes

Cohort / File(s) Summary
Shadow Filtering Refactoring
package/Shaders/Utility.hlsl
Removed two GetPoissonDiskFilteredShadowVisibility overloads and added SampleShadowPCF and SampleDualParaboloidShadowPCF helpers. Updated main call sites to use new PCF sampling with SpiralSampleOffsets8 rotated samples. Removed seed-based offset generation and noise range transformation logic. Updated dual-paraboloid UV remapping formatting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • alandtse
  • jiayev

Poem

🐰 Shadow sampling code, hops in new ways,
Poisson disks gone, PCF saves the day,
Eight spiral samples twirl and rotate,
Filtering shadows, the hoppy new fate! 🌙

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'perf: optimise shadows' accurately reflects the main change—replacing Poisson disk filtering with simpler PCF-style sampling to improve performance.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch shadow-opt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

No actionable suggestions for changed features.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
package/Shaders/Utility.hlsl (1)

620-644: ⚠️ Potential issue | 🟠 Major

PB path incorrectly clamps upper half of shadow samples — use SampleShadowPCF instead.

In the RENDER_SHADOWMASKPB case, shadowMapUv is computed across the full [0,1] range (line 628: lightDirection.xy / lightDirection.z * 0.5 + 0.5), which matches the layout of a single-paraboloid shadow map. However, line 638 calls SampleDualParaboloidShadowPCF(..., lowerHalf=false), which internally applies:

uv.y = min(uv.y, 0.5);

This caps all samples to y ≤ 0.5, collapsing the filter footprint onto a horizontal line whenever shadowMapUv.y > 0.5. The effect is visible as incorrect shadowing in the upper hemisphere of the single-paraboloid map—a horizontal seam or band where filtering breaks down.

By contrast, line 636 (SHADOWFILTER==1) samples the full unclamped range, so SHADOWFILTER==3 will produce visibly different shadows.

Fix: Use SampleShadowPCF instead, which applies no y-clamping and is designed for single-paraboloid layouts. Alternatively, pre-remap shadowMapUv.y to [0, 0.5] before the call, mirroring the RENDER_SHADOWMASKDPB pattern on line 656.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package/Shaders/Utility.hlsl` around lines 620 - 644, In the
RENDER_SHADOWMASKPB branch you must stop using SampleDualParaboloidShadowPCF
(which clamps uv.y) and call SampleShadowPCF instead so the full shadowMapUv
range is sampled; locate the call to SampleDualParaboloidShadowPCF in the block
that computes shadowMapUv and shadowVisibility and replace it with
SampleShadowPCF passing the same sampler/params (shadowMapUv,
EndSplitDistances.x, shadowMapCompareValue, rotationMatrix, ShadowSampleParam.z,
false) or otherwise mirror the RENDER_SHADOWMASKDPB pattern (remapping uv.y to
[0,0.5]) if you prefer clamping — ensure shadowVisibility is set from
SampleShadowPCF rather than SampleDualParaboloidShadowPCF.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@package/Shaders/Utility.hlsl`:
- Around line 620-644: In the RENDER_SHADOWMASKPB branch you must stop using
SampleDualParaboloidShadowPCF (which clamps uv.y) and call SampleShadowPCF
instead so the full shadowMapUv range is sampled; locate the call to
SampleDualParaboloidShadowPCF in the block that computes shadowMapUv and
shadowVisibility and replace it with SampleShadowPCF passing the same
sampler/params (shadowMapUv, EndSplitDistances.x, shadowMapCompareValue,
rotationMatrix, ShadowSampleParam.z, false) or otherwise mirror the
RENDER_SHADOWMASKDPB pattern (remapping uv.y to [0,0.5]) if you prefer clamping
— ensure shadowVisibility is set from SampleShadowPCF rather than
SampleDualParaboloidShadowPCF.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3105647f-f37d-4c8d-9429-be58f1c721e1

📥 Commits

Reviewing files that changed from the base of the PR and between c150dfd and a970bea.

📒 Files selected for processing (1)
  • package/Shaders/Utility.hlsl

@doodlum doodlum marked this pull request as draft April 18, 2026 15:27
@doodlum doodlum marked this pull request as ready for review April 18, 2026 15:28
@doodlum doodlum changed the title perf: optimise shadow sampling perf: optimise shadows Apr 18, 2026
@github-actions
Copy link
Copy Markdown

✅ A pre-release build is available for this PR:
Download

@alandtse alandtse merged commit 31862bd into dev Apr 18, 2026
26 of 32 checks passed
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants