Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/Interior Sun/Shaders/Features/InteriorSun.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Info]
Version = 1-0-0
Version = 1-0-1

[Nexus]
autoupload = false
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Info]
Version = 2-0-0
Version = 2-0-1

[Nexus]
autoupload = false
22 changes: 18 additions & 4 deletions package/Shaders/Common/ShadowSampling.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ namespace ShadowSampling
static const float3 LightingSampleNormal = float3(0, 0, 1);
static const float3 ImageBasedLightingNormal = float3(0, 0, -1);

bool HasDirectionalShadows()
{
return SharedData::HasDirectionalShadows;
}

float GetWorldShadow(float3 positionWS, float3 offset, uint eyeIndex)
{
if (SharedData::InInterior || SharedData::HideSky || SharedData::InMapMenu)
Expand Down Expand Up @@ -101,17 +106,26 @@ namespace ShadowSampling
worldShadow *= rcpSampleCount;

#if defined(VOLUMETRIC_SHADOWS)
float vsmSurfaceShadow;
float shadow = VolumetricShadows::GetVSMShadow3D(startPosition, endPosition, noise, sampleCount, eyeIndex, vsmSurfaceShadow);
surfaceShadow *= vsmSurfaceShadow;
return worldShadow * shadow;
if (HasDirectionalShadows()) {
float vsmSurfaceShadow;
float shadow = VolumetricShadows::GetVSMShadow3D(startPosition, endPosition, noise, sampleCount, eyeIndex, vsmSurfaceShadow);
surfaceShadow *= vsmSurfaceShadow;
return worldShadow * shadow;
}
#else
return worldShadow;
#endif

return worldShadow;
}

float GetLightingShadow(float3 worldPosition, uint eyeIndex, out float detailedShadow)
{
if (!HasDirectionalShadows()) {
detailedShadow = 1.0;
return 1.0;
}

#if defined(VOLUMETRIC_SHADOWS)
float shadow = VolumetricShadows::GetVSMShadow2D(worldPosition, eyeIndex, detailedShadow);
return shadow;
Expand Down
4 changes: 3 additions & 1 deletion package/Shaders/Common/SharedData.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ namespace SharedData
float Timer;
uint FrameCount;
uint FrameCountAlwaysActive;
bool InInterior; // If the area lacks a directional shadow light e.g. the sun or moon
bool InInterior; // If the current cell is an interior
bool HasDirectionalShadows;
bool InMapMenu; // If the world/local map is open (note that the renderer is still deferred here)
bool HideSky; // HideSky flag in WorldSpace, e.g. Blackreach
float MipBias; // Offset to mip level for TAA sharpness
float WaterSystemHeight; // TES::GetWaterHeight at eye-0 in camera-relative Z; -FLT_MAX when no water body found (VR only)
float3 pad0;
float4 AmbientSHR;
float4 AmbientSHG;
float4 AmbientSHB;
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/Effect.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ float3 GetLightingColor(float3 msPosition, float3 worldPosition, float2 screenPo

const bool inWorld = (Permutation::ExtraShaderDescriptor & Permutation::ExtraFlags::InWorld);

if (inWorld && !SharedData::InInterior)
if (inWorld && ShadowSampling::HasDirectionalShadows())
dirShadow = ShadowSampling::Get3DFilteredShadow(worldPosition.xyz, viewDirection, screenPosition, eyeIndex, unusedSurfaceShadow);

shadowVariance = 1.0 - sqrt(saturate(fwidth(dirShadow)));
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -2496,7 +2496,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace)
float dirVSMDetailedShadow = 1.0;

# if defined(VOLUMETRIC_SHADOWS)
if (inWorld && !inReflection && !SharedData::InInterior)
if (inWorld && !inReflection && ShadowSampling::HasDirectionalShadows())
dirSoftShadow = ShadowSampling::GetLightingShadow(input.WorldPosition.xyz, eyeIndex, dirVSMDetailedShadow);
# endif

Expand Down
3 changes: 2 additions & 1 deletion src/Features/InteriorSun.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct InteriorSun : Feature
};

static bool IsInteriorWithSun(const RE::TESObjectCELL* cell);
bool IsActiveInteriorSun() const { return loaded && isInteriorWithSun.load(); }
virtual bool IsCore() const override { return true; };

