Skip to content

Commit bab3d24

Browse files
committed
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
2 parents afd417f + 527793f commit bab3d24

File tree

12 files changed

+96
-16
lines changed

12 files changed

+96
-16
lines changed

features/IBL/Shaders/IBL/IBL.hlsli

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "Common/Color.hlsli"
12
#include "Common/Math.hlsli"
23
#include "Common/Random.hlsli"
34
#include "Common/SharedData.hlsli"
@@ -20,6 +21,23 @@ namespace ImageBasedLighting
2021
float colorR = SphericalHarmonics::SHHallucinateZH3Irradiance(shR, rayDir);
2122
float colorG = SphericalHarmonics::SHHallucinateZH3Irradiance(shG, rayDir);
2223
float colorB = SphericalHarmonics::SHHallucinateZH3Irradiance(shB, rayDir);
23-
return float3(colorR, colorG, colorB);
24+
return float3(colorR, colorG, colorB) / Math::PI;
25+
}
26+
27+
float3 GetFogIBLColor(float3 fogColor)
28+
{
29+
float3 directionalAmbientColor = max(0, mul(SharedData::DirectionalAmbient, float4(float3(0, 0, 0), 1.0))).xyz;
30+
float3 iblColor = directionalAmbientColor * SharedData::iblSettings.DALCAmount + Color::Saturation(GetDiffuseIBL(float3(0, 0, 0)), SharedData::iblSettings.IBLSaturation) * SharedData::iblSettings.DiffuseIBLScale;
31+
if (SharedData::iblSettings.PreserveFogLuminance) {
32+
const float fogLuminance = Color::RGBToLuminance2(fogColor);
33+
const float iblLuminance = Color::RGBToLuminance2(iblColor);
34+
if (iblLuminance > 0) {
35+
const float scale = fogLuminance / iblLuminance;
36+
iblColor *= scale;
37+
} else {
38+
iblColor = fogColor;
39+
}
40+
}
41+
return lerp(fogColor, iblColor, SharedData::iblSettings.FogAmount);
2442
}
2543
}
8.64 KB
Loading

package/Shaders/Common/SharedData.hlsli

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,13 @@ namespace SharedData
179179
struct IBLSettings
180180
{
181181
uint EnableDiffuseIBL;
182+
uint SampleUnderHorizonFromDynCube;
183+
uint PreserveFogLuminance;
184+
uint pad;
182185
float DiffuseIBLScale;
183186
float DALCAmount;
184187
float IBLSaturation;
185-
uint SampleUnderHorizonFromDynCube;
186-
uint3 pad;
188+
float FogAmount;
187189
};
188190

189191
struct ExtendedTranslucencySettings

package/Shaders/Effect.hlsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,13 @@ PS_OUTPUT main(PS_INPUT input)
793793
# elif defined(MULTBLEND) || defined(MULTBLEND_DECAL)
794794
float3 blendedColor = lerp(lightColor, 1.0.xxx, saturate(1.5 * input.FogParam.w).xxx);
795795
# else
796-
float3 blendedColor = lerp(lightColor, input.FogParam.xyz, input.FogParam.www);
796+
float3 fogColor = input.FogParam.xyz;
797+
# if defined(IBL)
798+
if (SharedData::iblSettings.EnableDiffuseIBL && !SharedData::InInterior) {
799+
fogColor = ImageBasedLighting::GetFogIBLColor(fogColor);
800+
}
801+
# endif
802+
float3 blendedColor = lerp(lightColor, fogColor, input.FogParam.www);
797803
# endif
798804
# else
799805
float3 blendedColor = lightColor.xyz;

package/Shaders/ISSAOComposite.hlsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ float SimplexNoise(float3 v)
125125
dot(p2, x2), dot(p3, x3)));
126126
}
127127

