Skip to content

Commit 8b13499

Browse files
authored
refactor(interior sun): rename interior sun shadows (#1387)
1 parent f925a5c commit 8b13499

File tree

11 files changed

+65
-43
lines changed

11 files changed

+65
-43
lines changed

src/Feature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "Features/GrassLighting.h"
1111
#include "Features/HairSpecular.h"
1212
#include "Features/IBL.h"
13-
#include "Features/InteriorSunShadows.h"
13+
#include "Features/InteriorSun.h"
1414
#include "Features/InverseSquareLighting.h"
1515
#include "Features/LODBlending.h"
1616
#include "Features/LightLimitFix.h"
@@ -219,7 +219,7 @@ const std::vector<Feature*>& Feature::GetFeatureList()
219219
&globals::features::lodBlending,
220220
&globals::features::inverseSquareLighting,
221221
&globals::features::hairSpecular,
222-
&globals::features::interiorSunShadows,
222+
&globals::features::interiorSun,
223223
&globals::features::terrainVariation,
224224
&globals::features::ibl,
225225
&globals::features::extendedTranslucency

src/Features/InteriorSunShadows.cpp renamed to src/Features/InteriorSun.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
1-
#include "InteriorSunShadows.h"
1+
#include "InteriorSun.h"
22
#include "State.h"
33

44
#include <numbers>
55

66
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
7-
InteriorSunShadows::Settings,
8-
ForceDoubleSidedRendering)
7+
InteriorSun::Settings,
8+
ForceDoubleSidedRendering,
9+
InteriorShadowDistance)
910

10-
void InteriorSunShadows::DrawSettings()
11+
void InteriorSun::DrawSettings()
1112
{
1213
ImGui::Checkbox("Force Double-Sided Rendering", &settings.ForceDoubleSidedRendering);
1314
if (auto _tt = Util::HoverTooltipWrapper()) {
1415
ImGui::Text(
1516
"Disables backface culling during sun shadowmap rendering in interiors. "
1617
"Will prevent most light leaking through unmasked/unprepared interiors at a small performance cost. ");
1718
}
19+
if (ImGui::SliderFloat("Interior Shadow Distance", &settings.InteriorShadowDistance, 1000.0f, 8000.0f)) {
20+
*gInteriorShadowDistance = settings.InteriorShadowDistance;
21+
SetShadowDistance(globals::game::tes && globals::game::tes->interiorCell);
22+
}
23+
if (auto _tt = Util::HoverTooltipWrapper()) {
24+
ImGui::Text(
25+
"Sets the distance shadows are rendered at in interiors. "
26+
"Lower values provide higher quality shadows and improved performance but may cause distant interior spaces to light up incorrectly. ");
27+
}
1828
}
1929

20-
void InteriorSunShadows::LoadSettings(json& o_json)
30+
void InteriorSun::LoadSettings(json& o_json)
2131
{
2232
settings = o_json;
2333
}
2434

25-
void InteriorSunShadows::SaveSettings(json& o_json)
35+
void InteriorSun::SaveSettings(json& o_json)
2636
{
2737
o_json = settings;
2838
}
2939

30-
void InteriorSunShadows::RestoreDefaultSettings()
40+
void InteriorSun::RestoreDefaultSettings()
3141
{
3242
settings = {};
3343
}
3444

