Panda3D
Public Member Functions | List of all members
ShadowSource Class Reference

RenderPipeline. More...

#include "shadowSource.h"

Public Member Functions

 ShadowSource ()
 RenderPipeline. More...
 
void clear_region ()
 Clears the assigned region of the source. More...
 
const BoundingSphereget_bounds () const
 Returns the shadow sources bounds. More...
 
const LMatrix4 & get_mvp () const
 Returns the View-Projection matrix of the source. More...
 
bool get_needs_update () const
 RenderPipeline. More...
 
const LVecBase4i & get_region () const
 Returns the assigned region of the source in atlas space. More...
 
size_t get_resolution () const
 Returns the resolution of the source. More...
 
int get_slot () const
 Returns the slot of the shadow source. More...
 
const LVecBase4 & get_uv_region () const
 Returns the assigned region of the source in UV space. More...
 
bool has_region () const
 Returns whether the source has a valid region. More...
 
bool has_slot () const
 Returns whether the source has a slot. More...
 
void set_matrix_lens (const LMatrix4 &mvp)
 Sets a custom matrix for the source. More...
 
void set_needs_update (bool flag)
 Sets the update flag of the source. More...
 
void set_perspective_lens (PN_stdfloat fov, PN_stdfloat near_plane, PN_stdfloat far_plane, LVecBase3 pos, LVecBase3 direction)
 Setups a perspective lens for the source. More...
 
void set_region (const LVecBase4i &region, const LVecBase4 &region_uv)
 Sets the assigned region of the source in atlas and uv space. More...
 
void set_resolution (size_t resolution)
 Sets the resolution of the source. More...
 
void set_slot (int slot)
 Assigns the source a slot. More...
 
void write_to_command (GPUCommand &cmd) const
 Writes the source to a GPUCommand. More...
 

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. This class represents a single shadow source.

The ShadowSource can be seen as a Camera. It is used by the Lights to render their shadows. Each ShadowSource has a position in the atlas, and a view-projection matrix. The shadow manager regenerates the shadow maps using the data from the shadow sources.

Definition at line 51 of file shadowSource.h.

Constructor & Destructor Documentation

◆ ShadowSource()

ShadowSource::ShadowSource ( )

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 shadow source

This constructs a new shadow source, with no projection setup, and no slot assigned.

Definition at line 34 of file shadowSource.cxx.

Member Function Documentation

◆ clear_region()

void ShadowSource::clear_region ( )
inline

Clears the assigned region of the source.

This unassigns any shadow atlas region from the source, previously set with set_region

Definition at line 259 of file shadowSource.I.

◆ get_bounds()

const BoundingSphere & ShadowSource::get_bounds ( ) const
inline

Returns the shadow sources bounds.

This returns the bounds of the shadow source, approximated as a sphere

Returns
Bounds as a BoundingSphere

Definition at line 250 of file shadowSource.I.

◆ get_mvp()

const LMatrix4 & ShadowSource::get_mvp ( ) const
inline

Returns the View-Projection matrix of the source.

This returns the current view-projection matrix of the ShadowSource. If no matrix was set yet, returns a matrix with all components zero. If a matrix was set with ShadowSource::set_matrix_lens, returns the matrix set by that function call.

If a matrix was set with ShadowSource::set_perspective_lens, returns a perspective view-projection matrix setup by those parameters.

The matrix returned is the matrix used for rendering the shadow map, and includes the camera transform as well as the projection matrix.

Returns
View-Projection matrix.

Definition at line 214 of file shadowSource.I.

◆ get_needs_update()

bool ShadowSource::get_needs_update ( ) 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 whether the shadow source needs an update.

This returns the update flag, which was previously set with ShadowSource::set_needs_update. If the value is true, it means that the ShadowSource is invalid and should be regenerated. This can either be the case because the scene changed and affected the shadow source, or the light moved.

Returns
Update-Flag

Definition at line 38 of file shadowSource.I.

References has_region().

◆ get_region()

const LVecBase4i & ShadowSource::get_region ( ) const
inline

Returns the assigned region of the source in atlas space.

This returns the region of the source, in atlas space. This is the region set by ShadowSource::set_region. If no region was set yet, returns a 4-component integer vector with all components set to -1. To check this, you should call ShadowSource::has_region() first.

Returns
[description]

Definition at line 165 of file shadowSource.I.

◆ get_resolution()

size_t ShadowSource::get_resolution ( ) const
inline

Returns the resolution of the source.

Returns the shadow map resolution of source, in pixels. This is the space the source takes in the shadow atlas, in pixels.

Returns
Resolution in pixels

Definition at line 152 of file shadowSource.I.

◆ get_slot()

int ShadowSource::get_slot ( ) const
inline

Returns the slot of the shadow source.

