Panda3D
Public Types | Public Member Functions | Public Attributes | List of all members
RPLight Class Referenceabstract

RenderPipeline. More...

#include "rpLight.h"

Inheritance diagram for RPLight:
ReferenceCount MemoryBase RPPointLight RPSpotLight

Public Types

enum  LightType { LT_empty = 0, LT_point_light = 1, LT_spot_light = 2 }
 Different types of light. More...
 

Public Member Functions

 RPLight (LightType light_type)
 RenderPipeline. More...
 
virtual ~RPLight ()
 Light destructor. More...
 
void assign_slot (int slot)
 Assigns a slot to the light. More...
 
void clear_ies_profile ()
 
void clear_shadow_sources ()
 Clears all shadow source. More...
 
bool get_casts_shadows () const
 
const LVecBase3 & get_color () const
 
float get_energy () const
 
int get_ies_profile () const
 
LightType get_light_type () const
 
float get_near_plane () const
 
bool get_needs_update () const
 Returns whether the light needs an update. More...
 
size_t get_num_shadow_sources () const
 RenderPipeline. More...
 
const LVecBase3 & get_pos () const
 
size_t get_shadow_map_resolution () const
 
ShadowSourceget_shadow_source (size_t index) const
 Returns the n-th shadow source. More...
 
int get_slot () const
 Returns the slot of the light. More...
 
bool has_ies_profile () const
 
bool has_slot () const
 Returns whether the light has a slot. More...
 
virtual void init_shadow_sources ()=0
 
void invalidate_shadows ()
 Invalidates the shadows. More...
 
void remove_slot ()
 Removes the light slot. More...
 
void set_casts_shadows (bool flag=true)
 
void set_color (const LVecBase3 &color)
 
void set_color (float r, float g, float b)
 
void set_color_from_temperature (float temperature)
 Sets the lights color from a given color temperature. More...
 
void set_energy (float energy)
 
void set_ies_profile (int profile)
 
void set_near_plane (float near_plane)
 
void set_needs_update (bool flag)
 Sets whether the light needs an update. More...
 
void set_pos (const LVecBase3 &pos)
 
void set_pos (float x, float y, float z)
 
void set_shadow_map_resolution (size_t resolution)
 
virtual void update_shadow_sources ()=0
 
virtual void write_to_command (GPUCommand &cmd)
 Writes the light to a GPUCommand. More...
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object. More...
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More...
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More...
 
void ref () const
 Explicitly increments the reference count. More...
 
bool ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. More...
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
virtual bool unref () const
 Explicitly decrements the reference count. More...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 

Public Attributes

 clear_ies_profile
 Clears the ies profile. More...
 
 get_casts_shadows
 Returns whether the light casts shadows. More...
 
 get_color
 Returns the lights color. More...
 
 get_energy
 Returns the energy of the light. More...
 
 get_ies_profile
 Returns the lights ies profile. More...
 
 get_light_type
 Returns the type of the light. More...
 
 get_near_plane
 Returns the near plane of the light. More...
 
 get_pos
 Returns the position of the light. More...
 
 get_shadow_map_resolution
 Returns the shadow map resolution. More...
 
 has_ies_profile
 Returns whether the light has an ies profile assigned. More...
 
 set_casts_shadows
 Controls whether the light casts shadows. More...
 
 set_color
 Sets the lights color. More...
 
 set_energy
 Sets the energy of the light. More...
 
 set_ies_profile
 Sets the ies profile. More...
 
 set_near_plane
 Sets the near plane of the light. More...
 
 set_pos
 Sets the position of the light. More...
 
 set_shadow_map_resolution
 Sets the lights shadow map resolution. More...
 
- Public Attributes inherited from ReferenceCount
 get_ref_count
 Returns the current reference count. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 

Detailed Description

RenderPipeline.

Copyright (c) 2014-2016 tobspr tobia.nosp@m.s.sp.nosp@m.ringe.nosp@m.r1@g.nosp@m.mail..nosp@m.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Base class for Lights

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.

Definition at line 41 of file rpLight.h.

Member Enumeration Documentation

◆ LightType

Different types of light.

Definition at line 46 of file rpLight.h.

Constructor & Destructor Documentation

◆ RPLight()

RPLight::RPLight ( LightType  light_type)

RenderPipeline.

Copyright (c) 2014-2016 tobspr tobia.nosp@m.s.sp.nosp@m.ringe.nosp@m.r1@g.nosp@m.mail..nosp@m.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Constructs a new light with the given type

