RPLight

class RPLight

Bases: ReferenceCount

This is the base class for all lights in the render pipeline. It stores common properties, and provides methods to modify these. It also defines some interface functions which subclasses have to implement.

Inheritance diagram

Inheritance diagram of RPLight

enum LightType

Different types of light.

enumerator LT_empty = 0
enumerator LT_point_light = 1
enumerator LT_spot_light = 2
void clear_ies_profile(void)

This clears the IES profile of the light, telling it to no longer use an IES profile, and instead use the default attenuation.

bool get_casts_shadows(void) const

This returns whether the light casts shadows, the returned value is the one previously set with RPLight::set_casts_shadows().

LVecBase3 const &get_color(void) const

This returns the light color, previously set with RPLight::set_color(). This does not include the energy of the light. It might differ from what was set with set_color, because the color is normalized by dividing it by its luminance.

float get_energy(void) const

This returns the energy of the light, previously set with RPLight::set_energy().

int get_ies_profile(void) const

This returns the IES profile of a light, previously set with RPLight::set_ies_profile(). In case no ies profile was set, returns -1.

LightType get_light_type(void) const

This returns the internal type of the light, which was specified in the lights constructor. This can be used to distinguish between light types.

float get_near_plane(void) const

This returns the light’s near plane, previously set with RPLight::set_near_plane(). If the light does not cast shadows, this value is meaningless.

LVecBase3 const &get_pos(void) const

This returns the position of the light previously set with RPLight::set_pos(). The returned position is in world space.

std::size_t get_shadow_map_resolution(void) const

This returns the shadow map resolution of each source of the light. If the light is not setup to cast shadows, this value is meaningless. The returned value is the one previously set with RPLight::set_shadow_map_resolution().

bool has_ies_profile(void) const

This returns whether the light has an IES profile assigned, previously done with RPLight::set_ies_profile().

void invalidate_shadows(void)

This invalidates all shadows of the light, causing them to get regenerated. This might be the case when the lights position or similar changed. This will cause all shadow sources to be updated, emitting a shadow update. Be careful when calling this method if you don’t want all sources to get updated. If you only have to invalidate a single shadow source, use get_shadow_source(n)->set_needs_update(true).

void set_casts_shadows(bool flag = true)

This sets whether the light casts shadows. You can not change this while the light is attached. When flag is set to true, the light will be setup to cast shadows, spawning shadow sources based on the lights type. If the flag is set to false, the light will be inddicated to cast no shadows.

void set_color(LVecBase3 const &color)
void set_color(float r, float g, float b)

This sets the lights color. The color should not include the brightness of the light, you should control that with the energy. The color specifies the lights “tint” and will get multiplied with its specular and diffuse contribution.

The color will be normalized by dividing by the colors luminance. Setting higher values than 1.0 will have no effect.

@copydetails RPLight::set_color(const LVecBase3 &color)

void set_color_from_temperature(float temperature)

This sets the lights color, given a temperature. This is more physically based than setting a user defined color. The color will be computed from the given temperature.

void set_energy(float energy)

This sets the energy of the light, which can be seen as the brightness of the light. It will get multiplied with the normalized color.

void set_ies_profile(int profile)

This sets the ies profile of the light. The parameter should be a handle previously returned by RenderPipeline.load_ies_profile. Using a value of -1 indicates no ies profile.

Notice that for IES profiles which cover a whole range, you should use an RPPointLight, whereas for ies profiles which only cover the lower hemisphere you should use an RPSpotLight for the best performance.

void set_near_plane(float near_plane)

This sets the near plane of all shadow sources of the light. It has no effects if the light does not cast shadows. This prevents artifacts from objects near to the light. It behaves like Lens::set_near().

It can also help increasing shadow map precision, low near planes will cause the precision to suffer. Try setting the near plane as big as possible.

If a negative or zero near plane is passed, an assertion is thrown.

void set_pos(LVecBase3 const &pos)
void set_pos(float x, float y, float z)

This sets the position of the light in world space. It will cause the light to get invalidated, and resubmitted to the GPU.

@copydetails RPLight::set_pos(const LVecBase3 &pos)

void set_shadow_map_resolution(std::size_t resolution)

This sets the light’s shadow map resolution. This has no effect when the light is not told to cast shadows (Use RPLight::set_casts_shadows()).

When calling this on a light with multiple shadow sources (e.g. RPPointLight), this controls the resolution of each source. If the light has 6 shadow sources, and you use a resolution of 512x512, the light’s shadow map will occupy a space of 6 * 512x512 maps in the shadow atlas.