Refactor lights data in renderer storage

This commit is contained in:
Wojtek Figat
2024-03-25 17:13:40 +01:00
parent d13621e631
commit 0e00f1e0eb
11 changed files with 58 additions and 116 deletions

View File

@@ -24,7 +24,7 @@ void DirectionalLight::Draw(RenderContext& renderContext)
&& EnumHasAnyFlags(renderContext.View.Pass, DrawPass::GBuffer)
&& (ViewDistance < ZeroTolerance || Float3::DistanceSquared(renderContext.View.Position, position) < ViewDistance * ViewDistance))
{
RendererDirectionalLightData data;
RenderDirectionalLightData data;
data.Position = position;
data.MinRoughness = MinRoughness;
data.ShadowsDistance = ShadowsDistance;
@@ -45,7 +45,6 @@ void DirectionalLight::Draw(RenderContext& renderContext)
data.Cascade2Spacing = Cascade2Spacing;
data.Cascade3Spacing = Cascade3Spacing;
data.Cascade4Spacing = Cascade4Spacing;
data.PartitionMode = PartitionMode;
data.ContactShadowsLength = ContactShadowsLength;
data.StaticFlags = GetStaticFlags();
@@ -66,7 +65,6 @@ void DirectionalLight::Serialize(SerializeStream& stream, const void* otherObj)
SERIALIZE(Cascade2Spacing);
SERIALIZE(Cascade3Spacing);
SERIALIZE(Cascade4Spacing);
SERIALIZE(PartitionMode);
}
@@ -80,7 +78,6 @@ void DirectionalLight::Deserialize(DeserializeStream& stream, ISerializeModifier
DESERIALIZE(Cascade2Spacing);
DESERIALIZE(Cascade3Spacing);
DESERIALIZE(Cascade4Spacing);
DESERIALIZE(PartitionMode);
}

View File