35-
void InteriorSunShadows::PostPostLoad()
45+
void InteriorSun::PostPostLoad()
3646
{
3747
// Hooks and patch to enable directional lighting for interiors
3848
stl::write_thunk_call<GetWorldSpace>(REL::RelocationID(35562, 36561).address() + REL::Relocate(0x399, 0x37D, 0x639));
@@ -48,6 +58,7 @@ void InteriorSunShadows::PostPostLoad()
4858
REL::safe_fill(REL::RelocationID(38900, 39946).address() + REL::Relocate(0x2CA, 0x22B), REL::NOP, REL::Module::IsAE() ? 6 : 2);
4959

5060
gShadowDistance = reinterpret_cast<float*>(REL::RelocationID(528314, 415263).address());
61+
gInteriorShadowDistance = reinterpret_cast<float*>(REL::RelocationID(513755, 391724).address());
5162

5263
// Patches BSShadowDirectionalLight::SetFrameCamera to read the correct shadow distance value in interior cells
5364
const std::uintptr_t address = REL::RelocationID(101499, 108496).address() + REL::Relocate(0xD62, 0xE6C, 0xE72);
@@ -56,41 +67,41 @@ void InteriorSunShadows::PostPostLoad()
5667

5768
rasterStateCullMode = globals::game::isVR ? &globals::game::shadowState->GetVRRuntimeData().rasterStateCullMode : &globals::game::shadowState->GetRuntimeData().rasterStateCullMode;
5869

59-
logger::info("[Interior Sun Shadows] Installed hooks");
70+
logger::info("[Interior Sun] Installed hooks");
6071
}
6172

62-
void InteriorSunShadows::EarlyPrepass()
73+
void InteriorSun::EarlyPrepass()
6374
{
6475
isInteriorWithSun = IsInteriorWithSun(globals::game::tes->interiorCell);
6576
}
6677

67-
inline bool InteriorSunShadows::IsInteriorWithSun(const RE::TESObjectCELL* cell)
78+
inline bool InteriorSun::IsInteriorWithSun(const RE::TESObjectCELL* cell)
6879
{
6980
return cell && cell->cellFlags.all(RE::TESObjectCELL::Flag::kIsInteriorCell, RE::TESObjectCELL::Flag::kShowSky, RE::TESObjectCELL::Flag::kUseSkyLighting, static_cast<RE::TESObjectCELL::Flag>(CellFlagExt::kSunlightShadows));
7081
}
7182

72-
RE::TESWorldSpace* InteriorSunShadows::GetWorldSpace::thunk(RE::TES* tes)
83+
RE::TESWorldSpace* InteriorSun::GetWorldSpace::thunk(RE::TES* tes)
7384
{
7485
if (const auto cell = tes->interiorCell)
75-
return IsInteriorWithSun(cell) ? enableInteriorSunShadows : disableInteriorSunShadows;
86+
return IsInteriorWithSun(cell) ? enableInteriorSun : disableInteriorSun;
7687
return func(tes);
7788
}
7889

