|
GREM 3.12.0
Game/Rendering Engine Modules for C++
|
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. | |
Set of direct light sources in 3D space.
| using grem::graphics::Lights3D::ParameterBuffer = UniformBuffer<Parameters, "Lights3DParameters"> |
Shader buffer for light parameters.
| using grem::graphics::Lights3D::ShadowMatrixBuffer = StorageBuffer<ShadowMatrixFields, "Lights3DShadowMatrices"> |
Shader buffer for shadow matrices.
|
explicit |
Construct a set of lights.
| device | device to create the lights for. Must outlive the lights. |
| options | light set options, see Lights3DOptions. |
| graphics::Error | if resource creation failed. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenoexcept |
Destroy all lights and remove them from the set.
| LightID grem::graphics::Lights3D::createAmbientLight | ( | const AmbientLightOptions3D & | options | ) |
Create an ambient light source, which adds an (unrealistic) constant amount of light to everything.
| options | light options, see AmbientLightOptions3D. |
| graphics::Error | if resource creation failed. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| 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.
| options | light options, see SunLightOptions3D. |
| graphics::Error | if resource creation failed. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| LightID grem::graphics::Lights3D::createDirectionalLight | ( | const DirectionalLightOptions3D & | options | ) |
Create a purely directional light with infinite range.
| options | light options, see DirectionalLightOptions3D. |
| graphics::Error | if resource creation failed. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| 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.
| options | light options, see PointLightOptions3D. |
| graphics::Error | if resource creation failed. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| 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.
| options | light options, see SpotLightOptions3D. |
| graphics::Error | if resource creation failed. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
nodiscardnoexcept |
Check if a specific light handle is still valid, meaning that the light has not yet been destroyed.
| id | handle to the light. |
| bool grem::graphics::Lights3D::destroyLight | ( | LightID | id | ) |
Destroy a light and remove it from the set.
| id | handle to the light. |
Get the light type of a specific light.
| id | handle to the light. |
| Optional< AmbientLightOptions3D > grem::graphics::Lights3D::getAmbientLightOptions | ( | LightID | id | ) | const |
Get the options of a specific ambient light.
| id | handle to the light. |
| Optional< SunLightOptions3D > grem::graphics::Lights3D::getSunLightOptions | ( | LightID | id | ) | const |
Get the options of a specific sun light.
| id | handle to the light. |
| Optional< DirectionalLightOptions3D > grem::graphics::Lights3D::getDirectionalLightOptions | ( | LightID | id | ) | const |
Get the options of a specific directional light.
| id | handle to the light. |
| Optional< PointLightOptions3D > grem::graphics::Lights3D::getPointLightOptions | ( | LightID | id | ) | const |
Get the options of a specific point light.
| id | handle to the light. |
| Optional< SpotLightOptions3D > grem::graphics::Lights3D::getSpotLightOptions | ( | LightID | id | ) | const |
Get the options of a specific spot light.
| id | handle to the light. |
| void grem::graphics::Lights3D::setAmbientLightOptions | ( | LightID | id, |
| const AmbientLightOptions3D & | newOptions ) |
Update the options of an ambient light.
| id | handle to the light. |
| newOptions | new light options, see AmbientLightOptions3D. |
| void grem::graphics::Lights3D::setSunLightOptions | ( | LightID | id, |
| const SunLightOptions3D & | newOptions ) |
Update the options of a sun light.
| id | handle to the light. |
| newOptions | new light options, see SunLightOptions3D. |
| void grem::graphics::Lights3D::setDirectionalLightOptions | ( | LightID | id, |
| const DirectionalLightOptions3D & | newOptions ) |
Update the options of a directional light.
| id | handle to the light. |
| newOptions | new light options, see DirectionalLightOptions3D. |
| void grem::graphics::Lights3D::setPointLightOptions | ( | LightID | id, |
| const PointLightOptions3D & | newOptions ) |
Update the options of a point light.
| id | handle to the light. |
| newOptions | new light options, see PointLightOptions3D. |
| void grem::graphics::Lights3D::setSpotLightOptions | ( | LightID | id, |
| const SpotLightOptions3D & | newOptions ) |
Update the options of a spot light.
| id | handle to the light. |
| newOptions | new light options, see SpotLightOptions3D. |
Update the position of a light.
| id | handle to the light. |
| newPosition | new position of the light, in world coordinates. |
Update the direction of a light.
| id | handle to the light. |
| newDirection | new direction vector of the light, in world coordinates. |
| void grem::graphics::Lights3D::setLightRange | ( | LightID | id, |
| float | newRange ) |
Update the range of a light.
| id | handle to the light. |
| newRange | new maximum range of the light, in world coordinates, beyond which the light will have no effect, or a non-positive value for infinite range. |
| void grem::graphics::Lights3D::setLightInnerConeAngle | ( | LightID | id, |
| float | newInnerConeAngle ) |
Update the inner cone angle of a light.
| id | handle to the light. |
| newInnerConeAngle | new angle, in radians. Must be less than or equal to the outer cone angle, and between 0 and pi radians (inclusive). |
| void grem::graphics::Lights3D::setLightOuterConeAngle | ( | LightID | id, |
| float | newOuterConeAngle ) |
Update the outer cone angle of a light.
| id | handle to the light. |
| newOuterConeAngle | new angle, in radians. Must be greater than or equal to the inner cone angle, and between 0 and pi radians (inclusive). |
Update the color of a light.
| id | handle to the light. |
| newColor | new color of the light, where the alpha component controls the light's intensity. |
| void grem::graphics::Lights3D::setLightShadowNearZ | ( | LightID | id, |
| float | newShadowNearZ ) |
Update the shadow near plane distance of a light.
| id | handle to the light. |
| newShadowNearZ | new distance to the near plane of the light's shadow map. Must be less than the shadow far plane distance. |
| void grem::graphics::Lights3D::setLightShadowFarZ | ( | LightID | id, |
| float | newShadowFarZ ) |
Update the shadow far plane distance of a light.
| id | handle to the light. |
| newShadowFarZ | new distance to the far plane of the light's shadow map. Must be greater than the shadow near plane distance. |
| void grem::graphics::Lights3D::setLightShadowMapNormalOffsetBiasConstantFactor | ( | LightID | id, |
| float | newShadowMapNormalOffsetBiasConstantFactor ) |
Update the shadow map constant normal offset bias factor of a light.
| id | handle to the light. |
| newShadowMapNormalOffsetBiasConstantFactor | new constant normal offset bias factor to use when sampling the shadow map of the light. |
| void grem::graphics::Lights3D::setLightShadowMapNormalOffsetBiasSlopeFactor | ( | LightID | id, |
| float | newShadowMapNormalOffsetBiasSlopeFactor ) |
Update the shadow map slope-scaled normal offset bias factor of a light.
| id | handle to the light. |
| newShadowMapNormalOffsetBiasSlopeFactor | new slope-scaled normal offset bias factor to use when sampling the shadow map of the light. |
| void grem::graphics::Lights3D::setLightShadowMapped | ( | LightID | id, |
| bool | newShadowMapped ) |
Update whether a light should use shadow mapping or not.
| id | handle to the light. |
| newShadowMapped | new shadow mapped flag. |
|
inline |
Set the configuration options of the light set.
| newOptions | new configuration options, see Lights3DOptions. |
|
inlinenodiscardnoexcept |
Get the configuration options of the light set.
|
inline |
Execute a callback function for each light in the light set.
| callback | function 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. |
| any | exception thrown by the callback function. |
|
staticconstexpr |
Maximum number of cascade levels used for cascaded shadow mapping of directional lights.