diff --git a/Source/Engine/Level/Actors/Sky.cpp b/Source/Engine/Level/Actors/Sky.cpp
index 2e1d46161..1f7a4b33e 100644
--- a/Source/Engine/Level/Actors/Sky.cpp
+++ b/Source/Engine/Level/Actors/Sky.cpp
@@ -16,6 +16,9 @@
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Level/Scene/SceneRendering.h"
+#if USE_EDITOR
+#include "Engine/Renderer/Lightmaps.h"
+#endif
GPU_CB_STRUCT(Data {
Matrix WVP;
@@ -66,6 +69,10 @@ void Sky::InitConfig(ShaderAtmosphericFogData& config) const
config.AtmosphericFogSunPower = SunPower;
config.AtmosphericFogDensityOffset = 0.0f;
+#if USE_EDITOR
+ if (IsRunningRadiancePass)
+ config.AtmosphericFogSunPower *= IndirectLightingIntensity;
+#endif
if (SunLight)
{
@@ -140,6 +147,7 @@ void Sky::Serialize(SerializeStream& stream, const void* otherObj)
SERIALIZE_MEMBER(Sun, SunLight);
SERIALIZE(SunDiscScale);
SERIALIZE(SunPower);
+ SERIALIZE(IndirectLightingIntensity);
}
void Sky::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
@@ -150,6 +158,7 @@ void Sky::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
DESERIALIZE_MEMBER(Sun, SunLight);
DESERIALIZE(SunDiscScale);
DESERIALIZE(SunPower);
+ DESERIALIZE(IndirectLightingIntensity);
}
bool Sky::HasContentLoaded() const
@@ -204,6 +213,11 @@ bool Sky::IsDynamicSky() const
return !IsStatic() || (SunLight && !SunLight->IsStatic());
}
+float Sky::GetIndirectLightingIntensity() const
+{
+ return IndirectLightingIntensity;
+}
+
void Sky::ApplySky(GPUContext* context, RenderContext& renderContext, const Matrix& world)
{
// Get precomputed cache and bind it to the pipeline
diff --git a/Source/Engine/Level/Actors/Sky.h b/Source/Engine/Level/Actors/Sky.h
index 313843748..bbc58888f 100644
--- a/Source/Engine/Level/Actors/Sky.h
+++ b/Source/Engine/Level/Actors/Sky.h
@@ -31,21 +31,27 @@ public:
///
/// Directional light that is used to simulate the sun.
///
- API_FIELD(Attributes="EditorOrder(10), DefaultValue(null), EditorDisplay(\"Sky\")")
+ API_FIELD(Attributes="EditorOrder(10), EditorDisplay(\"Sky\")")
ScriptingObjectReference SunLight;
///
/// The sun disc scale.
///
- API_FIELD(Attributes="EditorOrder(20), DefaultValue(2.0f), EditorDisplay(\"Sky\"), Limit(0, 100, 0.01f)")
+ API_FIELD(Attributes="EditorOrder(20), EditorDisplay(\"Sky\"), Limit(0, 100, 0.01f)")
float SunDiscScale = 2.0f;
///
/// The sun power.
///
- API_FIELD(Attributes="EditorOrder(30), DefaultValue(8.0f), EditorDisplay(\"Sky\"), Limit(0, 1000, 0.01f)")
+ API_FIELD(Attributes="EditorOrder(30), EditorDisplay(\"Sky\"), Limit(0, 1000, 0.01f)")
float SunPower = 8.0f;
+ ///
+ /// Controls how much sky will contribute indirect lighting. When set to 0, there is no GI from the sky. The default value is 1.
+ ///
+ API_FIELD(Attributes="EditorOrder(40), Limit(0, 100, 0.1f), EditorDisplay(\"Sky\")")
+ float IndirectLightingIntensity = 1.0f;
+
private:
#if COMPILE_WITH_DEV_ENV
void OnShaderReloading(Asset* obj)
@@ -76,6 +82,7 @@ public:
// [ISkyRenderer]
bool IsDynamicSky() const override;
+ float GetIndirectLightingIntensity() const override;
void ApplySky(GPUContext* context, RenderContext& renderContext, const Matrix& world) override;
protected:
diff --git a/Source/Engine/Level/Actors/Skybox.cpp b/Source/Engine/Level/Actors/Skybox.cpp
index e59e3a3e4..51b288c42 100644
--- a/Source/Engine/Level/Actors/Skybox.cpp
+++ b/Source/Engine/Level/Actors/Skybox.cpp
@@ -94,6 +94,11 @@ bool Skybox::IsDynamicSky() const
return !IsStatic();
}
+float Skybox::GetIndirectLightingIntensity() const
+{
+ return 1.0f;
+}
+
void Skybox::ApplySky(GPUContext* context, RenderContext& renderContext, const Matrix& world)
{
// Prepare mock draw call data
diff --git a/Source/Engine/Level/Actors/Skybox.h b/Source/Engine/Level/Actors/Skybox.h
index 46adef7ca..240c3b62a 100644
--- a/Source/Engine/Level/Actors/Skybox.h
+++ b/Source/Engine/Level/Actors/Skybox.h
@@ -70,6 +70,7 @@ public:
// [ISkyRenderer]
bool IsDynamicSky() const override;
+ float GetIndirectLightingIntensity() const override;
void ApplySky(GPUContext* context, RenderContext& renderContext, const Matrix& world) override;
protected:
diff --git a/Source/Engine/Renderer/DrawCall.h b/Source/Engine/Renderer/DrawCall.h
index 448d1361e..a3324e1f3 100644
--- a/Source/Engine/Renderer/DrawCall.h
+++ b/Source/Engine/Renderer/DrawCall.h
@@ -40,6 +40,8 @@ public:
///
virtual bool IsDynamicSky() const = 0;
+ virtual float GetIndirectLightingIntensity() const = 0;
+
///
/// Apply sky material/shader state to the GPU pipeline with custom parameters set (render to GBuffer).
///
diff --git a/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp b/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp
index 1169d7ff6..d615e2515 100644
--- a/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp
+++ b/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp
@@ -60,7 +60,7 @@ GPU_CB_STRUCT(Data0 {
GlobalSurfaceAtlasPass::ConstantsData GlobalSurfaceAtlas;
ShaderGBufferData GBuffer;
Float4 RaysRotation;
- float Padding0;
+ float SkyboxIntensity;
uint32 ProbesCount;
float ResetBlend;
float TemporalTime;
@@ -533,6 +533,7 @@ bool DynamicDiffuseGlobalIlluminationPass::RenderInner(RenderContext& renderCont
}
data.TemporalTime = renderContext.List->Setup.UseTemporalAAJitter ? RenderTools::ComputeTemporalTime() : 0.0f;
data.ViewDir = renderContext.View.Direction;
+ data.SkyboxIntensity = renderContext.List->Sky ? renderContext.List->Sky->GetIndirectLightingIntensity() : 1.0f;
GBufferPass::SetInputs(renderContext.View, data.GBuffer);
context->UpdateCB(_cb0, &data);
context->BindCB(0, _cb0);
diff --git a/Source/Shaders/GI/DDGI.shader b/Source/Shaders/GI/DDGI.shader
index 89d0fdea3..7a58b03df 100644
--- a/Source/Shaders/GI/DDGI.shader
+++ b/Source/Shaders/GI/DDGI.shader
@@ -35,7 +35,7 @@ GlobalSDFData GlobalSDF;
GlobalSurfaceAtlasData GlobalSurfaceAtlas;
GBufferData GBuffer;
float4 RaysRotation;
-float Padding0;
+float SkyboxIntensity;
uint ProbesCount;
float ResetBlend;
float TemporalTime;
@@ -397,7 +397,7 @@ void CS_TraceRays(uint3 DispatchThreadId : SV_DispatchThreadID)
else
{
// Ray hits sky
- radiance.rgb = Skybox.SampleLevel(SamplerLinearClamp, probeRayDirection, 0).rgb;
+ radiance.rgb = Skybox.SampleLevel(SamplerLinearClamp, probeRayDirection, 0).rgb * SkyboxIntensity;
radiance.a = 1e27f; // Sky is the limit
}