Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
573e758
feat(ssgi): cursed ssgi optimisations
doodlum Sep 20, 2025
161d250
chore: deferred composite missing thing??
doodlum Sep 20, 2025
0d28510
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Sep 20, 2025
2fae42e
fix: fix type
doodlum Sep 20, 2025
1725b95
fix: fix format of masks
doodlum Sep 20, 2025
a2b7972
fix: fixes
doodlum Sep 20, 2025
7027f28
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Sep 20, 2025
19a6efe
chore: add back cheese
doodlum Sep 20, 2025
a564f2f
Merge branch 'cursed-ssgi-2' of https://github.com/doodlum/skyrim-com…
doodlum Sep 20, 2025
b396341
fix: more fixes
doodlum Sep 20, 2025
60a51e8
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Sep 20, 2025
e3866ec
Update package/Shaders/DeferredCompositeCS.hlsl
doodlum Sep 21, 2025
6a5efa5
Update src/Deferred.cpp
doodlum Sep 21, 2025
65ca85d
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Sep 21, 2025
ddee46f
fix: fix masks nonsense
doodlum Sep 22, 2025
afb5165
feat: improved and simplified skylighting application
doodlum Sep 22, 2025
01db164
fix: fix compile error
doodlum Sep 22, 2025
2ed761e
fix: fix where skylighting is off but ssgi on
doodlum Sep 22, 2025
6e4ada4
chore: clean up forward path
doodlum Sep 22, 2025
3ede763
chore: what
doodlum Sep 22, 2025
d14b0f2
chore: clean up math
doodlum Sep 22, 2025
b62c9f7
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Sep 22, 2025
8e65ee1
fix: missing shader define
doodlum Sep 22, 2025
c358526
Merge branch 'cursed-ssgi-2' of https://github.com/doodlum/skyrim-com…
doodlum Sep 22, 2025
2d85322
fix: masks texture format
doodlum Sep 22, 2025
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
22 changes: 21 additions & 1 deletion features/Skylighting/Shaders/Skylighting/Skylighting.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Skylighting
{
#ifdef PSHADER
#if defined(PSHADER)
Texture3D<sh2> SkylightingProbeArray : register(t50);
Texture2DArray<float3> stbn_vec3_2Dx1D_128x128x64 : register(t51);
#endif
Expand All @@ -35,6 +35,26 @@ namespace Skylighting
return lerp(params.MinSpecularVisibility, 1.0, saturate(visibility));
}

#if defined(PSHADER)
void applySkylighting(inout float3 diffuseColor, inout float3 directionalAmbientColor, float skylightingDiffuse)
{
float maxScale = 1.0;
if (directionalAmbientColor.x > 0.0)
maxScale = min(maxScale, diffuseColor.x / directionalAmbientColor.x);
if (directionalAmbientColor.y > 0.0)
maxScale = min(maxScale, diffuseColor.y / directionalAmbientColor.y);
if (directionalAmbientColor.z > 0.0)
maxScale = min(maxScale, diffuseColor.z / directionalAmbientColor.z);
directionalAmbientColor *= maxScale;

diffuseColor = max(0.0, diffuseColor - directionalAmbientColor);

directionalAmbientColor = Color::LinearToGamma(Color::GammaToLinear(directionalAmbientColor) * skylightingDiffuse);

diffuseColor += directionalAmbientColor;
}
#endif

