4#ifndef GREM_GRAPHICS_3D_LIGHTS_3D_HPP
5#define GREM_GRAPHICS_3D_LIGHTS_3D_HPP
410 shadowMapIndicesDirty =
true;
411 shadowMatrixIndicesDirty =
true;
791 cascadedShadowMapCapacity = 0;
794 pointLightShadowMapCapacity = 0;
797 spotLightShadowMapCapacity = 0;
799 options = newOptions;
800 shadowMapIndicesDirty =
true;
801 shadowMatrixIndicesDirty =
true;
802 parameterBufferDirty =
true;
837 for (
const auto& [lightID, light] : lights) {
838 if constexpr (CALLBACK_RETURNS_BOOL) {
839 if (callback(lightID)) {
846 if constexpr (CALLBACK_RETURNS_BOOL) {
855 vec3 direction{0.0f, 0.0f, 0.0f};
858 vec3 position{0.0f, 0.0f, 0.0f};
860 float innerConeCosine = 0.0f;
861 float outerConeCosine = 0.0f;
862 float shadowMapIndex = -1.0f;
863 float shadowMatrixIndex = -1.0f;
864 float shadowNearZ = 0.01f;
865 float shadowFarZ = 100.0f;
866 float shadowMapNormalOffsetBiasConstantFactor = 0.04f;
867 float shadowMapNormalOffsetBiasSlopeFactor = 1.0f;
870 GREM_API(graphics_3d)
void flushIndices(Device& device)
const;
871 GREM_API(graphics_3d)
void flush(Device& device)
const;
873 Lights3DOptions options;
874 mutable Registry<Light, LightID> lights{};
875 mutable uint32_t cascadedShadowMapCapacity = 0;
876 mutable uint32_t pointLightShadowMapCapacity = 0;
877 mutable uint32_t spotLightShadowMapCapacity = 0;
878 mutable Texture cascadedShadowMaps{};
879 mutable Texture pointLightShadowMaps{};
880 mutable Texture spotLightShadowMaps{};
881 mutable Buffer<ShadowMatrixFields> shadowMatrices{};
884 mutable bool shadowMapIndicesDirty =
true;
885 mutable bool shadowMatrixIndicesDirty =
true;
886 mutable bool parameterBufferDirty =
true;
887 mutable bool shadowMatrixBufferDirty =
true;
Floating-point linear RGBA color in the Rec.
Definition Color.hpp:60
static const Color WHITE
Definition Color.hpp:215
Definition InplaceBuffer.hpp:24
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
constexpr RegistryElementIDBase() noexcept=default
Construct an invalid element handle.
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
void setAmbientLightOptions(LightID id, const AmbientLightOptions3D &newOptions)
Update the options of an ambient light.
StorageBuffer< ShadowMatrixFields, "Lights3DShadowMatrices"> ShadowMatrixBuffer
Shader buffer for shadow matrices.
Definition Lights3D.hpp:390
void setLightDirection(LightID id, vec3 newDirection)
Update the direction of a light.
LightID createDirectionalLight(const DirectionalLightOptions3D &options)
Create a purely directional light with infinite range.
void setSunLightOptions(LightID id, const SunLightOptions3D &newOptions)
Update the options of a sun light.
static constexpr size_t MAX_SHADOW_CASCADE_COUNT
Maximum number of cascade levels used for cascaded shadow mapping of directional lights.
Definition Lights3D.hpp:366
void setLightShadowFarZ(LightID id, float newShadowFarZ)
Update the shadow far plane distance of a light.
void setLightShadowNearZ(LightID id, float newShadowNearZ)
Update the shadow near plane distance of a light.
void setSpotLightOptions(LightID id, const SpotLightOptions3D &newOptions)
Update the options of a spot light.
void setLightShadowMapNormalOffsetBiasConstantFactor(LightID id, float newShadowMapNormalOffsetBiasConstantFactor)
Update the shadow map constant normal offset bias factor of a light.
Optional< PointLightOptions3D > getPointLightOptions(LightID id) const
Get the options of a specific point light.
void setLightPosition(LightID id, vec3 newPosition)
Update the position of a light.
Optional< LightType > getLightType(LightID id) const
Get the light type of a specific light.
Optional< AmbientLightOptions3D > getAmbientLightOptions(LightID id) const
Get the options of a specific ambient light.
void clearLights() noexcept
Destroy all lights and remove them from the set.
Definition Lights3D.hpp:408
Lights3D(Device &device, const Lights3DOptions &options={})
Construct a set of lights.
void setLightShadowMapNormalOffsetBiasSlopeFactor(LightID id, float newShadowMapNormalOffsetBiasSlopeFactor)
Update the shadow map slope-scaled normal offset bias factor of a light.
void setOptions(const Lights3DOptions &newOptions)
Set the configuration options of the light set.
Definition Lights3D.hpp:789
Optional< DirectionalLightOptions3D > getDirectionalLightOptions(LightID id) const
Get the options of a specific directional light.
void setPointLightOptions(LightID id, const PointLightOptions3D &newOptions)
Update the options of a point light.
LightID createPointLight(const PointLightOptions3D &options)
Create an infinitesimally small point light, which can be used to approximate e.g....
void setLightInnerConeAngle(LightID id, float newInnerConeAngle)
Update the inner cone angle of a light.
void setLightRange(LightID id, float newRange)
Update the range of a light.
void setLightOuterConeAngle(LightID id, float newOuterConeAngle)
Update the outer cone angle of a light.
Optional< SunLightOptions3D > getSunLightOptions(LightID id) const
Get the options of a specific sun light.
bool containsLight(LightID id) const noexcept
Check if a specific light handle is still valid, meaning that the light has not yet been destroyed.
void setLightColor(LightID id, Color newColor)
Update the color of a light.
void setDirectionalLightOptions(LightID id, const DirectionalLightOptions3D &newOptions)
Update the options of a directional light.
Lights3DOptions getOptions() const noexcept
Get the configuration options of the light set.
Definition Lights3D.hpp:810
LightID createAmbientLight(const AmbientLightOptions3D &options)
Create an ambient light source, which adds an (unrealistic) constant amount of light to everything.
LightID createSunLight(const SunLightOptions3D &options)
Create a sun light source, or a directional light that is tied to the skybox and replaces its baked l...
bool destroyLight(LightID id)
Destroy a light and remove it from the set.
auto forEachLight(auto callback)
Execute a callback function for each light in the light set.
Definition Lights3D.hpp:835
LightID createSpotLight(const SpotLightOptions3D &options)
Create a point light that is limited to a cone shape, which can be used to approximate e....
void setLightShadowMapped(LightID id, bool newShadowMapped)
Update whether a light should use shadow mapping or not.
Optional< SpotLightOptions3D > getSpotLightOptions(LightID id) const
Get the options of a specific spot light.
UniformBuffer< Parameters, "Lights3DParameters"> ParameterBuffer
Shader buffer for light parameters.
Definition Lights3D.hpp:381
Persistent system that provides 3D rendering capabilities.
Definition Renderer3D.hpp:120
GPU memory buffer containing an array of structs to be read by a shader program.
Definition buffers.hpp:493
Definition concepts.hpp:47
Definition concepts.hpp:243
Definition buffer_layouts.hpp:20
LightType
Type of a light in a Lights3D set.
Definition Lights3D.hpp:39
@ DIRECTIONAL_LIGHT
See DirectionalLightOptions3D.
Definition Lights3D.hpp:42
@ POINT_LIGHT
See PointLightOptions3D.
Definition Lights3D.hpp:43
@ SPOT_LIGHT
See SpotLightOptions3D.
Definition Lights3D.hpp:44
@ SUN_LIGHT
See SunLightOptions3D.
Definition Lights3D.hpp:41
@ AMBIENT_LIGHT
See AmbientLightOptions3D.
Definition Lights3D.hpp:40
vec< 3, float > vec3
Definition math.hpp:439
mat< 4, 4, float > mat4
Definition math.hpp:806
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL convertDegreesToRadians(T angleInDegrees)
Definition math.hpp:3390
Configuration options for a 3D light source representing the ambient light in a scene,...
Definition Lights3D.hpp:51
constexpr bool operator==(const AmbientLightOptions3D &other) const noexcept=default
Compare these options to another set of options for equality.
Color color
Color of the light, where the alpha component controls the light's intensity.
Definition Lights3D.hpp:56
Configuration options for a 3D light source representing a purely directional light with infinite ran...
Definition Lights3D.hpp:116
bool shadowMapped
Whether the light should use shadow mapping or not.
Definition Lights3D.hpp:143
vec3 direction
Vector representing the direction of the light, in world coordinates.
Definition Lights3D.hpp:120
Color color
Color of the light, where the alpha component controls the light's intensity.
Definition Lights3D.hpp:126
constexpr bool operator==(const DirectionalLightOptions3D &other) const noexcept=default
Compare these options to another set of options for equality.
float shadowMapNormalOffsetBiasSlopeFactor
Slope-scaled normal offset bias factor to use when sampling the shadow map of the light.
Definition Lights3D.hpp:138
float shadowMapNormalOffsetBiasConstantFactor
Constant normal offset bias factor to use when sampling the shadow map of the light.
Definition Lights3D.hpp:132
Opaque handle to a specific light in a Lights3D set.
Definition Lights3D.hpp:32
constexpr RegistryElementIDBase() noexcept=default
Construct an invalid element handle.
Configuration options for a Lights3D set.
Definition Lights3D.hpp:305
uint32_t cascadedShadowMapResolution
Width, in texels, of each cascade level of the shadow maps of sun/directional lights.
Definition Lights3D.hpp:316
static constexpr size_t MAX_SHADOW_CASCADE_COUNT
Maximum number of cascade levels used for cascaded shadow mapping of directional lights.
Definition Lights3D.hpp:310
uint32_t spotLightShadowMapResolution
Width, in texels, of the shadow maps of spot lights.
Definition Lights3D.hpp:328
float shadowCascadeBlendSize
Length of the blend area between cascade levels for cascaded shadow mapping of sun/directional lights...
Definition Lights3D.hpp:348
constexpr bool operator==(const Lights3DOptions &other) const noexcept=default
Compare these options to another set of options for equality.
uint32_t pointLightShadowMapResolution
Width, in texels, of the shadow maps of point lights.
Definition Lights3D.hpp:322
InplaceBuffer< float, MAX_SHADOW_CASCADE_COUNT > shadowCascadeFrustumFarPlaneDistances
Distances of the far planes of each cascade level's view frustum used for cascaded shadow mapping of ...
Definition Lights3D.hpp:334
Struct of shader parameters for a set of lights.
Definition Lights3D.hpp:369
float lightsShadowCascadeBlendSize
Length of the blend area between cascade levels for cascaded shadow mapping of directional lights.
Definition Lights3D.hpp:377
Array< float, Lights3D::MAX_SHADOW_CASCADE_COUNT > lightsShadowCascadeFrustumFarPlaneDistances
Distances to the far planes of each cascade level's view frustum used for cascaded shadow mapping of ...
Definition Lights3D.hpp:371
uint32_t lightsShadowCascadeCount
Number of shadow cascade levels for cascaded shadow mapping of directional lights.
Definition Lights3D.hpp:374
Struct of shader fields representing the shadow matrix of a light.
Definition Lights3D.hpp:384
mat4 shadowMatrix
Combined view-projection matrix of the light.
Definition Lights3D.hpp:386
Configuration options for an infinitesimally small point light source, which can be used to approxima...
Definition Lights3D.hpp:159
float shadowNearZ
Distance to the near plane of the light's shadow map.
Definition Lights3D.hpp:183
vec3 position
Position of the light, in world coordinates.
Definition Lights3D.hpp:163
float shadowMapNormalOffsetBiasSlopeFactor
Slope-scaled normal offset bias factor to use when sampling the shadow map of the light.
Definition Lights3D.hpp:202
Color color
Color of the light, where the alpha component controls the light's intensity.
Definition Lights3D.hpp:176
constexpr bool operator==(const PointLightOptions3D &other) const noexcept=default
Compare these options to another set of options for equality.
float shadowMapNormalOffsetBiasConstantFactor
Constant normal offset bias factor to use when sampling the shadow map of the light.
Definition Lights3D.hpp:196
float shadowFarZ
Distance to the near plane of the light's shadow map.
Definition Lights3D.hpp:190
bool shadowMapped
Whether the light should use shadow mapping or not.
Definition Lights3D.hpp:207
Configuration options for a point light source that is limited to a cone shape, which can be used to ...
Definition Lights3D.hpp:223
float innerConeAngle
Angle, from the light's direction axis, of the inner limit where the light cone is the brightest,...
Definition Lights3D.hpp:246
float shadowNearZ
Distance to the near plane of the light's shadow map.
Definition Lights3D.hpp:266
float shadowFarZ
Distance to the near plane of the light's shadow map.
Definition Lights3D.hpp:273
vec3 direction
Vector representing the direction of the light, in world coordinates.
Definition Lights3D.hpp:232
bool shadowMapped
Whether the light should use shadow mapping or not.
Definition Lights3D.hpp:290
vec3 position
Position of the light, in world coordinates.
Definition Lights3D.hpp:227
float shadowMapNormalOffsetBiasSlopeFactor
Slope-scaled normal offset bias factor to use when sampling the shadow map of the light.
Definition Lights3D.hpp:285
float outerConeAngle
Angle, from the light's direction axis, of the outer limit where the light cone fades to zero,...
Definition Lights3D.hpp:253
float shadowMapNormalOffsetBiasConstantFactor
Constant normal offset bias factor to use when sampling the shadow map of the light.
Definition Lights3D.hpp:279
Color color
Color of the light, where the alpha component controls the light's intensity.
Definition Lights3D.hpp:259
constexpr bool operator==(const SpotLightOptions3D &other) const noexcept=default
Compare these options to another set of options for equality.
Configuration options for a 3D light source representing a directional light that is tied to the skyb...
Definition Lights3D.hpp:73
bool shadowMapped
Whether the light should use shadow mapping or not.
Definition Lights3D.hpp:100
vec3 direction
Vector representing the direction of the light, in world coordinates.
Definition Lights3D.hpp:77
Color color
Color of the light, where the alpha component controls the light's intensity.
Definition Lights3D.hpp:83
float shadowMapNormalOffsetBiasConstantFactor
Constant normal offset bias factor to use when sampling the shadow map of the light.
Definition Lights3D.hpp:89
float shadowMapNormalOffsetBiasSlopeFactor
Slope-scaled normal offset bias factor to use when sampling the shadow map of the light.
Definition Lights3D.hpp:95
constexpr bool operator==(const SunLightOptions3D &other) const noexcept=default
Compare these options to another set of options for equality.