GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::graphics::Lights3D Class Reference

Set of direct light sources in 3D space. More...

#include <GREM/graphics_3d/Lights3D.hpp>

Classes

struct  Parameters
 Struct of shader parameters for a set of lights. More...
struct  ShadowMatrixFields
 Struct of shader fields representing the shadow matrix of a light. More...

Public Types

using ParameterBuffer = UniformBuffer<Parameters, "Lights3DParameters">
 Shader buffer for light parameters.
using ShadowMatrixBuffer = StorageBuffer<ShadowMatrixFields, "Lights3DShadowMatrices">
 Shader buffer for shadow matrices.

Public Member Functions

 Lights3D (Device &device, const Lights3DOptions &options={})
 Construct a set of lights.
void clearLights () noexcept
 Destroy all lights and remove them from the set.
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 lighting on directly lit surfaces.
LightID createDirectionalLight (const DirectionalLightOptions3D &options)
 Create a purely directional light with infinite range.
LightID createPointLight (const PointLightOptions3D &options)
 Create an infinitesimally small point light, which can be used to approximate e.g. a light bulb.
LightID createSpotLight (const SpotLightOptions3D &options)
 Create a point light that is limited to a cone shape, which can be used to approximate e.g. a headlamp on a car.
bool containsLight (LightID id) const noexcept
 Check if a specific light handle is still valid, meaning that the light has not yet been destroyed.
bool destroyLight (LightID id)
 Destroy a light and remove it from the set.
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.
Optional< SunLightOptions3D > getSunLightOptions (LightID id) const
 Get the options of a specific sun light.
Optional< DirectionalLightOptions3D > getDirectionalLightOptions (LightID id) const
 Get the options of a specific directional light.
Optional< PointLightOptions3D > getPointLightOptions (LightID id) const
 Get the options of a specific point light.
Optional< SpotLightOptions3D > getSpotLightOptions (LightID id) const
 Get the options of a specific spot light.
void setAmbientLightOptions (LightID id, const AmbientLightOptions3D &newOptions)
 Update the options of an ambient light.
void setSunLightOptions (LightID id, const SunLightOptions3D &newOptions)
 Update the options of a sun light.
void setDirectionalLightOptions (LightID id, const DirectionalLightOptions3D &newOptions)
 Update the options of a directional light.
void setPointLightOptions (LightID id, const PointLightOptions3D &newOptions)
 Update the options of a point light.
void setSpotLightOptions (LightID id, const SpotLightOptions3D &newOptions)
 Update the options of a spot light.
void setLightPosition (LightID id, vec3 newPosition)
 Update the position of a light.
void setLightDirection (LightID id, vec3 newDirection)
 Update the direction of a light.
void setLightRange (LightID id, float newRange)
 Update the range of a light.
void setLightInnerConeAngle (LightID id, float newInnerConeAngle)
 Update the inner cone angle of a light.
void setLightOuterConeAngle (LightID id, float newOuterConeAngle)
 Update the outer cone angle of a light.
void setLightColor (LightID id, Color newColor)
 Update the color of a light.
void setLightShadowNearZ (LightID id, float newShadowNearZ)
 Update the shadow near plane distance of a light.
void setLightShadowFarZ (LightID id, float newShadowFarZ)
 Update the shadow far plane distance of a light.
void setLightShadowMapNormalOffsetBiasConstantFactor (LightID id, float newShadowMapNormalOffsetBiasConstantFactor)
 Update the shadow map constant normal offset bias factor of a light.
void setLightShadowMapNormalOffsetBiasSlopeFactor (LightID id, float newShadowMapNormalOffsetBiasSlopeFactor)
 Update the shadow map slope-scaled normal offset bias factor of a light.
void setLightShadowMapped (LightID id, bool newShadowMapped)
 Update whether a light should use shadow mapping or not.
void setOptions (const Lights3DOptions &newOptions)
 Set the configuration options of the light set.
Lights3DOptions getOptions () const noexcept
 Get the configuration options of the light set.
auto forEachLight (auto callback)
 Execute a callback function for each light in the light set.

Static Public Attributes

static constexpr size_t MAX_SHADOW_CASCADE_COUNT = Lights3DOptions::MAX_SHADOW_CASCADE_COUNT
 Maximum number of cascade levels used for cascaded shadow mapping of directional lights.

Detailed Description