@@ -89,7 +89,7 @@ void PointLight::Draw(RenderContext& renderContext)
&& radius > ZeroTolerance
&& (ViewDistance < ZeroTolerance || Vector3::DistanceSquared(renderContext.View.Position, position) < ViewDistance * ViewDistance))
{
RendererPointLightData data;
RenderPointLightData data;
data.Position = position;
data.MinRoughness = MinRoughness;
data.ShadowsDistance = ShadowsDistance;

View File

@@ -113,7 +113,7 @@ void SkyLight::Draw(RenderContext& renderContext)
&& brightness > ZeroTolerance
&& (ViewDistance < ZeroTolerance || Vector3::DistanceSquared(renderContext.View.Position, position) < ViewDistance * ViewDistance))
{
RendererSkyLightData data;
RenderSkyLightData data;
data.Position = position;
data.Color = Color.ToFloat3() * (Color.A * brightness);
data.VolumetricScatteringIntensity = VolumetricScatteringIntensity;

View File

@@ -139,7 +139,7 @@ void SpotLight::Draw(RenderContext& renderContext)
&& outerConeAngle > ZeroTolerance
&& (ViewDistance < ZeroTolerance || Vector3::DistanceSquared(renderContext.View.Position, position) < ViewDistance * ViewDistance))
{
RendererSpotLightData data;
RenderSpotLightData data;
data.Position = position;
data.MinRoughness = MinRoughness;
data.ShadowsDistance = ShadowsDistance;

View File

@@ -388,7 +388,7 @@ void ParticleEmitterGraphCPUExecutor::Draw(ParticleEmitter* emitter, ParticleEff
const auto module = emitter->Graph.LightModules[moduleIndex];
ASSERT(module->TypeID == 401);
RendererPointLightData lightData;
RenderPointLightData lightData;
lightData.MinRoughness = 0.04f;
lightData.ShadowsDistance = 2000.0f;
lightData.ShadowsStrength = 1.0f;

View File

@@ -39,7 +39,7 @@ namespace
CriticalSection MemPoolLocker;
}
void RendererDirectionalLightData::SetupLightData(LightData* data, bool useShadow) const
void RenderDirectionalLightData::SetupLightData(LightData* data, bool useShadow) const
{
data->SpotAngles.X = -2.0f;
data->SpotAngles.Y = 1.0f;
@@ -56,7 +56,7 @@ void RendererDirectionalLightData::SetupLightData(LightData* data, bool useShado
data->RadiusInv = 0;
}
void RendererSpotLightData::SetupLightData(LightData* data, bool useShadow) const
void RenderSpotLightData::SetupLightData(LightData* data, bool useShadow) const
{
data->SpotAngles.X = CosOuterCone;
data->SpotAngles.Y = InvCosConeDifference;
@@ -73,7 +73,7 @@ void RendererSpotLightData::SetupLightData(LightData* data, bool useShadow) cons
data->RadiusInv = 1.0f / Radius;
}
void RendererPointLightData::SetupLightData(LightData* data, bool useShadow) const
void RenderPointLightData::SetupLightData(LightData* data, bool useShadow) const
{
data->SpotAngles.X = -2.0f;
data->SpotAngles.Y = 1.0f;
@@ -90,7 +90,7 @@ void RendererPointLightData::SetupLightData(LightData* data, bool useShadow) con
data->RadiusInv = 1.0f / Radius;
}
void RendererSkyLightData::SetupLightData(LightData* data, bool useShadow) const
void RenderSkyLightData::SetupLightData(LightData* data, bool useShadow) const
{
data->SpotAngles.X = AdditiveColor.X;
data->SpotAngles.Y = AdditiveColor.Y;

View File

@@ -22,8 +22,10 @@ class CubeTexture;
struct RenderContext;
struct RenderContextBatch;
struct RendererDirectionalLightData
struct RenderLightData
{
Guid ID;
Float3 Position;
float MinRoughness;
@@ -36,49 +38,35 @@ struct RendererDirectionalLightData
float ShadowsNormalOffsetScale;
float ShadowsDepthBias;
float ShadowsSharpness;
float VolumetricScatteringIntensity;
float ShadowsDistance;
StaticFlags StaticFlags;
ShadowsCastingMode ShadowsMode;
float IndirectLightingIntensity;
int16 ShadowDataIndex = -1;
uint8 CastVolumetricShadow : 1;
uint8 RenderedVolumetricFog : 1;
float ShadowsDistance;
float VolumetricScatteringIntensity;
float ContactShadowsLength;
};
struct RenderDirectionalLightData : RenderLightData
{
PartitionMode PartitionMode;
int32 CascadeCount;
float Cascade1Spacing;
float Cascade2Spacing;
float Cascade3Spacing;
float Cascade4Spacing;
PartitionMode PartitionMode;
float ContactShadowsLength;
ShadowsCastingMode ShadowsMode;
Guid ID;
void SetupLightData(LightData* data, bool useShadow) const;
};
struct RendererSpotLightData
struct RenderSpotLightData : RenderLightData
{
Float3 Position;
float MinRoughness;
Float3 Color;
float ShadowsStrength;
Float3 Direction;
float ShadowsFadeDistance;
float ShadowsNormalOffsetScale;
float ShadowsDepthBias;
float ShadowsSharpness;
float VolumetricScatteringIntensity;
float ShadowsDistance;
float Radius;
float FallOffExponent;
float SourceRadius;
Float3 UpVector;
@@ -86,77 +74,34 @@ struct RendererSpotLightData
float CosOuterCone;
float InvCosConeDifference;
float ContactShadowsLength;
float IndirectLightingIntensity;
ShadowsCastingMode ShadowsMode;
StaticFlags StaticFlags;
int16 ShadowDataIndex = -1;
uint8 CastVolumetricShadow : 1;
uint8 RenderedVolumetricFog : 1;
float FallOffExponent;
uint8 UseInverseSquaredFalloff : 1;
GPUTexture* IESTexture;
Guid ID;
void SetupLightData(LightData* data, bool useShadow) const;
};
struct RendererPointLightData
struct RenderPointLightData : RenderLightData
{
Float3 Position;
float MinRoughness;
Float3 Color;
float ShadowsStrength;
Float3 Direction;
float ShadowsFadeDistance;
float ShadowsNormalOffsetScale;
float ShadowsDepthBias;
float ShadowsSharpness;
float VolumetricScatteringIntensity;
float ShadowsDistance;
float Radius;
float FallOffExponent;
float SourceRadius;
float FallOffExponent;
float SourceLength;
float ContactShadowsLength;
float IndirectLightingIntensity;
ShadowsCastingMode ShadowsMode;
StaticFlags StaticFlags;
int16 ShadowDataIndex = -1;
uint8 CastVolumetricShadow : 1;
uint8 RenderedVolumetricFog : 1;
uint8 UseInverseSquaredFalloff : 1;
GPUTexture* IESTexture;
Guid ID;
void SetupLightData(LightData* data, bool useShadow) const;
};
struct RendererSkyLightData
struct RenderSkyLightData : RenderLightData
{
Float3 Position;
float VolumetricScatteringIntensity;
Float3 Color;
Float3 AdditiveColor;
float Radius;
Float3 AdditiveColor;
float IndirectLightingIntensity;
StaticFlags StaticFlags;
uint8 CastVolumetricShadow : 1;
uint8 RenderedVolumetricFog : 1;
CubeTexture* Image;
Guid ID;
void SetupLightData(LightData* data, bool useShadow) const;
};
@@ -318,22 +263,22 @@ public:
/// <summary>
/// Light pass members - directional lights
/// </summary>
Array<RendererDirectionalLightData> DirectionalLights;
Array<RenderDirectionalLightData> DirectionalLights;
/// <summary>
/// Light pass members - point lights
/// </summary>
Array<RendererPointLightData> PointLights;
Array<RenderPointLightData> PointLights;
/// <summary>
/// Light pass members - spot lights
/// </summary>
Array<RendererSpotLightData> SpotLights;
Array<RenderSpotLightData> SpotLights;
/// <summary>
/// Light pass members - sky lights
/// </summary>
Array<RendererSkyLightData> SkyLights;
Array<RenderSkyLightData> SkyLights;
/// <summary>
/// Environment probes to use for rendering reflections

View File

@@ -219,7 +219,7 @@ void ShadowsPass::SetupRenderContext(RenderContext& renderContext, RenderContext
shadowContext.Task = renderContext.Task;
}
void ShadowsPass::SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererDirectionalLightData& light)
void ShadowsPass::SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RenderDirectionalLightData& light)
{
const RenderView& view = renderContext.View;
auto mainCache = renderContext.List;
@@ -453,7 +453,7 @@ void ShadowsPass::SetupLight(RenderContext& renderContext, RenderContextBatch& r
shadowData.Constants.CascadeSplits = view.Near + Float4(cascadeSplits) * cameraRange;
}
void ShadowsPass::SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererPointLightData& light)
void ShadowsPass::SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RenderPointLightData& light)
{
// Init shadow data
light.ShadowDataIndex = _shadowData.Count();
@@ -493,7 +493,7 @@ void ShadowsPass::SetupLight(RenderContext& renderContext, RenderContextBatch& r
shadowData.Constants.CascadeSplits = Float4::Zero;
}
void ShadowsPass::SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererSpotLightData& light)
void ShadowsPass::SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RenderSpotLightData& light)
{
// Init shadow data
light.ShadowDataIndex = _shadowData.Count();
@@ -585,7 +585,7 @@ void ShadowsPass::SetupShadows(RenderContext& renderContext, RenderContextBatch&
}
}
bool ShadowsPass::CanRenderShadow(const RenderContext& renderContext, const RendererPointLightData& light)
bool ShadowsPass::CanRenderShadow(const RenderContext& renderContext, const RenderPointLightData& light)
{
const Float3 lightPosition = light.Position;
const float dstLightToView = Float3::Distance(lightPosition, renderContext.View.Position);
@@ -597,7 +597,7 @@ bool ShadowsPass::CanRenderShadow(const RenderContext& renderContext, const Rend
return fade > ZeroTolerance && _shadowMapFormat != PixelFormat::Unknown;
}
bool ShadowsPass::CanRenderShadow(const RenderContext& renderContext, const RendererSpotLightData& light)
bool ShadowsPass::CanRenderShadow(const RenderContext& renderContext, const RenderSpotLightData& light)
{
const Float3 lightPosition = light.Position;
const float dstLightToView = Float3::Distance(lightPosition, renderContext.View.Position);
@@ -609,12 +609,12 @@ bool ShadowsPass::CanRenderShadow(const RenderContext& renderContext, const Rend
return fade > ZeroTolerance && _shadowMapFormat != PixelFormat::Unknown;
}
bool ShadowsPass::CanRenderShadow(const RenderContext& renderContext, const RendererDirectionalLightData& light)
bool ShadowsPass::CanRenderShadow(const RenderContext& renderContext, const RenderDirectionalLightData& light)
{
return _shadowMapFormat != PixelFormat::Unknown;
}
void ShadowsPass::RenderShadow(RenderContextBatch& renderContextBatch, RendererPointLightData& light, GPUTextureView* shadowMask)
void ShadowsPass::RenderShadow(RenderContextBatch& renderContextBatch, RenderPointLightData& light, GPUTextureView* shadowMask)
{
if (light.ShadowDataIndex == -1)
return;
@@ -692,7 +692,7 @@ void ShadowsPass::RenderShadow(RenderContextBatch& renderContextBatch, RendererP
VolumetricFogPass::Instance()->RenderLight(renderContext, context, light, _shadowMapCube->ViewArray(), sperLight.LightShadow);
}
void ShadowsPass::RenderShadow(RenderContextBatch& renderContextBatch, RendererSpotLightData& light, GPUTextureView* shadowMask)
void ShadowsPass::RenderShadow(RenderContextBatch& renderContextBatch, RenderSpotLightData& light, GPUTextureView* shadowMask)
{
if (light.ShadowDataIndex == -1)
return;
@@ -770,7 +770,7 @@ void ShadowsPass::RenderShadow(RenderContextBatch& renderContextBatch, RendererS
VolumetricFogPass::Instance()->RenderLight(renderContext, context, light, _shadowMapCube->View(faceIndex), sperLight.LightShadow);
}
void ShadowsPass::RenderShadow(RenderContextBatch& renderContextBatch, RendererDirectionalLightData& light, int32 index, GPUTextureView* shadowMask)
void ShadowsPass::RenderShadow(RenderContextBatch& renderContextBatch, RenderDirectionalLightData& light, int32 index, GPUTextureView* shadowMask)
{
if (light.ShadowDataIndex == -1)
return;

View File

@@ -107,7 +107,7 @@ public:
/// <param name="renderContext">The rendering context.</param>
/// <param name="light">The light.</param>
/// <returns><c>true</c> if can render shadow for the specified light; otherwise, <c>false</c>.</returns>
bool CanRenderShadow(const RenderContext& renderContext, const RendererPointLightData& light);
bool CanRenderShadow(const RenderContext& renderContext, const RenderPointLightData& light);
/// <summary>
/// Determines whether can render shadow for the specified light.
@@ -115,7 +115,7 @@ public:
/// <param name="renderContext">The rendering context.</param>
/// <param name="light">The light.</param>
/// <returns><c>true</c> if can render shadow for the specified light; otherwise, <c>false</c>.</returns>
bool CanRenderShadow(const RenderContext& renderContext, const RendererSpotLightData& light);
bool CanRenderShadow(const RenderContext& renderContext, const RenderSpotLightData& light);
/// <summary>
/// Determines whether can render shadow for the specified light.
@@ -123,7 +123,7 @@ public:
/// <param name="renderContext">The rendering context.</param>
/// <param name="light">The light.</param>
/// <returns><c>true</c> if can render shadow for the specified light; otherwise, <c>false</c>.</returns>
bool CanRenderShadow(const RenderContext& renderContext, const RendererDirectionalLightData& light);
bool CanRenderShadow(const RenderContext& renderContext, const RenderDirectionalLightData& light);
/// <summary>
/// Renders the shadow mask for the given light.
@@ -131,7 +131,7 @@ public:
/// <param name="renderContextBatch">The rendering context batch.</param>
/// <param name="light">The light.</param>
/// <param name="shadowMask">The shadow mask (output).</param>
void RenderShadow(RenderContextBatch& renderContextBatch, RendererPointLightData& light, GPUTextureView* shadowMask);
void RenderShadow(RenderContextBatch& renderContextBatch, RenderPointLightData& light, GPUTextureView* shadowMask);
/// <summary>
/// Renders the shadow mask for the given light.
@@ -139,7 +139,7 @@ public:
/// <param name="renderContextBatch">The rendering context batch.</param>
/// <param name="light">The light.</param>
/// <param name="shadowMask">The shadow mask (output).</param>
void RenderShadow(RenderContextBatch& renderContextBatch, RendererSpotLightData& light, GPUTextureView* shadowMask);
void RenderShadow(RenderContextBatch& renderContextBatch, RenderSpotLightData& light, GPUTextureView* shadowMask);
/// <summary>
/// Renders the shadow mask for the given light.
@@ -148,15 +148,15 @@ public:
/// <param name="light">The light.</param>
/// <param name="index">The light index.</param>
/// <param name="shadowMask">The shadow mask (output).</param>
void RenderShadow(RenderContextBatch& renderContextBatch, RendererDirectionalLightData& light, int32 index, GPUTextureView* shadowMask);
void RenderShadow(RenderContextBatch& renderContextBatch, RenderDirectionalLightData& light, int32 index, GPUTextureView* shadowMask);
private:
void updateShadowMapSize();
void SetupRenderContext(RenderContext& renderContext, RenderContext& shadowContext);
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererDirectionalLightData& light);
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererPointLightData& light);
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RendererSpotLightData& light);
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RenderDirectionalLightData& light);
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RenderPointLightData& light);
void SetupLight(RenderContext& renderContext, RenderContextBatch& renderContextBatch, RenderSpotLightData& light);
#if COMPILE_WITH_DEV_ENV
void OnShaderReloading(Asset* obj)

