-
Notifications
You must be signed in to change notification settings - Fork 138
feat: add shadowmap rasterizer override #1690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alandtse
merged 12 commits into
community-shaders:dev
from
Dawntic:fix-shadowmap-rasterizers
Feb 16, 2026
+134
−10
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
31d8666
feat: add rasterizer replacement system
Dawntic 8e0b431
remove shader thresholds
Dawntic 6837d7b
fix: depth bias
Dawntic c5ad7bf
fix: interiors default to being in shadow
Dawntic ee84fac
fix: address bot
Dawntic 7f0e7eb
fix version offsets
Dawntic 7773b56
feat: remember other cascade
Dawntic 3fa3237
fix: inline
Dawntic 070d33a
fix spelling
Dawntic ebabed7
adjust base settings
Dawntic adecef6
address comments
Dawntic c93a4e3
Merge branch 'dev' into fix-shadowmap-rasterizers
doodlum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #include "ShadowmapCascadeRasterizerFix.h" | ||
|
|
||
| void ShadowmapRasterizerFix::Install() | ||
| { | ||
| // This function is called once per cascade to begin the updating and rendering process | ||
| stl::write_thunk_call<BSShadowDirectionalLight_RenderShadowmaps_RenderCascade>(REL::RelocationID(101495, 108489).address() + REL::Relocate(0xC6, 0xC6)); | ||
|
|
||
| gRasterStates = reinterpret_cast<RasterStateArray*>(REL::RelocationID(524748, 411363).address()); | ||
| } | ||
|
|
||
| void ShadowmapRasterizerFix::BSShadowDirectionalLight_RenderShadowmaps_RenderCascade::thunk(RE::BSShadowDirectionalLight* light, void* arg1, void* arg2, uint32_t flags) | ||
| { | ||
| static uint cascade = 0; | ||
|
|
||
| static bool initialized = false; | ||
| if (!initialized) { | ||
| //Backup | ||
| if (cascade == 0) { | ||
| std::memcpy(backupGameRasterStates, *gRasterStates, sizeof(RasterStateArray)); | ||
| numCascades = std::min(RE::GetINISetting("iNumSplits:Display")->data.u, maxCascades); | ||
| } | ||
|
Dawntic marked this conversation as resolved.
|
||
|
|
||
| //Clone | ||
| CloneRasterStates(gRasterStates, cascade); | ||
|
|
||
| initialized = cascade == numCascades - 1; | ||
| } | ||
|
|
||
| //Emplace | ||
| std::memcpy(*gRasterStates, shadowmapRasterStates[cascade], sizeof(RasterStateArray)); | ||
|
|
||
| func(light, arg1, arg2, flags); | ||
|
|
||
| //Restore | ||
| if (cascade == numCascades - 1) | ||
| std::memcpy(*gRasterStates, backupGameRasterStates, sizeof(RasterStateArray)); | ||
|
|
||
| cascade = ++cascade < numCascades ? cascade : 0; | ||
| } | ||
|
Dawntic marked this conversation as resolved.
|
||
|
|
||
| void ShadowmapRasterizerFix::GetUpdatedRasterDesc(D3D11_RASTERIZER_DESC& outputDesc, ShadowMapRasterizerDescriptor shadowmapDesc) | ||
| { | ||
| outputDesc.DepthBias = shadowmapDesc.rasterDepthBias; | ||
| outputDesc.DepthBiasClamp = shadowmapDesc.rasterDepthBiasClamp; | ||
| outputDesc.SlopeScaledDepthBias = shadowmapDesc.rasterSlopeScaleBias; | ||
| } | ||
|
|
||
| // Since state objects are shared globally across the pipeline we make duplicate arrays that cover the same range of states the game does | ||
| void ShadowmapRasterizerFix::CloneRasterStates(RasterStateArray* inputArray, int cascade) | ||
| { | ||
| for (int fill = 0; fill < 2; fill++) { | ||
| for (int cull = 0; cull < 3; cull++) { | ||
| for (int depth = 0; depth < 12; depth++) { | ||
| for (int scissor = 0; scissor < 2; scissor++) { | ||
| if (auto* gRasterizer = (*inputArray)[fill][cull][depth][scissor]) { | ||
| D3D11_RASTERIZER_DESC desc{}; | ||
| gRasterizer->GetDesc(&desc); | ||
|
|
||
| GetUpdatedRasterDesc(desc, cascadeDescriptors[cascade]); | ||
|
|
||
| DX::ThrowIfFailed(globals::d3d::device->CreateRasterizerState(&desc, &shadowmapRasterStates[cascade][fill][cull][depth][scissor])); | ||
| } | ||
|
Dawntic marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Dawntic marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #pragma once | ||
|
|
||
| // This overrides the shadow cascade rasterizers to fix issues with peter panning and self shadowing | ||
| struct ShadowmapRasterizerFix : EngineFix | ||
| { | ||
| std::string GetName() override { return "Shadowmap Cascade Rasterizer Fix"; } | ||
| void Install() override; | ||
|
|
||
| using RasterStateArray = ID3D11RasterizerState* [2][3][12][2]; | ||
|
|
||
| static void CloneRasterStates(RasterStateArray* inputArray, int cascade); | ||
|
|
||
| static constexpr uint maxCascades = 3; | ||
| static inline uint numCascades = 0; | ||
|
|
||
| static inline RasterStateArray* gRasterStates = nullptr; | ||
| static inline RasterStateArray backupGameRasterStates = {}; | ||
| static inline RasterStateArray shadowmapRasterStates[maxCascades] = {}; | ||
|
Dawntic marked this conversation as resolved.
|
||
|
|
||
| static constexpr int firstCascadeDepthBias = 160; | ||
| static constexpr float firstCascadeDepthBiasClamp = 0.015f; | ||
| static constexpr float firstCascadeSlopeScaleBias = 3.2f; | ||
|
|
||
| static constexpr int secondCascadeDepthBias = 100; | ||
| static constexpr float secondCascadeDepthBiasClamp = 0.015f; | ||
| static constexpr float secondCascadeSlopeScaleBias = 3.8f; | ||
|
|
||
| static constexpr int thirdCascadeDepthBias = 100; | ||
| static constexpr float thirdCascadeDepthBiasClamp = 0.015f; | ||
| static constexpr float thirdCascadeSlopeScaleBias = 3.8f; | ||
|
|
||
| struct ShadowMapRasterizerDescriptor | ||
| { | ||
| int rasterDepthBias; | ||
| float rasterDepthBiasClamp; | ||
| float rasterSlopeScaleBias; | ||
| }; | ||
| static void GetUpdatedRasterDesc(D3D11_RASTERIZER_DESC& outputDesc, ShadowMapRasterizerDescriptor desc); | ||
|
|
||
| static constexpr ShadowMapRasterizerDescriptor cascadeDescriptors[maxCascades] = { | ||
| { firstCascadeDepthBias, firstCascadeDepthBiasClamp, firstCascadeSlopeScaleBias }, | ||
| { secondCascadeDepthBias, secondCascadeDepthBiasClamp, secondCascadeSlopeScaleBias }, | ||
| { thirdCascadeDepthBias, thirdCascadeDepthBiasClamp, thirdCascadeSlopeScaleBias } | ||
| }; | ||
|
|
||
| struct BSShadowDirectionalLight_RenderShadowmaps_RenderCascade | ||
| { | ||
| static void thunk(RE::BSShadowDirectionalLight* light, void* arg1, void* arg2, uint32_t flags); | ||
| static inline REL::Relocation<decltype(thunk)> func; | ||
| }; | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.