Panda3D
Public Member Functions | Public Attributes | List of all members
InternalLightManager Class Reference

Internal class used for handling lights and shadows. More...

Public Member Functions

 __init__ ()
 Constructs the light manager. More...
 
 __init__ (const InternalLightManager)
 
 addLight (RPLight light)
 Adds a new light. More...
 
int getMaxLightIndex ()
 Returns the maximum light index. More...
 
int getNumLights ()
 Returns the amount of stored lights. More...
 
int getNumShadowSources ()
 Returns the amount of shadow sources. More...
 
ShadowManager getShadowManager ()
 Returns the internal used ShadowManager. More...
 
 removeLight (RPLight light)
 Removes a light. More...
 
 setCameraPos (const LPoint3 pos)
 Sets the camera position. More...
 
 setCommandList (GPUCommandList cmd_list)
 Sets a handle to the command list. More...
 
 setShadowManager (ShadowManager mgr)
 Sets the handle to the shadow manager. More...
 
 setShadowUpdateDistance (float dist)
 Sets the maximum shadow update distance. More...
 
 update ()
 Main update method. More...
 

Public Attributes

int max_light_index
 Returns the maximum light index. More...
 
int num_lights
 Returns the amount of stored lights. More...
 
int num_shadow_sources
 Returns the amount of shadow sources. More...
 
ShadowManager shadow_manager
 Returns the internal used ShadowManager. More...
 

Detailed Description

Internal class used for handling lights and shadows.

This is the internal class used by the pipeline to handle all lights and shadows. It stores references to the lights, manages handling the light and shadow slots, and also communicates with the GPU with the GPUCommandQueue to store light and shadow source data.

Member Function Documentation

◆ __init__() [1/2]

__init__ ( )

Constructs the light manager.

This constructs the light manager, initializing the light and shadow storage. You should set a command list and shadow manager before calling InternalLightManager::update. s

◆ __init__() [2/2]

__init__ ( const  InternalLightManager)

◆ addLight()

addLight ( RPLight  light)

Adds a new light.

This adds a new light to the list of lights. This will throw an error and return if the light is already attached. You may only call this after the ShadowManager was already set.

While the light is attached, the light manager keeps a reference to it, so the light does not get destructed.

This also setups the shadows on the light, in case shadows are enabled. While a light is attached, you can not change whether it casts shadows or not. To do so, detach the light, change the setting, and re-add the light.

In case no free light slot is available, an error will be printed and no action will be performed.

If no shadow manager was set, an assertion will be triggered.

Parameters
lightThe light to add.

◆ getMaxLightIndex()

int getMaxLightIndex ( )

Returns the maximum light index.

This returns the maximum light index (also called slot). Any lights after that slot are guaranteed to be zero-lights. This is useful when iterating over the list of lights, because iteration can be stopped when the maximum light index is reached.

The maximum light index points to the last slot which is used. If no lights are attached, -1 is returned. If one light is attached at slot 0, the index is 0, if two are attached at the slots 0 and 1, the index is 1, and so on.

If, for example, two lights are attached at the slots 2 and 5, then the index will be 5. Keep in mind that the max-index is not an indicator for how many lights are attached. Also, zero lights still may occur when iterating over the light lists

Returns
Maximum light index

◆ getNumLights()

int getNumLights ( )

Returns the amount of stored lights.

This returns the amount of stored lights. This behaves unlike InternalLightManager::get_max_light_index, and instead returns the true amount of lights, which is completely unrelated to the amount of used slots.

Returns
Amount of stored lights

◆ getNumShadowSources()

int getNumShadowSources ( )

Returns the amount of shadow sources.

This returns the total amount of stored shadow sources. This does not denote the amount of updated sources, but instead takes into account all sources, even those out of frustum.

Returns
Amount of shadow sources.

◆ getShadowManager()

ShadowManager getShadowManager ( )

Returns the internal used ShadowManager.

