struct mrpt::viz::TLight

Python API: mrpt.viz.TLight

Overview

A single light source (directional, point, or spot).

#include <mrpt/viz/TLightParameters.h>

struct TLight
{
    // fields

    TLightType type = TLightType::Directional;
    mrpt::img::TColorf color = {1.0f, 1.0f, 1.0f};
    float diffuse = 0.8f;
    float specular = 0.95f;
    mrpt::math::TVector3Df direction = {-0.40825f, -0.40825f, -0.81650f};
    mrpt::math::TPoint3Df position = {0, 0, 0};
    float attenuation_constant = 1.0f;
    float attenuation_linear = 0.09f;
    float attenuation_quadratic = 0.032f;
    float range = 0;
    bool cast_shadows = false;
    float spot_inner_cutoff_deg = 12.5f;
    float spot_outer_cutoff_deg = 17.5f;

    // methods

    static TLight Directional(
        const mrpt::math::TVector3Df& dir,
        const mrpt::img::TColorf& color = {1.0f, 1.0f, 1.0f},
        float diffuse = 0.8f,
        float specular = 0.95f
        );

    static TLight PointLight(
        const mrpt::math::TPoint3Df& pos,
        const mrpt::img::TColorf& color = {1.0f, 1.0f, 1.0f},
        float diffuse = 0.8f,
        float specular = 0.95f,
        float att_constant = 1.0f,
        float att_linear = 0.09f,
        float att_quadratic = 0.032f,
        float range = 0
        );

    static TLight SpotLight(
        const mrpt::math::TPoint3Df& pos,
        const mrpt::math::TVector3Df& dir,
        float innerCutoffDeg = 12.5f,
        float outerCutoffDeg = 17.5f,
        const mrpt::img::TColorf& color = {1.0f, 1.0f, 1.0f},
        float diffuse = 0.8f,
        float specular = 0.95f,
        float att_constant = 1.0f,
        float att_linear = 0.09f,
        float att_quadratic = 0.032f,
        float range = 0
        );

    void writeToStream(mrpt::serialization::CArchive& out) const;
    void readFromStream(mrpt::serialization::CArchive& in);
};

Fields

mrpt::img::TColorf color = {1.0f, 1.0f, 1.0f}

Light color.

float diffuse = 0.8f

Diffuse intensity [0,1].

float specular = 0.95f

Specular intensity [0,1].

mrpt::math::TVector3Df direction = {-0.40825f, -0.40825f, -0.81650f}

Direction vector (must be normalized).

Used by Directional and Spot.

mrpt::math::TPoint3Df position = {0, 0, 0}

Position in world coordinates.

Used by Point and Spot.

float attenuation_constant = 1.0f

Attenuation factors for Point/Spot: intensity = 1 / (constant + linear*d + quadratic*d²).

Ignored for Directional.

float range = 0

Maximum reach of Point/Spot lights [meters]: the attenuation is multiplied by a smooth window that reaches exactly zero at this distance, so the light does not affect anything farther away.

0 (default) means unlimited reach. Ignored for Directional.

bool cast_shadows = false

Whether this Point/Spot light casts shadows (default: false).

Each one renders the scene into a cube shadow map (six depth passes, cached while nothing within its reach changes), so enable it only for the lights that matter. Only the first MAX_SHADOW_POINT_LIGHTS such lights cast shadows, and only in viewports with shadow casting enabled. Set a range too, which limits the shadow passes to nearby objects. Directional lights ignore this flag: the first one always casts shadows.

See also:

TLightParameters::point_shadow_map_size

float spot_inner_cutoff_deg = 12.5f

Spot light inner cutoff angle in degrees (full intensity cone).

float spot_outer_cutoff_deg = 17.5f

Spot light outer cutoff angle in degrees (light fades to zero).

Methods

static TLight Directional(
    const mrpt::math::TVector3Df& dir,
    const mrpt::img::TColorf& color = {1.0f, 1.0f, 1.0f},
    float diffuse = 0.8f,
    float specular = 0.95f
    )

Factory: creates a directional light.

static TLight PointLight(
    const mrpt::math::TPoint3Df& pos,
    const mrpt::img::TColorf& color = {1.0f, 1.0f, 1.0f},
    float diffuse = 0.8f,
    float specular = 0.95f,
    float att_constant = 1.0f,
    float att_linear = 0.09f,
    float att_quadratic = 0.032f,
    float range = 0
    )

Factory: creates a point light.

static TLight SpotLight(
    const mrpt::math::TPoint3Df& pos,
    const mrpt::math::TVector3Df& dir,
    float innerCutoffDeg = 12.5f,
    float outerCutoffDeg = 17.5f,
    const mrpt::img::TColorf& color = {1.0f, 1.0f, 1.0f},
    float diffuse = 0.8f,
    float specular = 0.95f,
    float att_constant = 1.0f,
    float att_linear = 0.09f,
    float att_quadratic = 0.032f,
    float range = 0
    )

Factory: creates a spot light.