Add IndirectLightingIntensity to Sky for GI intensity control

This commit is contained in:
Wojtek Figat
2024-08-12 15:34:08 +02:00
parent bcb0200435
commit 63bee0c78d
7 changed files with 36 additions and 6 deletions

View File

@@ -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

View File

@@ -31,21 +31,27 @@ public:
/// <summary>
/// Directional light that is used to simulate the sun.
/// </summary>
API_FIELD(Attributes="EditorOrder(10), DefaultValue(null), EditorDisplay(\"Sky\")")
API_FIELD(Attributes="EditorOrder(10), EditorDisplay(\"Sky\")")
ScriptingObjectReference<DirectionalLight> SunLight;
/// <summary>
/// The sun disc scale.
/// </summary>
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;
/// <summary>
/// The sun power.
/// </summary>
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;
/// <summary>
/// Controls how much sky will contribute indirect lighting. When set to 0, there is no GI from the sky. The default value is 1.
/// </summary>
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:

View File

@@ -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

View File

@@ -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:

View File

@@ -40,6 +40,8 @@ public:
/// </summary>
virtual bool IsDynamicSky() const = 0;
virtual float GetIndirectLightingIntensity() const = 0;
/// <summary>
/// Apply sky material/shader state to the GPU pipeline with custom parameters set (render to GBuffer).
/// </summary>

View File

@@ -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);

View File

@@ -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
}