This returns a handle to the internally used shadow manager

Returns
Shadow manager

◆ removeLight()

removeLight ( RPLight  light)

Removes a light.

This detaches a light. This prevents it from being rendered, and also cleans up all resources used by that light. If no reference is kept on the python side, the light will also get destructed.

If the light was not previously attached with InternalLightManager::add_light, an error will be triggered and nothing happens.

In case the light was set to cast shadows, all shadow sources are cleaned up, and their regions in the shadow atlas are freed.

All resources used by the light in the light and shadow storage are also cleaned up, by emitting cleanup GPUCommands.

If no shadow manager was set, an assertion will be triggered.

Parameters
light[description]

◆ setCameraPos()

setCameraPos ( const LPoint3  pos)

Sets the camera position.

This sets the camera position, which will be used to determine which shadow sources have to get updated

Parameters
matView projection mat

◆ setCommandList()

setCommandList ( GPUCommandList  cmd_list)

Sets a handle to the command list.

This sets a handle to the global GPUCommandList. This is required to emit GPUCommands, which are used for attaching and detaching lights, as well as shadow source updates.

The cmd_list should be a handle to a GPUCommandList handle, and will be stored somewhere on the python side most likely. The light manager does not keep a reference to it, so the python side should make sure to keep one.

Be sure to call this before the InternalLightManager::update() method is called, otherwise an assertion will get triggered.

Parameters
cmd_listThe GPUCommandList instance

◆ setShadowManager()

setShadowManager ( ShadowManager  mgr)

Sets the handle to the shadow manager.

This sets the handle to the global shadow manager. It is usually constructed on the python side, so we need to get a handle to it.

The manager should be a handle to a ShadowManager instance, and will be stored somewhere on the python side most likely. The light manager does not keep a reference to it, so the python side should make sure to keep one.

Be sure to call this before the InternalLightManager::update() method is called, otherwise an assertion will get triggered.

Parameters
mgrThe ShadowManager instance

◆ setShadowUpdateDistance()

setShadowUpdateDistance ( float  dist)

Sets the maximum shadow update distance.

This controls the maximum distance until which shadows are updated. If a shadow source is past that distance, it is ignored and no longer recieves updates until it is in range again

Parameters
distDistance in world space units

◆ update()

update ( )

Main update method.

This is the main update method of the InternalLightManager. It processes all lights and shadow sources, updates them, and notifies the GPU about it. This should be called on a per-frame basis.

If the InternalLightManager was not initialized yet, an assertion is thrown.

Member Data Documentation

◆ max_light_index

int max_light_index

Returns the maximum light index.

This returns the maximum light index (also called slot). Any lights after that slot are guaranteed to be zero-lights. This is useful when iterating over the list of lights, because iteration can be stopped when the maximum light index is reached.

The maximum light index points to the last slot which is used. If no lights are attached, -1 is returned. If one light is attached at slot 0, the index is 0, if two are attached at the slots 0 and 1, the index is 1, and so on.

If, for example, two lights are attached at the slots 2 and 5, then the index will be 5. Keep in mind that the max-index is not an indicator for how many lights are attached. Also, zero lights still may occur when iterating over the light lists

Returns
Maximum light index

◆ num_lights

int num_lights

Returns the amount of stored lights.

This returns the amount of stored lights. This behaves unlike InternalLightManager::get_max_light_index, and instead returns the true amount of lights, which is completely unrelated to the amount of used slots.

Returns
Amount of stored lights

◆ num_shadow_sources

int num_shadow_sources

Returns the amount of shadow sources.

This returns the total amount of stored shadow sources. This does not denote the amount of updated sources, but instead takes into account all sources, even those out of frustum.

Returns
Amount of shadow sources.

◆ shadow_manager

ShadowManager shadow_manager

Returns the internal used ShadowManager.

This returns a handle to the internally used shadow manager

Returns
Shadow manager