sh2 sample(SharedData::SkylightingSettings params, Texture3D<sh2> probeArray, Texture2DArray<float3> blueNoise, float2 screenPosition, float3 positionMS, float3 normalWS)
{
const static sh2 unitSH = float4(sqrt(4 * Math::PI), 0, 0, 0);
Expand Down
147 changes: 0 additions & 147 deletions package/Shaders/AmbientCompositeCS.hlsl

This file was deleted.

83 changes: 73 additions & 10 deletions package/Shaders/DeferredCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Texture2D<float3> SpecularTexture : register(t0);
Texture2D<unorm float3> AlbedoTexture : register(t1);
Texture2D<unorm float3> NormalRoughnessTexture : register(t2);
Texture2D<unorm float3> MasksTexture : register(t3);
Texture2D<float3> MasksTexture : register(t3);

RWTexture2D<float4> MainRW : register(u0);
RWTexture2D<float4> NormalTAAMaskSpecularMaskRW : register(u1);
Expand Down Expand Up @@ -39,6 +39,17 @@ Texture2D<float4> SsgiYTexture : register(t11);
Texture2D<float4> SsgiCoCgTexture : register(t12);
Texture2D<float4> SsgiSpecularTexture : register(t13);

void SampleSSGI(uint2 pixCoord, float3 normalWS, out float ao, out float3 il)
{
ao = 1 - SsgiAoTexture[pixCoord];
float4 ssgiIlYSh = SsgiYTexture[pixCoord];
// without ZH hallucination
// float ssgiIlY = SphericalHarmonics::FuncProductIntegral(ssgiIlYSh, SphericalHarmonics::EvaluateCosineLobe(normalWS));
float ssgiIlY = SphericalHarmonics::SHHallucinateZH3Irradiance(ssgiIlYSh, normalWS);
float2 ssgiIlCoCg = SsgiCoCgTexture[pixCoord];
il = max(0, Color::YCoCgToRGB(float3(ssgiIlY, ssgiIlCoCg)));
}

void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il, in float3 normal, in float3 view)
{
// https://www.iryoku.com/stare-into-the-future/
Expand Down Expand Up @@ -95,21 +106,73 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il, i

float glossiness = normalGlossiness.z;

float3 color = Color::GammaToLinear(diffuseColor) + specularColor;
float3 linDiffuseColor = Color::GammaToLinear(diffuseColor);
float3 normalWS = normalize(mul(FrameBuffer::CameraViewInverse[eyeIndex], float4(normalVS, 0)).xyz);

#if defined(DYNAMIC_CUBEMAPS)
#if defined(SSGI)
# if defined(VR)
float3 uvF = float3((dispatchID.xy + 0.5) * SharedData::BufferDim.zw, depth); // calculate high precision uv of initial eye
float3 uv2 = Stereo::ConvertStereoUVToOtherEyeStereoUV(uvF, eyeIndex, false); // calculate other eye uv
float3 uv1Mono = Stereo::ConvertFromStereoUV(uvF, eyeIndex);
float3 uv2Mono = Stereo::ConvertFromStereoUV(uv2, (1 - eyeIndex));
uint2 pixCoord2 = (uint2)(uv2.xy / SharedData::BufferDim.zw - 0.5);
# endif
Comment thread
doodlum marked this conversation as resolved.

float3 reflectance = ReflectanceTexture[dispatchID.xy];
float ssgiAo;
float3 ssgiIl;
SampleSSGI(dispatchID.xy, normalWS, ssgiAo, ssgiIl);

if (reflectance.x > 0.0 || reflectance.y > 0.0 || reflectance.z > 0.0) {
float3 normalWS = normalize(mul(FrameBuffer::CameraViewInverse[eyeIndex], float4(normalVS, 0)).xyz);
# if defined(VR)
float ssgiAo2;
float3 ssgiIl2;
SampleSSGI(pixCoord2, normalWS, ssgiAo2, ssgiIl2);

float4 ssgiMixed = Stereo::BlendEyeColors(uv1Mono, float4(ssgiIl, ssgiAo), uv2Mono, float4(ssgiIl2, ssgiAo2));
ssgiAo = ssgiMixed.a;
ssgiIl = ssgiMixed.rgb;
# endif

float3 directionalAmbientColor = max(0, mul(SharedData::DirectionalAmbient, float4(normalWS, 1.0)));
directionalAmbientColor *= albedo;

directionalAmbientColor = Color::RGBToYCoCg(directionalAmbientColor);
directionalAmbientColor.x = MasksTexture[dispatchID.xy].z;
directionalAmbientColor = Color::YCoCgToRGB(directionalAmbientColor);
directionalAmbientColor = max(0, directionalAmbientColor);

float wetnessMask = MasksTexture[dispatchID.xy].z * 2.0 - 1.0;
float maxScale = 1.0;
if (directionalAmbientColor.x > 0.0)
maxScale = min(maxScale, diffuseColor.x / directionalAmbientColor.x);
if (directionalAmbientColor.y > 0.0)
maxScale = min(maxScale, diffuseColor.y / directionalAmbientColor.y);
if (directionalAmbientColor.z > 0.0)
maxScale = min(maxScale, diffuseColor.z / directionalAmbientColor.z);
directionalAmbientColor *= maxScale;

normalWS.z = wetnessMask;
float xyLength = sqrt(max(0.0, 1.0 - wetnessMask * wetnessMask));
normalWS.xy = normalize(normalWS.xy) * xyLength;
diffuseColor = max(0.0, diffuseColor - directionalAmbientColor);

linDiffuseColor = Color::GammaToLinear(diffuseColor);
# if defined(INTERIOR)
linDiffuseColor *= ssgiAo;
# else
linDiffuseColor *= sqrt(ssgiAo);
# endif
diffuseColor = Color::LinearToGamma(linDiffuseColor);

diffuseColor += Color::LinearToGamma(Color::GammaToLinear(directionalAmbientColor) * ssgiAo);

linDiffuseColor = Color::GammaToLinear(diffuseColor);

linDiffuseColor += ssgiIl * Color::GammaToLinear(albedo);
#endif

float3 color = linDiffuseColor + specularColor;

#if defined(DYNAMIC_CUBEMAPS)

float3 reflectance = ReflectanceTexture[dispatchID.xy];

if (reflectance.x > 0.0 || reflectance.y > 0.0 || reflectance.z > 0.0) {
float3 V = normalize(positionWS.xyz);
float3 R = reflect(V, normalWS);

Expand Down
2 changes: 0 additions & 2 deletions package/Shaders/DistantTree.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ PS_OUTPUT main(PS_INPUT input)
float3 ddy = ddy_coarse(input.WorldPosition.xyz);
float3 normal = -normalize(cross(ddx, ddy));

# if !defined(SSGI)
float3 directionalAmbientColor = max(0, mul(SharedData::DirectionalAmbient, float4(normal, 1.0)));
# if defined(IBL)
if (SharedData::iblSettings.EnableDiffuseIBL) {
Expand All @@ -244,7 +243,6 @@ PS_OUTPUT main(PS_INPUT input)
}
# endif
diffuseColor += directionalAmbientColor;
# endif

psout.Diffuse.xyz = diffuseColor * baseColor.xyz;
psout.Diffuse.w = 1;
Expand Down
3 changes: 1 addition & 2 deletions package/Shaders/Effect.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,7 @@ struct PS_OUTPUT
# elif defined(NORMALS)
float4 NormalGlossiness : SV_Target2;
# endif
# if defined(MULTBLEND) || defined(MULTBLEND_DECAL)
float4 Albedo : SV_Target3;
# endif
float4 Specular : SV_Target4;
float4 Reflectance : SV_Target5;
float4 Masks : SV_Target6;
Expand Down Expand Up @@ -861,6 +859,7 @@ PS_OUTPUT main(PS_INPUT input)
psout.Reflectance = float4(psout.Diffuse.xyz, finalColor.w);
psout.Masks = float4(Color::RGBToLuminance(psout.Diffuse.xyz).xxx, finalColor.w);
#else
psout.Albedo = float4(psout.Diffuse.xyz, finalColor.w);
psout.Specular = float4(0, 0, 0, finalColor.w);
psout.Reflectance = float4(0, 0, 0, finalColor.w);
psout.Masks = float4(0, 0, 0, finalColor.w);
Expand Down
Loading