Skip to content

Commit

Permalink
fix: glowmap brightness (#439)
Browse files Browse the repository at this point in the history
* fix: glowmap brightness

* fix: effect shadows not working
  • Loading branch information
doodlum authored Aug 20, 2024
1 parent efe0460 commit bebb308
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
3 changes: 2 additions & 1 deletion package/Shaders/Common/Permutation.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
#define _GrayscaleToAlpha (1 << 20)
#define _IgnoreTexAlpha (1 << 21)

#define _InWorld (1 << 24)
#define _InWorld (1 << 0)

cbuffer PerShader : register(b4)
{
uint VertexShaderDescriptor;
uint PixelShaderDescriptor;
uint ExtraShaderDescriptor;
};
6 changes: 3 additions & 3 deletions package/Shaders/Effect.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ float3 GetLightingColor(float3 msPosition, float3 worldPosition, float4 screenPo
float4 lightFadeMul = 1.0.xxxx - saturate(PLightingRadiusInverseSquared * lightDistanceSquared);

float3 color = DLightColor.xyz;
if (!Interior && (PixelShaderDescriptor & _InWorld)) {
if (!Interior && (ExtraShaderDescriptor & _InWorld)) {
float3 viewDirection = normalize(worldPosition);
color = DirLightColorShared * GetEffectShadow(worldPosition, viewDirection, screenPosition, eyeIndex);

Expand Down Expand Up @@ -606,10 +606,10 @@ PS_OUTPUT main(PS_INPUT input)
if (LightingInfluence.x > 0.0) {
float3 viewPosition = mul(CameraView[eyeIndex], float4(input.WorldPosition.xyz, 1)).xyz;
float2 screenUV = ViewToUV(viewPosition, true, eyeIndex);
bool mainPass = PixelShaderDescriptor & _InWorld;
bool inWorld = ExtraShaderDescriptor & _InWorld;

uint clusterIndex = 0;
if (mainPass && LightLimitFix::GetClusterIndex(screenUV, viewPosition.z, clusterIndex)) {
if (inWorld && LightLimitFix::GetClusterIndex(screenUV, viewPosition.z, clusterIndex)) {
lightCount = lightGrid[clusterIndex].lightCount;
uint lightOffset = lightGrid[clusterIndex].offset;
[loop] for (uint i = 0; i < lightCount; i++)
Expand Down
23 changes: 11 additions & 12 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
screenNoise3D = float3(r * sin_theta * sincos_phi.x, r * sin_theta * sincos_phi.y, r * cos_theta);
}

// If InWorld or first-person
bool mainPass = PixelShaderDescriptor & _InWorld;
bool inWorld = ExtraShaderDescriptor & _InWorld;

# if defined(TERRAIN_BLENDING)
float depthSampled = TerrainBlending::GetTerrainOffsetDepth(screenUV, eyeIndex);
Expand Down Expand Up @@ -1761,7 +1760,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# if defined(DEFERRED)
sh2 skylightingSH = Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMSSkylight, worldSpaceNormal);
# else
sh2 skylightingSH = mainPass ? Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMSSkylight, worldSpaceNormal) : float4(sqrt(4.0 * shPI), 0, 0, 0);
sh2 skylightingSH = inWorld ? Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMSSkylight, worldSpaceNormal) : float4(sqrt(4.0 * shPI), 0, 0, 0);
# endif

# endif
Expand All @@ -1787,9 +1786,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float minWetnessAngle = 0;
minWetnessAngle = saturate(max(minWetnessValue, worldSpaceNormal.z));
# if defined(SKYLIGHTING)
float wetnessOcclusion = mainPass ? pow(saturate(shUnproject(skylightingSH, float3(0, 0, 1))), 2) : 0;
float wetnessOcclusion = inWorld ? pow(saturate(shUnproject(skylightingSH, float3(0, 0, 1))), 2) : 0;
# else
float wetnessOcclusion = mainPass;
float wetnessOcclusion = inWorld;
# endif

float4 raindropInfo = float4(0, 0, 1, 0);
Expand Down Expand Up @@ -1878,7 +1877,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
dirLightColorMultiplier *= shadowColor.x;
}
# if !defined(DEFERRED)
else if (!Interior && mainPass) {
else if (!Interior && inWorld) {
dirLightColorMultiplier *= GetLightingShadow(screenNoise, input.WorldPosition, eyeIndex);
}
# endif
Expand All @@ -1903,16 +1902,16 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if defined(DEFERRED)
# if defined(SOFT_LIGHTING) || defined(BACK_LIGHTING) || defined(RIM_LIGHTING)
bool extraDirShadows = !inDirShadow && mainPass;
bool extraDirShadows = !inDirShadow && inWorld;
# else
// If lighting cannot hit the backface of the object, do not render shadows
bool extraDirShadows = !inDirShadow && dirLightAngle > 0.0 && mainPass;
bool extraDirShadows = !inDirShadow && dirLightAngle > 0.0 && inWorld;
# endif
# else
# if defined(SOFT_LIGHTING) || defined(BACK_LIGHTING) || defined(RIM_LIGHTING)
bool extraDirShadows = !inDirShadow && mainPass;
bool extraDirShadows = !inDirShadow && inWorld;
# else
bool extraDirShadows = !inDirShadow && dirLightAngle > 0.0 && mainPass;
bool extraDirShadows = !inDirShadow && dirLightAngle > 0.0 && inWorld;
# endif
# endif

Expand Down Expand Up @@ -2100,7 +2099,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
uint totalLightCount = strictLights[0].NumStrictLights;
uint clusterIndex = 0;
uint lightOffset = 0;
if (mainPass && LightLimitFix::GetClusterIndex(screenUV, viewPosition.z, clusterIndex)) {
if (inWorld && LightLimitFix::GetClusterIndex(screenUV, viewPosition.z, clusterIndex)) {
numClusteredLights = lightGrid[clusterIndex].lightCount;
totalLightCount += numClusteredLights;
lightOffset = lightGrid[clusterIndex].offset;
Expand Down Expand Up @@ -2140,7 +2139,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float lightAngle = dot(worldSpaceNormal.xyz, normalizedLightDirection.xyz);

float contactShadow = 1;
[branch] if (mainPass && !FrameParams.z && lightLimitFixSettings.EnableContactShadows && shadowComponent != 0.0 && lightAngle > 0.0)
[branch] if (inWorld && !FrameParams.z && lightLimitFixSettings.EnableContactShadows && shadowComponent != 0.0 && lightAngle > 0.0)
{
float3 normalizedLightDirectionVS = normalize(light.positionVS[eyeIndex].xyz - viewPosition.xyz);
contactShadow = LightLimitFix::ContactShadows(viewPosition, screenNoise, screenNoise3D, normalizedLightDirectionVS, contactShadowSteps, eyeIndex);
Expand Down
13 changes: 6 additions & 7 deletions src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

#include "VariableRateShading.h"

enum class PermutationFlags : uint32_t
{
InWorld = 1 << 24,
};

void State::Draw()
{
const auto& shaderCache = SIE::ShaderCache::Instance();
Expand Down Expand Up @@ -49,22 +44,26 @@ void State::Draw()
// Only check against non-shader bits
currentPixelDescriptor &= ~modifiedPixelDescriptor;

currentExtraDescriptor = 0;

if (auto accumulator = RE::BSGraphics::BSShaderAccumulator::GetCurrentAccumulator()) {
// Set an unused bit to indicate if we are rendering an object in the main rendering pass
if (accumulator->GetRuntimeData().activeShadowSceneNode == RE::BSShaderManager::State::GetSingleton().shadowSceneNode[0]) {
currentPixelDescriptor |= (uint32_t)PermutationFlags::InWorld;
currentExtraDescriptor |= (uint32_t)ExtraShaderDescriptors::InWorld;
}
}

if (currentPixelDescriptor != lastPixelDescriptor) {
if (currentPixelDescriptor != lastPixelDescriptor || currentExtraDescriptor != lastExtraDescriptor) {
PermutationCB data{};
data.VertexShaderDescriptor = currentVertexDescriptor;
data.PixelShaderDescriptor = currentPixelDescriptor;
data.ExtraShaderDescriptor = currentExtraDescriptor;

permutationCB->Update(data);

lastVertexDescriptor = currentVertexDescriptor;
lastPixelDescriptor = currentPixelDescriptor;
lastExtraDescriptor = currentExtraDescriptor;
}

static Util::FrameChecker frameChecker;
Expand Down
10 changes: 9 additions & 1 deletion src/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,22 @@ class State
uint modifiedPixelDescriptor = 0;
uint lastModifiedVertexDescriptor = 0;
uint lastModifiedPixelDescriptor = 0;
uint currentExtraDescriptor = 0;
uint lastExtraDescriptor = 0;

enum class ExtraShaderDescriptors : uint32_t
{
InWorld = 1 << 0,
};

void UpdateSharedData();

struct alignas(16) PermutationCB
{
uint VertexShaderDescriptor;
uint PixelShaderDescriptor;
uint pad0[2];
uint ExtraShaderDescriptor;
uint pad0[1];
};

ConstantBuffer* permutationCB = nullptr;
Expand Down

0 comments on commit bebb308

Please sign in to comment.