Skip to content

Commit e91f159

Browse files
fix(ibl): add ibl to reflection normalization (#1528)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 62834b8 commit e91f159

File tree

4 files changed

+54
-8
lines changed

4 files changed

+54
-8
lines changed

features/IBL/Shaders/IBL/IBL.hlsli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
namespace ImageBasedLighting
1111
{
12-
#if defined(IBL_AMBIENTCOMPOSITE)
13-
Texture2D<sh2> DiffuseIBLTexture : register(t8);
14-
Texture2D<sh2> DiffuseSkyIBLTexture : register(t9);
12+
#if defined(IBL_DEFERRED)
13+
Texture2D<sh2> DiffuseIBLTexture : register(t14);
14+
Texture2D<sh2> DiffuseSkyIBLTexture : register(t15);
1515
#else
1616
Texture2D<sh2> DiffuseIBLTexture : register(t76);
1717
Texture2D<sh2> DiffuseSkyIBLTexture : register(t77);
@@ -40,7 +40,7 @@ namespace ImageBasedLighting
4040
return float3(colorR, colorG, colorB) / Math::PI;
4141
}
4242

43-
#if defined(SKYLIGHTING)
43+
#if defined(SKYLIGHTING) && !defined(INTERIOR)
4444
float3 GetIBLColor(float3 rayDir, float skylighting)
4545
#else
4646
float3 GetIBLColor(float3 rayDir)

package/Shaders/DeferredCompositeCS.hlsl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il, i
7272
}
7373
#endif
7474

75+
#if defined(IBL)
76+
# if !defined(DYNAMIC_CUBEMAPS)
77+
# undef IBL
78+
# else
79+
# define IBL_DEFERRED
80+
# include "IBL/IBL.hlsli"
81+
# endif
82+
#endif
83+
7584
[numthreads(8, 8, 1)] void main(uint3 dispatchID : SV_DispatchThreadID) {
7685
// Early exit if dispatch thread is outside screen bounds
7786
if (any(dispatchID.xy >= uint2(SharedData::BufferDim.xy)))
@@ -188,6 +197,15 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il, i
188197

189198
float specularIrradianceLuminance = Color::RGBToLuminance(Color::GammaToLinear(EnvTexture.SampleLevel(LinearSampler, R, 15)));
190199

200+
# if defined(IBL)
201+
float3 iblColor = 0;
202+
if (SharedData::iblSettings.EnableDiffuseIBL && SharedData::iblSettings.EnableInterior) {
203+
directionalAmbientColorSpecular *= SharedData::iblSettings.DALCAmount;
204+
iblColor += Color::Saturation(ImageBasedLighting::GetIBLColor(-R), SharedData::iblSettings.IBLSaturation) * SharedData::iblSettings.DiffuseIBLScale;
205+
float iblColorLuminance = Color::RGBToLuminance(iblColor);
206+
directionalAmbientColorSpecular += iblColorLuminance;
207+
}
208+
# endif
191209
specularIrradiance = (specularIrradiance / max(specularIrradianceLuminance, 0.001)) * directionalAmbientColorSpecular;
192210

193211
finalIrradiance += specularIrradiance;
@@ -204,6 +222,15 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il, i
204222
skylightingSpecular = Skylighting::mixSpecular(SharedData::skylightingSettings, skylightingSpecular);
205223

206224
directionalAmbientColorSpecular *= skylightingSpecular;
225+
# if defined(IBL)
226+
float3 iblColor = 0;
227+
if (SharedData::iblSettings.EnableDiffuseIBL) {
228+
directionalAmbientColorSpecular *= SharedData::iblSettings.DALCAmount;
229+
iblColor += Color::Saturation(ImageBasedLighting::GetIBLColor(-R, skylightingSpecular), SharedData::iblSettings.IBLSaturation) * SharedData::iblSettings.DiffuseIBLScale;
230+
float iblColorLuminance = Color::RGBToLuminance(iblColor);
231+
directionalAmbientColorSpecular += iblColorLuminance;
232+
}
233+
# endif
207234

208235
float3 specularIrradiance = 1;
209236

@@ -227,6 +254,15 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il, i
227254

228255
finalIrradiance = lerp(specularIrradiance, specularIrradianceReflections, skylightingSpecular);
229256
# else
257+
# if defined(IBL)
258+
float3 iblColor = 0;
259+
if (SharedData::iblSettings.EnableDiffuseIBL) {
260+
directionalAmbientColorSpecular *= SharedData::iblSettings.DALCAmount;
261+
iblColor += Color::Saturation(ImageBasedLighting::GetIBLColor(-R), SharedData::iblSettings.IBLSaturation) * SharedData::iblSettings.DiffuseIBLScale;
262+
float iblColorLuminance = Color::RGBToLuminance(iblColor);
263+
directionalAmbientColorSpecular += iblColorLuminance;
264+
}
265+
# endif
230266
float3 specularIrradianceReflections = Color::GammaToLinear(EnvReflectionsTexture.SampleLevel(LinearSampler, R, level));
231267

232268
float specularIrradianceReflectionsLuminance = Color::RGBToLuminance(Color::GammaToLinear(EnvReflectionsTexture.SampleLevel(LinearSampler, R, 15)));

package/Shaders/Lighting.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,8 +2746,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace)
27462746
# else
27472747
iblColor += Color::Saturation(ImageBasedLighting::GetIBLColor(-ambientNormal), SharedData::iblSettings.IBLSaturation) * SharedData::iblSettings.DiffuseIBLScale;
27482748
# endif
2749-
iblColor = Color::LinearToGamma(iblColor);
2750-
directionalAmbientColor += iblColor;
2749+
iblColor = Color::LinearToGamma(iblColor);
2750+
directionalAmbientColor += iblColor;
27512751
}
27522752
}
27532753
# endif