This returns the assigned slot of the ShadowSource, or -1 if no slot was assigned yet. You can check if a slot exists with ShadowSource::has_slot. The slot is the index of the ShadowSource in the global source buffer.

Returns
Slot, or -1 to indicate no slot.

Definition at line 49 of file shadowSource.I.

◆ get_uv_region()

const LVecBase4 & ShadowSource::get_uv_region ( ) const
inline

Returns the assigned region of the source in UV space.

This returns the region of the source, in UV space. This is the region set by ShadowSource::set_region. If no region was set yet, returns a 4-component integer vector with all components set to -1. To check this, you should call ShadowSource::has_region() first.

Returns
[description]

Definition at line 178 of file shadowSource.I.

◆ has_region()

bool ShadowSource::has_region ( ) const
inline

Returns whether the source has a valid region.

This returns whether the ShadowSource has a valid shadow atlas region assigned. This might be not the case when the source never was rendered yet, or is about to get updated.

Returns
true if the source has a valid region, else false.

Definition at line 142 of file shadowSource.I.

Referenced by get_needs_update().

◆ has_slot()

bool ShadowSource::has_slot ( ) const
inline

Returns whether the source has a slot.

This returns whether the ShadowSource currently has an assigned slot. If the source has a slot assigned, this returns true, otherwise false. Cases where the source has no slot might be when the source just got attached, but never got rendered yet.

Returns
[description]

Definition at line 61 of file shadowSource.I.

◆ set_matrix_lens()

void ShadowSource::set_matrix_lens ( const LMatrix4 &  mvp)
inline

Sets a custom matrix for the source.

This tells the source to use a custom matrix for rendering, just like the matrix lens. The matrix should include all transformations, rotations and scales. No other matrices will be used for rendering this shadow source (not even a coordinate system conversion).

Parameters
mvpCustom View-Projection matrix

Definition at line 117 of file shadowSource.I.

References set_needs_update().

Referenced by set_perspective_lens().

◆ set_needs_update()

void ShadowSource::set_needs_update ( bool  flag)
inline

Sets the update flag of the source.

Sets whether the source is still valid, or needs to get regenerated. Usually you only want to flag the shadow source as invalid, by passing true as the flag. However, the ShadowManager will set the flag to false after updating the source.

Parameters
flagThe update flag

Definition at line 131 of file shadowSource.I.

Referenced by set_matrix_lens().

◆ set_perspective_lens()

void ShadowSource::set_perspective_lens ( PN_stdfloat  fov,
PN_stdfloat  near_plane,
PN_stdfloat  far_plane,
LVecBase3  pos,
LVecBase3  direction 
)
inline

Setups a perspective lens for the source.

This makes the shadow source behave like a perspective lens. The parameters are similar to the ones of a PerspectiveLens.

Parameters
fovFoV of the lens
near_planeThe near plane of the lens, to avoid artifacts at low distance
far_planeThe far plane of the lens
posPosition of the lens, in world space
directionDirection (Orientation) of the lens

Definition at line 89 of file shadowSource.I.

References Lens::get_projection_mat(), Lens::set_film_offset, set_matrix_lens(), Lens::set_near_far(), and Lens::set_view_vector().

◆ set_region()

void ShadowSource::set_region ( const LVecBase4i &  region,
const LVecBase4 &  region_uv 
)
inline

Sets the assigned region of the source in atlas and uv space.

This sets the assigned region of the ShadowSource. The region in atlas space should be the region returned from the ShadowAtlas::find_and_reserve_region. The uv-region should be the same region, but in the 0 .. 1 range (can be converted with ShadowAtlas::region_to_uv). This is required for the shaders, because they expect coordinates in the 0 .. 1 range for sampling.

Parameters
regionAtlas-Space region
region_uvUV-Space region

Definition at line 194 of file shadowSource.I.

◆ set_resolution()

void ShadowSource::set_resolution ( size_t  resolution)
inline

Sets the resolution of the source.

This sets the resolution of the ShadowSource, in pixels. It should be a multiple of the tile size of the ShadowAtlas, and greater than zero.

Parameters
resolution[description]

Definition at line 239 of file shadowSource.I.

◆ set_slot()

void ShadowSource::set_slot ( int  slot)
inline

Assigns the source a slot.

This assigns a slot to the ShadowSource. This is called from the ShadowManager, when the source gets attached first time. This should not get called by the user.

Parameters
slotSlot of the source, or -1 to indicate no slot.

Definition at line 73 of file shadowSource.I.

◆ write_to_command()

void ShadowSource::write_to_command ( GPUCommand cmd) const
inline

Writes the source to a GPUCommand.

This writes the ShadowSource to a GPUCommand. This stores the mvp and the uv-region in the command.

Parameters
cmdGPUCommand to write to.

Definition at line 225 of file shadowSource.I.


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