class Light

Public

Constructors

Light

Light(const HSceneObject &parent)

Methods

SetType

void SetType(LightType type)

Determines the type of the light.

SetCastsShadow

void SetCastsShadow(bool castsShadow)

Determines does this light cast shadows when rendered.

SetShadowBias

void SetShadowBias(float bias)

Shadow bias determines offset at which the shadows are rendered from the shadow caster.

Bias value of 0 means the shadow will be renderered exactly at the casters position. If your geometry has thin areas this will produce an artifact called shadow acne, in which case you can increase the shadow bias value to eliminate it. Note that increasing the shadow bias will on the other hand make the shadow be offset from the caster and may make the caster appear as if floating (Peter Panning artifact). Neither is perfect, so it is preferable to ensure all your geometry has thickness and keep the bias at zero, or even at negative values.

Default value is 0.5. Should be in rough range [-1, 1].

SetColor

void SetColor(const Color &color)

Determines the color emitted by the light.

SetAttenuationRadius

void SetAttenuationRadius(float radius)

Range at which the light contribution fades out to zero.

Use SetUseAutoAttenuation to provide a radius automatically dependant on light intensity. The radius will cut-off light contribution and therefore manually set very small radius can end up being very physically incorrect.

SetSourceRadius

void SetSourceRadius(float radius)

Radius of the light source.

If non-zero then this light represents an area light, otherwise it is a punctual light. Area lights have different attenuation then punctual lights, and their appearance in specular reflections is realistic. Shape of the area light depends on light type:

  • For directional light the shape is a disc projected on the hemisphere on the sky. This parameter represents angular radius (in degrees) of the disk and should be very small (think of how much space the Sun takes on the sky - roughly 0.25 degree radius).
  • For radial light the shape is a sphere and the source radius is the radius of the sphere.
  • For spot lights the shape is a disc oriented in the direction of the spot light and the source radius is the radius of the disc.

SetUseAutoAttenuation

void SetUseAutoAttenuation(bool enabled)

If enabled the attenuation radius will automatically be controlled in order to provide reasonable light radius, depending on its intensity.

SetIntensity

void SetIntensity(float intensity)

Determines the power of the light source.

This will be luminous flux for radial

& spot lights, luminance for directional lights with no area, and illuminance for directional lights with area (non-zero source radius).

SetSpotAngle

void SetSpotAngle(const Degree &spotAngle)

Determines the total angle covered by a spot light.

SetSpotFalloffAngle

void SetSpotFalloffAngle(const Degree &spotFallofAngle)

Determines the falloff angle covered by a spot light.

Falloff angle determines at what point does light intensity starts quadratically falling off as the angle approaches the total spot angle.

GetLuminance

float GetLuminance() const

Returns the luminance of the light source.

This is the value that should be used in lighting equations.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

GetType

LightType GetType() const

Determines the type of the light.

GetCastsShadow

bool GetCastsShadow() const

Determines does this light cast shadows when rendered.

GetShadowBias

float GetShadowBias() const

Shadow bias determines offset at which the shadows are rendered from the shadow caster.

Bias value of 0 means the shadow will be renderered exactly at the casters position. If your geometry has thin areas this will produce an artifact called shadow acne, in which case you can increase the shadow bias value to eliminate it. Note that increasing the shadow bias will on the other hand make the shadow be offset from the caster and may make the caster appear as if floating (Peter Panning artifact). Neither is perfect, so it is preferable to ensure all your geometry has thickness and keep the bias at zero, or even at negative values.

Default value is 0.5. Should be in rough range [-1, 1].

GetColor

Color GetColor() const

Determines the color emitted by the light.

GetAttenuationRadius

float GetAttenuationRadius() const

Range at which the light contribution fades out to zero.

Use SetUseAutoAttenuation to provide a radius automatically dependant on light intensity. The radius will cut-off light contribution and therefore manually set very small radius can end up being very physically incorrect.