128+
# if defined(IBL)
129+
# include "IBL/IBL.hlsli"
130+
# endif
131+
128132
PS_OUTPUT main(PS_INPUT input)
129133
{
130134
PS_OUTPUT psout;
@@ -170,6 +174,11 @@ PS_OUTPUT main(PS_INPUT input)
170174
float fogDistanceFactor = (2 * CameraNearFar.x * CameraNearFar.y) / ((CameraNearFar.y + CameraNearFar.x) - (2 * (1.01 * depth - 0.01) - 1) * (CameraNearFar.y - CameraNearFar.x));
171175
float fogFactor = min(FogParam.w, pow(saturate(fogDistanceFactor * FogParam.y - FogParam.x), FogParam.z));
172176
float3 fogColor = lerp(FogNearColor.xyz, FogFarColor.xyz, fogFactor);
177+
# if defined(IBL)
178+
if (SharedData::iblSettings.EnableDiffuseIBL && !SharedData::InInterior) {
179+
fogColor = ImageBasedLighting::GetFogIBLColor(fogColor);
180+
}
181+
# endif
173182
if (depth < 0.999999) {
174183
composedColor.xyz = FogNearColor.w * lerp(composedColor.xyz, fogColor, fogFactor);
175184
}

package/Shaders/Lighting.hlsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,8 +3112,14 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace)
31123112

31133113
# if !defined(DEFERRED)
31143114
color.xyz = Color::LinearToGamma(Color::GammaToLinear(color.xyz) + specularColor);
3115+
float3 fogColor = input.FogParam.xyz;
3116+
# if defined(IBL)
3117+
if (SharedData::iblSettings.EnableDiffuseIBL && !SharedData::InInterior) {
3118+
fogColor = ImageBasedLighting::GetFogIBLColor(fogColor);
3119+
}
3120+
# endif
31153121
if (FrameBuffer::FrameParams.y && FrameBuffer::FrameParams.z)
3116-
color.xyz = lerp(color.xyz, input.FogParam.xyz, input.FogParam.w);
3122+
color.xyz = lerp(color.xyz, fogColor, input.FogParam.w);
31173123
# endif
31183124

31193125
# if defined(TESTCUBEMAP) && defined(ENVMAP) && defined(DYNAMIC_CUBEMAPS)

package/Shaders/Water.hlsl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,10 @@ float3 GetSunColor(float3 normal, float3 viewDirection)
984984
# include "InverseSquareLighting/InverseSquareLighting.hlsli"
985985
# endif
986986