This constructs a new base light with the given light type. Sub-Classes should call this to initialize all properties.

Parameters
light_typeType of the light

Definition at line 38 of file rpLight.cxx.

◆ ~RPLight()

RPLight::~RPLight ( )
virtual

Light destructor.

This destructs the light, cleaning up all resourced used. The light should be detached at this point, because while the Light is attached, the InternalLightManager holds a reference to prevent it from being destructed.

Definition at line 90 of file rpLight.cxx.

Member Function Documentation

◆ assign_slot()

void RPLight::assign_slot ( int  slot)
inline

Assigns a slot to the light.

This assigns a slot to the light, marking it as attached. The slot relates to the index in the GPU's storage of lights. This is an internal method called by the InternalLightManager when the light got attached.

Parameters
slotSlot of the light

Definition at line 140 of file rpLight.I.

◆ clear_shadow_sources()

void RPLight::clear_shadow_sources ( )
inline

Clears all shadow source.

This removes and destructs all shadow sources attached to this light. This usually gets called when the light gets detached or destructed. All shadows sources are freed, and then removed from the shadow source list.

Definition at line 60 of file rpLight.I.

◆ get_needs_update()

bool RPLight::get_needs_update ( ) const
inline

Returns whether the light needs an update.

This returns whether the light needs an update. This might be the case when a property of the light was changed, e.g. position or color. It does not affect the shadows, you have to query the update flag of each individual source for that. The return value is the value previously set with RPLight::set_needs_update.

Returns
Update-flag

Definition at line 94 of file rpLight.I.

◆ get_num_shadow_sources()

size_t RPLight::get_num_shadow_sources ( ) const
inline

RenderPipeline.

Copyright (c) 2014-2016 tobspr tobia.nosp@m.s.sp.nosp@m.ringe.nosp@m.r1@g.nosp@m.mail..nosp@m.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Returns the amount of shadow sources

This returns the amount of shadow sources attached to this light. In case the light has no shadows enabled, or the light was not attached yet, this returns 0.

Returns
Amount of shadow sources

Definition at line 36 of file rpLight.I.

◆ get_shadow_source()

ShadowSource * RPLight::get_shadow_source ( size_t  index) const
inline

Returns the n-th shadow source.

This returns the n-th attached shadow source. This ranges from 0 .. RPLight::get_num_shadow_sources(). If an invalid index is passed, an assertion is thrown.

Parameters
indexIndex of the source
Returns
Handle to the shadow source

Definition at line 49 of file rpLight.I.

◆ get_slot()

int RPLight::get_slot ( ) const
inline

Returns the slot of the light.

This returns the slot of the light. This is the space on the GPU where the light is stored. If the light is not attached yet, this will return -1, otherwise the index of the light.

Returns
Light-Slot

Definition at line 118 of file rpLight.I.

◆ has_slot()

bool RPLight::has_slot ( ) const
inline

Returns whether the light has a slot.

This returns wheter the light currently is attached, and thus has a slot in the InternalLightManagers light list. When the light is attached, this returns true, otherwise it will return false.

Returns
true if the light has a slot, false otherwise

Definition at line 106 of file rpLight.I.

◆ invalidate_shadows()

void RPLight::invalidate_shadows ( )
inline

Invalidates the shadows.

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).

Definition at line 153 of file rpLight.I.

◆ remove_slot()

void RPLight::remove_slot ( )
inline

Removes the light slot.

This is an internal method to remove the slot of the light. It gets called by the InternalLightManager when a light gets detached. It internally sets the slot to -1 to indicate the light is no longer attached.

Definition at line 128 of file rpLight.I.

◆ set_color_from_temperature()

void RPLight::set_color_from_temperature ( float  temperature)

Sets the lights color from a given color 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.

Parameters
temperatureLight temperature

Definition at line 103 of file rpLight.cxx.

References set_color.

◆ set_needs_update()

void RPLight::set_needs_update ( bool  flag)
inline

Sets whether the light needs an update.

This controls whether the light needs to get an update. This is the case when a property of the light changed, e.g. position or color. It does not affect the shadows (For that use RPLight::invalidate_shadows()). When this flag is set to true, the light will get resubmitted to the GPU in the next update cycle.

You should usually never set the flag to false manually. The InternalLightManager will do this when the data got sucessfully updated.