GetSourceRadius

float GetSourceRadius() const

Radius of the light source.

If non-zero then this light represents an area light, otherwise it is a punctual light. Area lights have different attenuation then punctual lights, and their appearance in specular reflections is realistic. Shape of the area light depends on light type:

  • For directional light the shape is a disc projected on the hemisphere on the sky. This parameter represents angular radius (in degrees) of the disk and should be very small (think of how much space the Sun takes on the sky - roughly 0.25 degree radius).
  • For radial light the shape is a sphere and the source radius is the radius of the sphere.
  • For spot lights the shape is a disc oriented in the direction of the spot light and the source radius is the radius of the disc.

GetUseAutoAttenuation

bool GetUseAutoAttenuation() const

If enabled the attenuation radius will automatically be controlled in order to provide reasonable light radius, depending on its intensity.

GetIntensity

float GetIntensity() const

Determines the power of the light source.

This will be luminous flux for radial

& spot lights, luminance for directional lights with no area, and illuminance for directional lights with area (non-zero source radius).

GetSpotAngle

Degree GetSpotAngle() const

Determines the total angle covered by a spot light.

GetSpotFalloffAngle

Degree GetSpotFalloffAngle() const

Determines the falloff angle covered by a spot light.

Falloff angle determines at what point does light intensity starts quadratically falling off as the angle approaches the total spot angle.

GetBounds

Sphere GetBounds() const

Returns world space bounds that completely encompass the light's area of influence.

Protected

Constructors

Light

Light()

Methods

Initialize

void Initialize() override

Construct any resources the component needs before use.

Called when the parent scene object is initialized. A non-initialized component shouldn't be used in a live scene (i.e. it should not receive any of the component logic updates or events).

OnCreated

void OnCreated() override

Called once when the component has been created.

Called regardless of the state the component is in.

OnEnabled

void OnEnabled() override

Called every time a component leaves the Stopped state, if the component is enabled.

This includes component creation if requirements for leaving the Stopped state are met. When called during creation it is called after OnBeginPlay.

OnDisabled

void OnDisabled() override

Called every time a component is placed into the Stopped state.

This includes component destruction if component wasn't already in Stopped state during destruction. When called during destruction it is called before OnDestroyed.

OnDestroyed

void OnDestroyed() override

Called once just before the component is destroyed.

Called regardless of the state the component is in.

OnSceneChanged

void OnSceneChanged(SceneInstance *oldScene, ecs::Entity oldEntity) override

Called when the parent SceneObject's ECS entity is migrated to a new registry (e.g. when moving between scenes).

The old scene and entity are provided so that components can access sub-systems (renderer, physics, etc.) and read any data stored only in ECS fragments.

OnTransformChanged

void OnTransformChanged(TransformChangedFlags flags) override

Called when the component's parent scene object has changed.

Not called if the component is in Stopped state. Also only called if necessary notify flags are set via SetNotifyFlagsInternal().

Private

Methods

MarkRenderProxyDataDirty

void MarkRenderProxyDataDirty(ComponentDirtyFlag flag = ComponentDirtyFlag::Everything)

Marks the render proxy data as dirty.

This causes the SyncToRenderProxy() method to trigger the next time objects are synced to the render thread.

flags
Flags in case you want to signal that only part of the internal data is dirty. SyncToRenderProxy() will be called regardless and it's up to the implementation to read the flags value if needed.

GetLightData

const TLightData<false> &GetLightData() const

Returns a reference to the light data for the CRTP getter interface.

GetFragment

ecs::Light &GetFragment()

Returns a mutable reference to the ECS light fragment.

GetFragment

const ecs::Light &GetFragment() const

Returns a const reference to the ECS light fragment.

UpdateBounds

void UpdateBounds()

Updates the internal bounds for the light.

Call this whenever a property affecting the bounds changes.

UpdateAttenuationRange

void UpdateAttenuationRange()

Calculates maximum light range based on light intensity.