987+
# if defined(IBL)
988+
# include "IBL/IBL.hlsli"
989+
# endif
990+
987991
PS_OUTPUT main(PS_INPUT input)
988992
{
989993
PS_OUTPUT psout;
@@ -1140,7 +1144,13 @@ PS_OUTPUT main(PS_INPUT input)
11401144
# if defined(VC)
11411145
float specularFraction = lerp(1, fresnel * diffuseOutput.refractionMul, distanceFactor);
11421146
float3 finalColorPreFog = lerp(diffuseColor, specularColor, specularFraction) + sunColor * depthControl.w;
1143-
float3 finalColor = lerp(finalColorPreFog, input.FogParam.xyz * PosAdjust[eyeIndex].w, input.FogParam.w);
1147+
float3 fogColor = input.FogParam.xyz;
1148+
# if defined(IBL)
1149+
if (SharedData::iblSettings.EnableDiffuseIBL && !SharedData::InInterior) {
1150+
fogColor = ImageBasedLighting::GetFogIBLColor(fogColor);
1151+
}
1152+
# endif
1153+
float3 finalColor = lerp(finalColorPreFog, fogColor * PosAdjust[eyeIndex].w, input.FogParam.w);
11441154
# if defined(WETNESS_EFFECTS) && defined(DEBUG_WETNESS_EFFECTS)
11451155
// DEBUG MODE: Override water color with debug visualization
11461156
float3 debugColor = WetnessEffects::GetDebugWetnessColorStandard(waterData.rippleInfo, 2.0, 3.0);
@@ -1152,12 +1162,23 @@ PS_OUTPUT main(PS_INPUT input)
11521162
# else
11531163
float specularFraction = lerp(1, fresnel, distanceFactor);
11541164
float3 finalColorPreFog = lerp(diffuseOutput.refractionDiffuseColor, specularColor, specularFraction) + sunColor * depthControl.w;
1155-
finalColorPreFog = lerp(finalColorPreFog, input.FogParam.xyz * PosAdjust[eyeIndex].w, input.FogParam.w);
1165+
float3 preFogColor = input.FogParam.xyz;
1166+
# if defined(IBL)
1167+
if (SharedData::iblSettings.EnableDiffuseIBL && !SharedData::InInterior) {
1168+
preFogColor = ImageBasedLighting::GetFogIBLColor(preFogColor);
1169+
}
1170+
# endif
1171+
finalColorPreFog = lerp(finalColorPreFog, preFogColor * PosAdjust[eyeIndex].w, input.FogParam.w);
11561172

11571173
float3 refractionColor = diffuseOutput.refractionColor;
11581174

11591175
float fogFactor = min(FogParam.w, pow(saturate(-diffuseOutput.depth * FogParam.y - FogParam.x), FogParam.z));
11601176
float3 fogColor = lerp(FogNearColor.xyz, FogFarColor.xyz, fogFactor);
1177+
# if defined(IBL)
1178+
if (SharedData::iblSettings.EnableDiffuseIBL && !SharedData::InInterior) {
1179+
fogColor = ImageBasedLighting::GetFogIBLColor(fogColor);
1180+
}
1181+
# endif
11611182
refractionColor = lerp(refractionColor, fogColor, fogFactor);
11621183

11631184
float3 finalColor = lerp(refractionColor, finalColorPreFog, diffuseOutput.refractionMul);

src/Features/IBL.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
99
IBL::Settings,
1010
EnableDiffuseIBL,
11+
SampleUnderHorizonFromDynCube,
12+
PreserveFogLuminance,
1113
DiffuseIBLScale,
1214
DALCAmount,
1315
IBLSaturation,
14-
SampleUnderHorizonFromDynCube)
16+
FogAmount)
1517

1618
void IBL::DrawSettings()
1719
{
1820
ImGui::Checkbox("Enable Diffuse IBL", (bool*)&settings.EnableDiffuseIBL);
1921
ImGui::SliderFloat("Diffuse IBL Scale", &settings.DiffuseIBLScale, 0.0f, 10.0f, "%.2f");
2022
ImGui::SliderFloat("Diffuse IBL Saturation", &settings.IBLSaturation, 0.0f, 2.0f, "%.2f");
2123
ImGui::SliderFloat("DALC Amount", &settings.DALCAmount, 0.0f, 1.0f, "%.2f");
24+
ImGui::SliderFloat("Fog Mix", &settings.FogAmount, 0.0f, 1.0f, "%.2f");
25+
ImGui::Checkbox("Preserve Fog Luminance", (bool*)&settings.PreserveFogLuminance);
2226
ImGui::Checkbox("[EXP] Sample Under Horizon From Dynamic Cubemaps", (bool*)&settings.SampleUnderHorizonFromDynCube);
2327
if (auto _tt = Util::HoverTooltipWrapper()) {
2428
ImGui::Text(

src/Features/IBL.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ struct IBL : Feature
4444
struct alignas(16) Settings
4545
{
4646
uint EnableDiffuseIBL = 1;
47-
float DiffuseIBLScale = 0.5f;
48-
float DALCAmount = 0.5f;
49-
float IBLSaturation = 0.65f;
5047
uint SampleUnderHorizonFromDynCube = 0;
51-
uint pad[3];
48+
uint PreserveFogLuminance = 0;
49+
uint pad;
50+
float DiffuseIBLScale = 1.0f;
51+
float DALCAmount = 0.33f;
52+
float IBLSaturation = 1.0f;
53+
float FogAmount = 0.0f;
5254
} settings;
5355

5456
ID3D11ComputeShader* GetDiffuseIBLCS();

src/Menu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Menu
9090
UIIcon water;
9191
UIIcon debug;
9292
UIIcon materials;
93+
UIIcon postProcessing;
9394
} uiIcons;
9495

9596
struct ThemeSettings

0 commit comments

Comments
 (0)