Parameters
flagUpdate-Flag

Definition at line 80 of file rpLight.I.

◆ write_to_command()

void RPLight::write_to_command ( GPUCommand cmd)
virtual

Writes the light to a GPUCommand.

This writes all of the lights data to the given GPUCommand handle. Subclasses should first call this method, and then append their own data. This makes sure that for unpacking a light, no information about the type of the light is required.

Parameters
cmdThe GPUCommand to write to

Reimplemented in RPSpotLight, and RPPointLight.

Definition at line 60 of file rpLight.cxx.

References GPUCommand::push_int().

Referenced by RPPointLight::write_to_command(), and RPSpotLight::write_to_command().

Member Data Documentation

◆ clear_ies_profile

void RPLight::clear_ies_profile
inline

Clears the ies profile.

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

Definition at line 107 of file rpLight.h.

◆ get_casts_shadows

bool RPLight::get_casts_shadows
inline

Returns whether the light casts shadows.

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

Returns
true if the light casts shadows, false otherwise

Definition at line 96 of file rpLight.h.

◆ get_color

const LVecBase3 & RPLight::get_color
inline

Returns the lights color.

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.

Returns
Light-color

Definition at line 83 of file rpLight.h.

◆ get_energy

float RPLight::get_energy
inline

Returns the energy of the light.

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

Returns
energy of the light

Definition at line 89 of file rpLight.h.

◆ get_ies_profile

int RPLight::get_ies_profile
inline

Returns the lights ies profile.

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

Returns
IES Profile handle

Definition at line 107 of file rpLight.h.

◆ get_light_type

RPLight::LightType RPLight::get_light_type
inline

Returns the type of the light.

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

Returns
Type of the light

Definition at line 92 of file rpLight.h.

◆ get_near_plane

float RPLight::get_near_plane
inline

Returns the near plane of the light.

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

Returns
Near-plane

Definition at line 111 of file rpLight.h.

◆ get_pos

const LVecBase3 & RPLight::get_pos
inline

Returns the position of the light.

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

Returns
Light-position

Definition at line 78 of file rpLight.h.

◆ get_shadow_map_resolution

size_t RPLight::get_shadow_map_resolution
inline

Returns the shadow map resolution.

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.

Returns
Shadow map resolution in pixels

Definition at line 100 of file rpLight.h.

Referenced by RPSpotLight::update_shadow_sources().

◆ has_ies_profile

bool RPLight::has_ies_profile
inline

Returns whether the light has an ies profile assigned.

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

Returns
true if the light has an ies profile assigned, false otherwise

Definition at line 107 of file rpLight.h.

◆ set_casts_shadows

void RPLight::set_casts_shadows
inline

Controls whether the light casts shadows.

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.

Parameters
flagWhether the light casts shadows

Definition at line 96 of file rpLight.h.

◆ set_color

void RPLight::set_color
inline

Sets the lights color.

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.

Parameters
colorLight color
rRed-component of the color
gGreen-component of the color
bBlue-component of the color

Definition at line 83 of file rpLight.h.

Referenced by set_color_from_temperature().

◆ set_energy

void RPLight::set_energy
inline

Sets the energy of the light.

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.

Parameters
energyenergy of the light

Definition at line 89 of file rpLight.h.

◆ set_ies_profile

void RPLight::set_ies_profile
inline

Sets the ies 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 PointLights, whereas for ies profiles which only cover the lower hemisphere you should use SpotLights for the best performance.

Parameters
profileIES Profile handle

Definition at line 107 of file rpLight.h.

◆ set_near_plane

void RPLight::set_near_plane
inline

Sets the near plane of the light.

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_plane.

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.

Parameters
near_planeNear-plane

Definition at line 111 of file rpLight.h.

◆ set_pos

void RPLight::set_pos
inline

Sets the position of the light.

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

Parameters
posPosition in world space
xX-component of the position
yY-component of the position
zZ-component of the position

Definition at line 78 of file rpLight.h.

◆ set_shadow_map_resolution

void RPLight::set_shadow_map_resolution
inline

Sets the lights shadow map resolution.

This sets the lights 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. PointLight), this controls the resolution of each source. If the light has 6 shadow sources, and you use a resolution of 512x512, the lights shadow map will occur a space of 6 * 512x512 maps in the shadow atlas.

Parameters
resolutionResolution of the shadow map in pixels

Definition at line 100 of file rpLight.h.


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