79-
RE::TESWorldSpace* InteriorSunShadows::enableInteriorSunShadows = [] {
90+
RE::TESWorldSpace* InteriorSun::enableInteriorSun = [] {
8091
alignas(RE::TESWorldSpace) static char buffer[sizeof(RE::TESWorldSpace)]{};
8192
return reinterpret_cast<RE::TESWorldSpace*>(buffer);
8293
}();
8394

84-
RE::TESWorldSpace* InteriorSunShadows::disableInteriorSunShadows = [] {
95+
RE::TESWorldSpace* InteriorSun::disableInteriorSun = [] {
8596
alignas(RE::TESWorldSpace) static char buffer[sizeof(RE::TESWorldSpace)] = {};
8697
const auto noShadows = reinterpret_cast<RE::TESWorldSpace*>(buffer);
8798
noShadows->flags.set(RE::TESWorldSpace::Flag::kNoSky, RE::TESWorldSpace::Flag::kFixedDimensions);
8899
return noShadows;
89100
}();
90101

91-
void InteriorSunShadows::DirShadowLightCulling::thunk(RE::BSShadowDirectionalLight* dirLight, RE::BSTArray<RE::BSTArray<RE::NiPointer<RE::NiAVObject>>>& jobArrays, RE::BSTArray<RE::NiPointer<RE::NiAVObject>>& nodes)
102+
void InteriorSun::DirShadowLightCulling::thunk(RE::BSShadowDirectionalLight* dirLight, RE::BSTArray<RE::BSTArray<RE::NiPointer<RE::NiAVObject>>>& jobArrays, RE::BSTArray<RE::NiPointer<RE::NiAVObject>>& nodes)
92103
{
93-
auto& singleton = globals::features::interiorSunShadows;
104+
auto& singleton = globals::features::interiorSun;
94105
const auto cell = globals::game::tes->interiorCell;
95106
auto* passedJobArrays = &jobArrays;
96107

@@ -111,7 +122,7 @@ void InteriorSunShadows::DirShadowLightCulling::thunk(RE::BSShadowDirectionalLig
111122
func(dirLight, *passedJobArrays, nodes);
112123
}
113124

114-
void InteriorSunShadows::ClearArrays()
125+
void InteriorSun::ClearArrays()
115126
{
116127
currentCellRoomsAndPortals.clear();
117128

@@ -127,7 +138,7 @@ namespace RE
127138
{};
128139
}
129140

130-
void InteriorSunShadows::PopulateReplacementJobArrays(RE::TESObjectCELL* cell, const RE::NiPointer<RE::BSPortalGraph>& portalGraph, const RE::BSShadowDirectionalLight* dirLight, RE::BSTArray<RE::BSTArray<RE::NiPointer<RE::NiAVObject>>>& jobArrays)
141+
void InteriorSun::PopulateReplacementJobArrays(RE::TESObjectCELL* cell, const RE::NiPointer<RE::BSPortalGraph>& portalGraph, const RE::BSShadowDirectionalLight* dirLight, RE::BSTArray<RE::BSTArray<RE::NiPointer<RE::NiAVObject>>>& jobArrays)
131142
{
132143
if (cell != currentCell) {
133144
InitialiseOnNewCell(portalGraph);
@@ -170,7 +181,7 @@ void InteriorSunShadows::PopulateReplacementJobArrays(RE::TESObjectCELL* cell, c
170181
arraysCleared = false;
171182
}
172183

173-
void InteriorSunShadows::InitialiseOnNewCell(const RE::NiPointer<RE::BSPortalGraph>& portalGraph)
184+
void InteriorSun::InitialiseOnNewCell(const RE::NiPointer<RE::BSPortalGraph>& portalGraph)
174185
{
175186
currentCellRoomsAndPortals.clear();
176187

@@ -183,11 +194,18 @@ void InteriorSunShadows::InitialiseOnNewCell(const RE::NiPointer<RE::BSPortalGra
183194
}
184195
}
185196

186-
bool InteriorSunShadows::IsInSunDirectionAndWithinShadowDistance(const RE::NiPointer<RE::NiAVObject>& object, const RE::NiPoint3& lightDir, const RE::NiPoint3& playerPos) const
197+
bool InteriorSun::IsInSunDirectionAndWithinShadowDistance(const RE::NiPointer<RE::NiAVObject>& object, const RE::NiPoint3& lightDir, const RE::NiPoint3& playerPos) const
187198
{
188199
const float radius = object->worldBound.radius;
189200
const auto diff = object->worldBound.center - playerPos;
190201
const float distance = diff.Length();
191202
const float projection = lightDir.Dot(diff);
192203
return projection >= -radius && (distance - radius) <= *gShadowDistance;
204+
}
205+
206+
void InteriorSun::SetShadowDistance(bool inInterior)
207+
{
208+
using func_t = decltype(SetShadowDistance);
209+
static REL::Relocation<func_t> func{ REL::RelocationID(98978, 105631).address() };
210+
func(inInterior);
193211
}

src/Features/InteriorSunShadows.h renamed to src/Features/InteriorSun.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#pragma once
22
#include "ShaderCache.h"
33

4-
struct InteriorSunShadows : Feature
4+
struct InteriorSun : Feature
55
{
66
private:
77
static constexpr std::string_view MOD_ID = "153541";
88

99
public:
10-
virtual inline std::string GetName() override { return "Interior Sun Shadows"; }
11-
virtual inline std::string GetShortName() override { return "InteriorSunShadows"; }
10+
virtual inline std::string GetName() override { return "Interior Sun"; }
11+
virtual inline std::string GetShortName() override { return "InteriorSun"; }
1212
virtual std::string_view GetCategory() const override { return "Lighting"; }
1313
virtual std::pair<std::string, std::vector<std::string>> GetFeatureSummary() override
1414
{
@@ -31,6 +31,7 @@ struct InteriorSunShadows : Feature
3131
struct Settings
3232
{
3333
bool ForceDoubleSidedRendering = true;
34+
float InteriorShadowDistance = 5000;
3435
};
3536

3637
Settings settings;
@@ -73,6 +74,7 @@ struct InteriorSunShadows : Feature
7374
};
7475

7576
float* gShadowDistance = nullptr;
77+
float* gInteriorShadowDistance = nullptr;
7678
uint32_t* rasterStateCullMode = nullptr;
7779

7880
RE::TESObjectCELL* currentCell = nullptr;
@@ -82,8 +84,8 @@ struct InteriorSunShadows : Feature
8284
RE::BSTArray<RE::BSTArray<RE::NiPointer<RE::NiAVObject>>> replacementJobArrays = {};
8385
eastl::hash_set<RE::NiAVObject*> addedSet = {};
8486

85-
static RE::TESWorldSpace* enableInteriorSunShadows;
86-
static RE::TESWorldSpace* disableInteriorSunShadows;
87+
static RE::TESWorldSpace* enableInteriorSun;
88+
static RE::TESWorldSpace* disableInteriorSun;
8789

8890
void ClearArrays();
8991

@@ -92,4 +94,6 @@ struct InteriorSunShadows : Feature
9294
bool IsInSunDirectionAndWithinShadowDistance(const RE::NiPointer<RE::NiAVObject>& object, const RE::NiPoint3& lightDir, const RE::NiPoint3& playerPos) const;
9395

9496
void PopulateReplacementJobArrays(RE::TESObjectCELL* cell, const RE::NiPointer<RE::BSPortalGraph>& portalGraph, const RE::BSShadowDirectionalLight* dirLight, RE::BSTArray<RE::BSTArray<RE::NiPointer<RE::NiAVObject>>>& jobArrays);
97+
98+
static void SetShadowDistance(bool inInterior);
9599
};

src/Features/VolumetricLighting.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "VolumetricLighting.h"
22

3-
#include "InteriorSunShadows.h"
3+
#include "InteriorSun.h"
44
#include "ShaderCache.h"
55
#include "State.h"
66

@@ -220,17 +220,17 @@ void VolumetricLighting::EarlyPrepass()
220220

221221
initialised = true;
222222
inInterior = currentlyInInterior;
223-
inInteriorWithSunShadows = InteriorSunShadows::IsInteriorWithSun(interiorCell);
223+
inInteriorWithSun = InteriorSun::IsInteriorWithSun(interiorCell);
224224
SetupVL();
225225
}
226226

227227
void VolumetricLighting::SetupVL()
228228
{
229229
if (inInterior) {
230230
if (globals::game::isVR)
231-
SetBooleanSettings(hiddenVRSettings, GetName(), settings.InteriorEnabled && inInteriorWithSunShadows);
231+
SetBooleanSettings(hiddenVRSettings, GetName(), settings.InteriorEnabled && inInteriorWithSun);
232232
else
233-
*bEnableVolumetricLighting = settings.InteriorEnabled && inInteriorWithSunShadows;
233+
*bEnableVolumetricLighting = settings.InteriorEnabled && inInteriorWithSun;
234234
*gVolumetricLightingSizeHigh = static_cast<Quality>(settings.InteriorQuality) == Quality::Custom ? settings.InteriorCustomSize : defaultSizeHigh;
235235
SetVLQuality(GetVLDescriptor(), settings.InteriorQuality);
236236
} else {

src/Features/VolumetricLighting.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct VolumetricLighting : Feature
128128

129129
bool initialised = false;
130130
bool inInterior = false;
131-
bool inInteriorWithSunShadows = false;
131+
bool inInteriorWithSun = false;
132132

133133
struct VLData
134134
{

src/Globals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "Features/GrassLighting.h"
2020
#include "Features/HairSpecular.h"
2121
#include "Features/IBL.h"
22-
#include "Features/InteriorSunShadows.h"
22+
#include "Features/InteriorSun.h"
2323
#include "Features/InverseSquareLighting.h"
2424
#include "Features/LODBlending.h"
2525
#include "Features/LightLimitFix.h"
@@ -63,7 +63,7 @@ namespace globals
6363
LightLimitFix lightLimitFix{};
6464
LODBlending lodBlending{};
6565
HairSpecular hairSpecular{};
66-
InteriorSunShadows interiorSunShadows{};
66+
InteriorSun interiorSun{};
6767
InverseSquareLighting inverseSquareLighting{};
6868
ScreenSpaceGI screenSpaceGI{};
6969
ScreenSpaceShadows screenSpaceShadows{};

src/Globals.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct HairSpecular;
99
struct IBL;
1010
struct LightLimitFix;
1111
struct LODBlending;
12-
struct InteriorSunShadows;
12+
struct InteriorSun;
1313
struct InverseSquareLighting;
1414
struct ScreenSpaceGI;
1515
struct ScreenSpaceShadows;
@@ -64,7 +64,7 @@ namespace globals
6464
extern IBL ibl;
6565
extern LightLimitFix lightLimitFix;
6666
extern LODBlending lodBlending;
67-
extern InteriorSunShadows interiorSunShadows;
67+
extern InteriorSun interiorSun;
6868
extern InverseSquareLighting inverseSquareLighting;
6969
extern ScreenSpaceGI screenSpaceGI;
7070
extern ScreenSpaceShadows screenSpaceShadows;

src/Hooks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "TruePBR.h"
1010
#include "Util.h"
1111

12-
#include "Features/InteriorSunShadows.h"
12+
#include "Features/InteriorSun.h"
1313
#include "Features/LightLimitFix.h"
1414
#include "Features/TerrainHelper.h"
1515
#include "Features/VR.h"
@@ -900,8 +900,8 @@ namespace Hooks
900900
if (globals::features::lightLimitFix.loaded && !globals::features::lightLimitFix.CheckParticleLights(a_pass, a_technique))
901901
return;
902902

903-
if (globals::features::interiorSunShadows.loaded)
904-
globals::features::interiorSunShadows.UpdateRasterStateCullMode(a_pass, a_technique);
903+
if (globals::features::interiorSun.loaded)
904+
globals::features::interiorSun.UpdateRasterStateCullMode(a_pass, a_technique);
905905

906906
func(a_pass, a_technique, a_alphaTest, a_renderFlags);
907907
}

src/TruePBR.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "TruePBR/BSLightingShaderMaterialPBR.h"
44
#include "TruePBR/BSLightingShaderMaterialPBRLandscape.h"
55

6-
#include "Features/InteriorSunShadows.h"
6+
#include "Features/InteriorSun.h"
77
#include "Hooks.h"
88
#include "ShaderCache.h"
99
#include "State.h"
@@ -675,7 +675,7 @@ struct BSLightingShaderProperty_GetRenderPasses
675675
return renderPasses;
676676
}
677677

678-
const auto issEnabledAndInteriorWithSun = globals::features::interiorSunShadows.loaded && globals::features::interiorSunShadows.isInteriorWithSun;
678+
const auto issEnabledAndInteriorWithSun = globals::features::interiorSun.loaded && globals::features::interiorSun.isInteriorWithSun;
679679

680680
bool isPbr = false;
681681

0 commit comments

Comments
 (0)