src/Deferred.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,13 @@ void Deferred::DeferredPasses()
433433

434434
auto& terrainBlending = globals::features::terrainBlending;
435435

436+
auto& ibl = globals::features::ibl;
437+
436438
// Deferred Composite
437439
{
438440
TracyD3D11Zone(globals::state->tracyCtx, "Deferred Composite");
439441

440-
ID3D11ShaderResourceView* srvs[14]{
442+
ID3D11ShaderResourceView* srvs[16]{
441443
specular.SRV,
442444
albedo.SRV,
443445
normalRoughness.SRV,
@@ -452,6 +454,8 @@ void Deferred::DeferredPasses()
452454
ssgi_hq_spec ? nullptr : ssgi_y,
453455
ssgi_hq_spec ? nullptr : ssgi_cocg,
454456
ssgi_hq_spec ? ssgi_gi_spec : nullptr,
457+
ibl.loaded ? ibl.diffuseIBLTexture->srv.get() : nullptr,
458+
ibl.loaded ? ibl.diffuseSkyIBLTexture->srv.get() : nullptr,
455459
};
456460

457461
if (dynamicCubemaps.loaded)
@@ -470,7 +474,7 @@ void Deferred::DeferredPasses()
470474

471475
// Clear
472476
{
473-
ID3D11ShaderResourceView* views[14]{ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
477+
ID3D11ShaderResourceView* views[16]{ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
474478
context->CSSetShaderResources(0, ARRAYSIZE(views), views);
475479

476480
ID3D11UnorderedAccessView* uavs[3]{ nullptr, nullptr, nullptr };
@@ -635,6 +639,9 @@ ID3D11ComputeShader* Deferred::GetComputeMainComposite()
635639
if (globals::features::screenSpaceGI.loaded)
636640
defines.push_back({ "SSGI", nullptr });
637641

642+
if (globals::features::ibl.loaded)
643+
defines.push_back({ "IBL", nullptr });
644+
638645
if (REL::Module::IsVR())
639646
defines.push_back({ "FRAMEBUFFER", nullptr });
640647

@@ -657,6 +664,9 @@ ID3D11ComputeShader* Deferred::GetComputeMainCompositeInterior()
657664
if (globals::features::screenSpaceGI.loaded)
658665
defines.push_back({ "SSGI", nullptr });
659666

667+
if (globals::features::ibl.loaded)
668+
defines.push_back({ "IBL", nullptr });
669+
660670
if (REL::Module::IsVR())
661671
defines.push_back({ "FRAMEBUFFER", nullptr });
662672

0 commit comments

Comments
 (0)