private:
Expand Down Expand Up @@ -128,4 +129,4 @@ struct InteriorSun : Feature
void PopulateReplacementJobArrays(RE::TESObjectCELL* cell, const RE::NiPointer<RE::BSPortalGraph>& portalGraph, const RE::BSShadowDirectionalLight* dirLight, RE::BSTArray<RE::BSTArray<RE::NiPointer<RE::NiAVObject>>>& jobArrays);

static void SetShadowDistance(bool inInterior);
};
};
14 changes: 12 additions & 2 deletions src/Features/VolumetricShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ void VolumetricShadows::CopyShadowLightData()
auto context = globals::d3d::context;

{
if (!globals::state->HasDirectionalShadows()) {
SetSharedShadowMapSRV(context, nullptr);
return;
}

context->PSGetShaderResources(4, 1, &shadowView);

// Downsample shadow texture array to fixed 512x512 (mip1: 256x256)
Expand Down Expand Up @@ -283,15 +288,20 @@ void VolumetricShadows::CopyShadowLightData()
}
}

ID3D11ShaderResourceView* srv = shadowView ? (shadowCopySRV ? shadowCopySRV : shadowView) : nullptr;
context->PSSetShaderResources(18, 1, &srv);
auto* srv = shadowView ? (shadowCopySRV ? shadowCopySRV : shadowView) : nullptr;
SetSharedShadowMapSRV(context, srv);

if (shadowView)
shadowView->Release();
shadowView = nullptr;
}
}

void VolumetricShadows::SetSharedShadowMapSRV(ID3D11DeviceContext* a_context, ID3D11ShaderResourceView* a_srv)
{
a_context->PSSetShaderResources(kSharedShadowMapShaderSlot, 1, &a_srv);
}

void VolumetricShadows::DrawSettings()
{
ImGui::SeparatorText("Debug");
Expand Down
5 changes: 5 additions & 0 deletions src/Features/VolumetricShadows.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct VolumetricShadows : Feature
virtual bool IsCore() const override { return true; }
virtual bool IsInMenu() const override { return true; }

static constexpr uint32_t kSharedShadowMapShaderSlot = 18;

virtual std::pair<std::string, std::vector<std::string>> GetFeatureSummary() override
{
return {
Expand Down Expand Up @@ -67,4 +69,7 @@ struct VolumetricShadows : Feature
virtual bool SupportsVR() override { return true; }

virtual void PostPostLoad() override;

private:
static void SetSharedShadowMapSRV(ID3D11DeviceContext* a_context, ID3D11ShaderResourceView* a_srv);
};
7 changes: 7 additions & 0 deletions src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "FeatureIssues.h"
#include "Features/CloudShadows.h"
#include "Features/HDRDisplay.h"
#include "Features/InteriorSun.h"
#include "Features/PerformanceOverlay.h"
#include "Features/TerrainBlending.h"
#include "Features/TerrainHelper.h"
Expand Down Expand Up @@ -962,6 +963,7 @@ void State::UpdateSharedData([[maybe_unused]] bool a_inWorld, [[maybe_unused]] b
}

data.InInterior = Util::IsInterior();
data.HasDirectionalShadows = HasDirectionalShadows();

if (globals::game::sky)
data.HideSky = globals::game::sky->flags.any(RE::Sky::Flags::kHideSky);
Expand Down Expand Up @@ -1082,6 +1084,11 @@ void State::LoadTheme()
}
}

bool State::HasDirectionalShadows() const
{
return !Util::IsInterior() || globals::features::interiorSun.IsActiveInteriorSun();
}
Comment thread
Dlizzio marked this conversation as resolved.

void State::SaveTheme()
{
// SelectedThemePreset is now persisted via SettingsUser.json (State::Save)
Expand Down
3 changes: 3 additions & 0 deletions src/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class State

void UpdateSharedData(bool a_inWorld, bool a_prepass);
void UpdateSkyShaderPermutation(RE::BSRenderPass* a_pass);
bool HasDirectionalShadows() const;

struct PermutationCB
{
Expand Down Expand Up @@ -246,10 +247,12 @@ class State
uint FrameCount;
uint FrameCountAlwaysActive;
uint InInterior;
uint HasDirectionalShadows;
uint InMapMenu;
uint HideSky;
float MipBias;
float WaterSystemHeight; // TES::GetWaterHeight at eye-0 in camera-relative Z; -NI_INFINITY when no water body found (VR only)
float3 pad0;
float4 AmbientSHR;
float4 AmbientSHG;
float4 AmbientSHB;
Expand Down
Loading