View File

@@ -387,7 +387,7 @@ void VolumetricFogPass::RenderRadialLight(RenderContext& renderContext, GPUConte
}
}
void VolumetricFogPass::RenderLight(RenderContext& renderContext, GPUContext* context, RendererPointLightData& light, GPUTextureView* shadowMap, LightShadowData& shadow)
void VolumetricFogPass::RenderLight(RenderContext& renderContext, GPUContext* context, RenderPointLightData& light, GPUTextureView* shadowMap, LightShadowData& shadow)
{
// Skip lights with no volumetric light influence or not casting volumetric shadow
if (light.VolumetricScatteringIntensity <= ZeroTolerance || !light.CastVolumetricShadow)
@@ -401,7 +401,7 @@ void VolumetricFogPass::RenderLight(RenderContext& renderContext, GPUContext* co
context->UnBindSR(5);
}
void VolumetricFogPass::RenderLight(RenderContext& renderContext, GPUContext* context, RendererSpotLightData& light, GPUTextureView* shadowMap, LightShadowData& shadow)
void VolumetricFogPass::RenderLight(RenderContext& renderContext, GPUContext* context, RenderSpotLightData& light, GPUTextureView* shadowMap, LightShadowData& shadow)
{
// Skip lights with no volumetric light influence or not casting volumetric shadow
if (light.VolumetricScatteringIntensity <= ZeroTolerance || !light.CastVolumetricShadow)
@@ -594,8 +594,8 @@ void VolumetricFogPass::Render(RenderContext& renderContext)
GPUTextureView* localShadowedLightScattering = nullptr;
{
// Get lights to render
Array<const RendererPointLightData*, InlinedAllocation<64, RendererAllocation>> pointLights;
Array<const RendererSpotLightData*, InlinedAllocation<64, RendererAllocation>> spotLights;
Array<const RenderPointLightData*, InlinedAllocation<64, RendererAllocation>> pointLights;
Array<const RenderSpotLightData*, InlinedAllocation<64, RendererAllocation>> spotLights;
for (int32 i = 0; i < renderContext.List->PointLights.Count(); i++)
{
const auto& light = renderContext.List->PointLights[i];

View File

@@ -8,8 +8,8 @@
#include "GI/DynamicDiffuseGlobalIllumination.h"
struct VolumetricFogOptions;
struct RendererSpotLightData;
struct RendererPointLightData;
struct RenderSpotLightData;
struct RenderPointLightData;
/// <summary>
/// Volumetric fog rendering service.
@@ -156,7 +156,7 @@ public:
/// <param name="light">The light.</param>
/// <param name="shadowMap">The shadow map.</param>
/// <param name="shadow">The light shadow data.</param>
void RenderLight(RenderContext& renderContext, GPUContext* context, RendererPointLightData& light, GPUTextureView* shadowMap, LightShadowData& shadow);
void RenderLight(RenderContext& renderContext, GPUContext* context, RenderPointLightData& light, GPUTextureView* shadowMap, LightShadowData& shadow);
/// <summary>
/// Renders the light to the volumetric fog light scattering volume texture. Called by the light pass after shadow map rendering. Used by the shadows casting lights.
@@ -166,7 +166,7 @@ public:
/// <param name="light">The light.</param>
/// <param name="shadowMap">The shadow map.</param>
/// <param name="shadow">The light shadow data.</param>
void RenderLight(RenderContext& renderContext, GPUContext* context, RendererSpotLightData& light, GPUTextureView* shadowMap, LightShadowData& shadow);
void RenderLight(RenderContext& renderContext, GPUContext* context, RenderSpotLightData& light, GPUTextureView* shadowMap, LightShadowData& shadow);
/// <summary>
/// Renders the volumetric fog (generates integrated light scattering 3D texture). Does nothing if feature is disabled or not supported.