Set of direct light sources in 3D space.

Member Typedef Documentation

◆ ParameterBuffer

Shader buffer for light parameters.

◆ ShadowMatrixBuffer

Shader buffer for shadow matrices.

Constructor & Destructor Documentation

◆ Lights3D()

grem::graphics::Lights3D::Lights3D ( Device & device,
const Lights3DOptions & options = {} )
explicit

Construct a set of lights.

Parameters
devicedevice to create the lights for. Must outlive the lights.
optionslight set options, see Lights3DOptions.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

Member Function Documentation

◆ clearLights()

void grem::graphics::Lights3D::clearLights ( )
inlinenoexcept

Destroy all lights and remove them from the set.

◆ createAmbientLight()

LightID grem::graphics::Lights3D::createAmbientLight ( const AmbientLightOptions3D & options)

Create an ambient light source, which adds an (unrealistic) constant amount of light to everything.

Parameters
optionslight options, see AmbientLightOptions3D.
Returns
a handle to the new light that can be used to refer back to it later in order to make changes to it.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ createSunLight()

LightID grem::graphics::Lights3D::createSunLight ( const SunLightOptions3D & options)

Create a sun light source, or a directional light that is tied to the skybox and replaces its baked lighting on directly lit surfaces.

Parameters
optionslight options, see SunLightOptions3D.
Returns
a handle to the new light that can be used to refer back to it later in order to make changes to it.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If the created light is shadow mapped, any current rendered shadow maps are invalidated for all lights.

◆ createDirectionalLight()

LightID grem::graphics::Lights3D::createDirectionalLight ( const DirectionalLightOptions3D & options)

Create a purely directional light with infinite range.

Parameters
optionslight options, see DirectionalLightOptions3D.
Returns
a handle to the new light that can be used to refer back to it later in order to make changes to it.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If the created light is shadow mapped, any current rendered shadow maps are invalidated for all lights.

◆ createPointLight()

LightID grem::graphics::Lights3D::createPointLight ( const PointLightOptions3D & options)

Create an infinitesimally small point light, which can be used to approximate e.g. a light bulb.

Parameters
optionslight options, see PointLightOptions3D.
Returns
a handle to the new light that can be used to refer back to it later in order to make changes to it.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If the created light is shadow mapped, any current rendered shadow maps are invalidated for all lights.

◆ createSpotLight()

LightID grem::graphics::Lights3D::createSpotLight ( const SpotLightOptions3D & options)

Create a point light that is limited to a cone shape, which can be used to approximate e.g. a headlamp on a car.

Parameters
optionslight options, see SpotLightOptions3D.
Returns
a handle to the new light that can be used to refer back to it later in order to make changes to it.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If the created light is shadow mapped, any current rendered shadow maps are invalidated for all lights.

◆ containsLight()

bool grem::graphics::Lights3D::containsLight ( LightID id) const
nodiscardnoexcept

Check if a specific light handle is still valid, meaning that the light has not yet been destroyed.

Parameters
idhandle to the light.
Returns
true if the associated light still exists, false if the light has been destroyed.

◆ destroyLight()

bool grem::graphics::Lights3D::destroyLight ( LightID id)

Destroy a light and remove it from the set.

Parameters
idhandle to the light.
Returns
true if the specified light was found and destroyed, false otherwise.
Note
If the specified light has already been destroyed, this function has no effect.
If the destroyed light was shadow mapped, any current rendered shadow maps are invalidated for all lights.

◆ getLightType()

Optional< LightType > grem::graphics::Lights3D::getLightType ( LightID id) const

Get the light type of a specific light.

Parameters
idhandle to the light.
Returns
the type of the light, or an empty optional if the light doesn't exist.

◆ getAmbientLightOptions()

Optional< AmbientLightOptions3D > grem::graphics::Lights3D::getAmbientLightOptions ( LightID id) const

Get the options of a specific ambient light.

Parameters
idhandle to the light.
Returns
the current options of the light, or an empty optional if the light doesn't exist or is not an ambient light.

◆ getSunLightOptions()

Optional< SunLightOptions3D > grem::graphics::Lights3D::getSunLightOptions ( LightID id) const

Get the options of a specific sun light.

Parameters
idhandle to the light.
Returns
the current options of the light, or an empty optional if the light doesn't exist or is not a sun light.

◆ getDirectionalLightOptions()

