Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
DirectionalLight Class Referencefinal

A directional light, where all light rays have the same direction. More...

#include <DirectionalLight.hpp>

Public Member Functions

 DirectionalLight ()=default
 
 DirectionalLight (const glm::vec3 &worldDirection, const glm::vec3 &color)
 
void draw (LightRenderer &renderer) override
 
void update (double fullTime, double frameTime) override
 
void setScene (const BoundingBox &sceneBox) override
 
glm::vec3 sample (const glm::vec3 &position, float &dist, float &attenuation) const override
 
bool decode (const KeyValues &params)
 
KeyValues encode () const override
 
const glm::vec3 & direction () const
 
- Public Member Functions inherited from Light
 Light ()
 
 Light (const glm::vec3 &color)
 
void addAnimation (const std::shared_ptr< Animation > &anim)
 
virtual void draw (LightRenderer &renderer)=0
 
virtual void update (double fullTime, double frameTime)=0
 
virtual void setScene (const BoundingBox &sceneBox)=0
 
virtual glm::vec3 sample (const glm::vec3 &position, float &dist, float &attenuation) const =0
 
virtual KeyValues encode () const
 
bool castsShadow () const
 
void setCastShadow (bool shouldCast)
 
const glm::vec3 & intensity () const
 
void setIntensity (const glm::vec3 &color)
 
const glm::mat4 & vp () const
 
const glm::mat4 & model () const
 
const ShadowMap::RegionshadowMap () const
 
void registerShadowMap (const Texture *map, ShadowMode mode, size_t layer=0, const glm::vec2 &minUV=glm::vec2(0.0f), const glm::vec2 &maxUV=glm::vec2(1.0f))
 
bool animated () const
 
virtual ~Light ()=default
 
 Light (const Light &)=delete
 
Lightoperator= (const Light &)=delete
 
 Light (Light &&)=default
 
Lightoperator= (Light &&)=delete
 

Private Attributes

glm::mat4 _projectionMatrix = glm::mat4(1.0f)
 Light projection matrix.
 
glm::mat4 _viewMatrix = glm::mat4(1.0f)
 Light view matrix.
 
Animated< glm::vec3 > _lightDirection { glm::vec3(0.0f, 0.0f, 1.0f) }
 Light direction.
 

Additional Inherited Members

- Static Public Member Functions inherited from Light
static std::shared_ptr< Lightdecode (const KeyValues &params)
 
- Protected Member Functions inherited from Light
bool decodeBase (const KeyValues &params)
 
- Protected Attributes inherited from Light
std::vector< std::shared_ptr< Animation > > _animations
 Animations list (will be applied in order).
 
ShadowMap::Region _shadowMapInfos
 Region of the (optional) shadow map containing this light information.
 
BoundingBox _sceneBox
 The scene bounding box, to fit the shadow map.
 
glm::mat4 _vp
 VP matrix for shadow casting.
 
glm::mat4 _model
 Model matrix of the mesh containing the light-covered region.
 
glm::vec3 _color
 Colored intensity.
 
bool _castShadows
 Is the light casting shadows (and thus use a shadow map)..
 

Detailed Description

A directional light, where all light rays have the same direction.

It can be associated with a shadow 2D map with orthogonal projection. It is rendered as a fullscreen squad in deferred rendering.

See also
GPU::Frag::Directional_light, GPU::Frag::Light_shadow, GPU::Frag::Light_debug

Inherits Light.

Constructor & Destructor Documentation

◆ DirectionalLight() [1/2]

DirectionalLight::DirectionalLight ( )
default

Default constructor.

◆ DirectionalLight() [2/2]

DirectionalLight::DirectionalLight ( const glm::vec3 &  worldDirection,
const glm::vec3 &  color 
)

Constructor.

Parameters
worldDirectionthe light direction in world space
colorthe colored intensity of the light

Member Function Documentation

◆ decode()

bool DirectionalLight::decode ( const KeyValues params)

Setup a directional light parameters from a list of key-value tuples. The following keywords will be searched for:

direction: dirX,dirY,dirZ
intensity: R,G,B
shadows: bool
animations:
    - animationtype: ...
    - ...
Parameters
paramsthe parameters tuple
Returns
decoding status

◆ direction()

const glm::vec3 & DirectionalLight::direction ( ) const
inline

Get the light principal direction in world space.

Returns
the direction

◆ draw()

void DirectionalLight::draw ( LightRenderer renderer)
overridevirtual

Process the light using a specific renderer.

See also
LightRenderer for the expected interface details.
Parameters
rendererthe light-specific renderer

Implements Light.

◆ encode()

KeyValues DirectionalLight::encode ( ) const
overridevirtual

Generate a key-values representation of the light. See decode for the keywords and layout.

Returns
a tuple representing the light

Reimplemented from Light.

◆ sample()

glm::vec3 DirectionalLight::sample ( const glm::vec3 &  position,
float &  dist,
float &  attenuation 
) const
overridevirtual

Sample a direction from a reference point to the light.

Parameters
positionthe 3D point
distwill contain the distance from the light to the point
attenuationwill contain the light attenuation factor
Returns
a direction from the point to the light

Implements Light.

◆ setScene()

void DirectionalLight::setScene ( const BoundingBox sceneBox)
overridevirtual

Update the scene bounding box used for internal setup (shadow map,...).

Parameters
sceneBoxthe new bounding box

Implements Light.

◆ update()

void DirectionalLight::update ( double  fullTime,
double  frameTime 
)
overridevirtual

Apply the animations for a frame duration.

Parameters
fullTimethe time since the launch of the application
frameTimethe time elapsed since the last frame

Implements Light.


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