Optional< DirectionalLightOptions3D > grem::graphics::Lights3D::getDirectionalLightOptions ( LightID id) const

Get the options of a specific directional light.

Parameters
idhandle to the light.
Returns
the current options of the light, or an empty optional if the light doesn't exist or is not a directional light.

◆ getPointLightOptions()

Optional< PointLightOptions3D > grem::graphics::Lights3D::getPointLightOptions ( LightID id) const

Get the options of a specific point light.

Parameters
idhandle to the light.
Returns
the current options of the light, or an empty optional if the light doesn't exist or is not a point light.

◆ getSpotLightOptions()

Optional< SpotLightOptions3D > grem::graphics::Lights3D::getSpotLightOptions ( LightID id) const

Get the options of a specific spot light.

Parameters
idhandle to the light.
Returns
the current options of the light, or an empty optional if the light doesn't exist or is not a spot light.

◆ setAmbientLightOptions()

void grem::graphics::Lights3D::setAmbientLightOptions ( LightID id,
const AmbientLightOptions3D & newOptions )

Update the options of an ambient light.

Parameters
idhandle to the light.
newOptionsnew light options, see AmbientLightOptions3D.
Note
If the given light handle is invalid, or if the specified light is not an ambient light, this function has no effect.

◆ setSunLightOptions()

void grem::graphics::Lights3D::setSunLightOptions ( LightID id,
const SunLightOptions3D & newOptions )

Update the options of a sun light.

Parameters
idhandle to the light.
newOptionsnew light options, see SunLightOptions3D.
Note
If the given light handle is invalid, or if the specified light is not a sun light, this function has no effect.
If the shadow mapped state changed for the specified light, any current rendered shadow maps are invalidated for all lights.

◆ setDirectionalLightOptions()

void grem::graphics::Lights3D::setDirectionalLightOptions ( LightID id,
const DirectionalLightOptions3D & newOptions )

Update the options of a directional light.

Parameters
idhandle to the light.
newOptionsnew light options, see DirectionalLightOptions3D.
Note
If the given light handle is invalid, or if the specified light is not a directional light, this function has no effect.
If the shadow mapped state changed for the specified light, any current rendered shadow maps are invalidated for all lights.

◆ setPointLightOptions()

void grem::graphics::Lights3D::setPointLightOptions ( LightID id,
const PointLightOptions3D & newOptions )

Update the options of a point light.

Parameters
idhandle to the light.
newOptionsnew light options, see PointLightOptions3D.
Note
If the given light handle is invalid, or if the specified light is not a point light, this function has no effect.
If the shadow mapped state changed for the specified light, any current rendered shadow maps are invalidated for all lights.

◆ setSpotLightOptions()

void grem::graphics::Lights3D::setSpotLightOptions ( LightID id,
const SpotLightOptions3D & newOptions )

Update the options of a spot light.

Parameters
idhandle to the light.
newOptionsnew light options, see SpotLightOptions3D.
Note
If the given light handle is invalid, or if the specified light is not a spot light, this function has no effect.
If the shadow mapped state changed for the specified light, any current rendered shadow maps are invalidated for all lights.

◆ setLightPosition()

void grem::graphics::Lights3D::setLightPosition ( LightID id,
vec3 newPosition )

Update the position of a light.

Parameters
idhandle to the light.
newPositionnew position of the light, in world coordinates.
Note
If the given light handle is invalid, this function has no effect.

◆ setLightDirection()

void grem::graphics::Lights3D::setLightDirection ( LightID id,
vec3 newDirection )

Update the direction of a light.

Parameters
idhandle to the light.
newDirectionnew direction vector of the light, in world coordinates.
Note
If the given light handle is invalid, this function has no effect.

◆ setLightRange()

void grem::graphics::Lights3D::setLightRange ( LightID id,
float newRange )

Update the range of a light.

Parameters
idhandle to the light.
newRangenew maximum range of the light, in world coordinates, beyond which the light will have no effect, or a non-positive value for infinite range.
Note
If the given light handle is invalid, this function has no effect.

◆ setLightInnerConeAngle()

void grem::graphics::Lights3D::setLightInnerConeAngle ( LightID id,
float newInnerConeAngle )

Update the inner cone angle of a light.

Parameters
idhandle to the light.
newInnerConeAnglenew angle, in radians. Must be less than or equal to the outer cone angle, and between 0 and pi radians (inclusive).
Note
If the given light handle is invalid, this function has no effect.

◆ setLightOuterConeAngle()

void grem::graphics::Lights3D::setLightOuterConeAngle ( LightID id,
float newOuterConeAngle )

Update the outer cone angle of a light.

Parameters
idhandle to the light.
newOuterConeAnglenew angle, in radians. Must be greater than or equal to the inner cone angle, and between 0 and pi radians (inclusive).
Note
If the given light handle is invalid, this function has no effect.

◆ setLightColor()

void grem::graphics::Lights3D::setLightColor ( LightID id,
Color newColor )

Update the color of a light.

Parameters
idhandle to the light.
newColornew color of the light, where the alpha component controls the light's intensity.
Note
If the given light handle is invalid, this function has no effect.

◆ setLightShadowNearZ()

void grem::graphics::Lights3D::setLightShadowNearZ ( LightID id,
float newShadowNearZ )

Update the shadow near plane distance of a light.

Parameters
idhandle to the light.
newShadowNearZnew distance to the near plane of the light's shadow map. Must be less than the shadow far plane distance.
Note
If the given light handle is invalid, this function has no effect.

◆ setLightShadowFarZ()

void grem::graphics::Lights3D::setLightShadowFarZ ( LightID id,
float newShadowFarZ )

Update the shadow far plane distance of a light.

Parameters
idhandle to the light.
newShadowFarZnew distance to the far plane of the light's shadow map. Must be greater than the shadow near plane distance.
Note
If the given light handle is invalid, this function has no effect.

◆ setLightShadowMapNormalOffsetBiasConstantFactor()

void grem::graphics::Lights3D::setLightShadowMapNormalOffsetBiasConstantFactor ( LightID id,
float newShadowMapNormalOffsetBiasConstantFactor )

Update the shadow map constant normal offset bias factor of a light.

Parameters
idhandle to the light.
newShadowMapNormalOffsetBiasConstantFactornew constant normal offset bias factor to use when sampling the shadow map of the light.
Note
If the given light handle is invalid, this function has no effect.

◆ setLightShadowMapNormalOffsetBiasSlopeFactor()

void grem::graphics::Lights3D::setLightShadowMapNormalOffsetBiasSlopeFactor ( LightID id,
float newShadowMapNormalOffsetBiasSlopeFactor )

Update the shadow map slope-scaled normal offset bias factor of a light.

Parameters
idhandle to the light.
newShadowMapNormalOffsetBiasSlopeFactornew slope-scaled normal offset bias factor to use when sampling the shadow map of the light.
Note
If the given light handle is invalid, this function has no effect.

◆ setLightShadowMapped()

void grem::graphics::Lights3D::setLightShadowMapped ( LightID id,
bool newShadowMapped )

Update whether a light should use shadow mapping or not.

Parameters
idhandle to the light.
newShadowMappednew shadow mapped flag.
Note
If the given light handle is invalid, this function has no effect.
If the shadow mapped state successfully changed for the specified light, any current rendered shadow maps are invalidated for all lights.

◆ setOptions()

void grem::graphics::Lights3D::setOptions ( const Lights3DOptions & newOptions)
inline

Set the configuration options of the light set.

Parameters
newOptionsnew configuration options, see Lights3DOptions.
Note
This function invalidates any current rendered shadow maps for all lights.

◆ getOptions()

Lights3DOptions grem::graphics::Lights3D::getOptions ( ) const
inlinenodiscardnoexcept

Get the configuration options of the light set.

Returns
the current configuration options.

◆ forEachLight()

auto grem::graphics::Lights3D::forEachLight ( auto callback)
inline

Execute a callback function for each light in the light set.

Parameters
callbackfunction to execute, which should accept the light ID as a parameter. The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
anyexception thrown by the callback function.
Note
The order of traversal is unspecified.
Warning
Lights must not be added or removed from the set during traversal, unless the traversal is stopped immediately afterwards.

Member Data Documentation

◆ MAX_SHADOW_CASCADE_COUNT

size_t grem::graphics::Lights3D::MAX_SHADOW_CASCADE_COUNT = Lights3DOptions::MAX_SHADOW_CASCADE_COUNT
staticconstexpr

Maximum number of cascade levels used for cascaded shadow mapping of directional lights.


The documentation for this class was generated from the following file: