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

Class which manages distributing shadow maps in an atlas. More...

#include "shadowAtlas.h"

Public Member Functions

 ShadowAtlas (size_t size, size_t tile_size=32)
 Constructs a new shadow atlas. More...
 
 ~ShadowAtlas ()
 Destructs the shadow atlas. More...
 
LVecBase4i find_and_reserve_region (size_t tile_width, size_t tile_height)
 Finds space for a map of the given size in the atlas. More...
 
void free_region (const LVecBase4i &region)
 Frees a given region. More...
 
float get_coverage () const
 
int get_num_used_tiles () const
 
int get_required_tiles (size_t resolution) const
 Returns the amount of tiles required to store a resolution. More...
 
int get_tile_size () const
 RenderPipeline. More...
 
LVecBase4 region_to_uv (const LVecBase4i &region)
 Converts a tile-space region to uv space. More...
 

Public Attributes

 get_coverage
 Returns the amount of used tiles in percentage. More...
 
 get_num_used_tiles
 Returns the amount of used tiles. More...
 

Detailed Description

Class which manages distributing shadow maps in an atlas.

This class manages the shadow atlas. It handles finding and reserving space for new shadow maps.

Definition at line 41 of file shadowAtlas.h.

Constructor & Destructor Documentation

◆ ShadowAtlas()

ShadowAtlas::ShadowAtlas ( size_t  size,
size_t  tile_size = 32 
)

Constructs a new shadow atlas.

This constructs a new shadow atlas with the given size and tile size.

The size determines the total size of the atlas in pixels. It should be a power-of-two to favour the GPU.

The tile_size determines the smallest unit of tiles the atlas can store. If, for example, a tile_size of 32 is used, then every entry stored must have a resolution of 32 or greater, and the resolution must be a multiple of 32. This is to optimize the search in the atlas, so the atlas does not have to check every pixel, and instead can just check whole tiles.

If you want to disable the use of tiles, set the tile_size to 1, which will make the shadow atlas use pixels instead of tiles.

Parameters
sizeAtlas-size in pixels
tile_sizetile-size in pixels, or 1 to use no tiles.

Definition at line 52 of file shadowAtlas.cxx.

◆ ~ShadowAtlas()

ShadowAtlas::~ShadowAtlas ( )

Destructs the shadow atlas.

This destructs the shadow atlas, freeing all used resources.

Definition at line 65 of file shadowAtlas.cxx.

Member Function Documentation

◆ find_and_reserve_region()

LVecBase4i ShadowAtlas::find_and_reserve_region ( size_t  tile_width,
size_t  tile_height 
)

Finds space for a map of the given size in the atlas.

This methods searches for a space to store a region of the given size in the atlas. tile_width and tile_height should be already in tile space. They can be converted using ShadowAtlas::get_required_tiles.

If no region is found, or an invalid size is passed, an integer vector with all components set to -1 is returned.

If a region is found, an integer vector with the given layout is returned: x: x- Start of the region y: y- Start of the region z: width of the region w: height of the region

The layout is in tile space, and can get converted to uv space using ShadowAtlas::region_to_uv.

Parameters
tile_widthWidth of the region in tile space
tile_heightHeight of the region in tile space
Returns
Region, see description, or -1 when no region is found.

Definition at line 130 of file shadowAtlas.cxx.

◆ free_region()

void ShadowAtlas::free_region ( const LVecBase4i &  region)

Frees a given region.

This frees a given region, marking it as free so that other shadow maps can use the space again. The region should be the same as returned by ShadowAtlas::find_and_reserve_region.

If an invalid region is passed, an assertion is triggered. If assertions are compiled out, undefined behaviour will occur.

Parameters
regionRegion to free

Definition at line 173 of file shadowAtlas.cxx.

◆ get_required_tiles()

int ShadowAtlas::get_required_tiles ( size_t  resolution) const
inline

Returns the amount of tiles required to store a resolution.

Returns the amount of tiles which would be required to store a given resolution. This basically just returns resolution / tile_size.

When an invalid resolution is passed (not a multiple of the tile size), an error is printed and 1 is returned. When a negative or zero resolution is passed, undefined behaviour occurs.

Parameters
resolutionThe resolution to compute the amount of tiles for
Returns
Amount of tiles to store the resolution

Definition at line 116 of file shadowAtlas.I.

◆ get_tile_size()

int ShadowAtlas::get_tile_size ( ) 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 tile size of the atlas.

This returns the tile size of the atlas, which was set in the constructor. This is the smalles unit of the atlas, and every resolution has to be a multiple of the tile size.

Returns
Tile size in pixels

Definition at line 35 of file shadowAtlas.I.

◆ region_to_uv()

LVecBase4 ShadowAtlas::region_to_uv ( const LVecBase4i &  region)
inline

Converts a tile-space region to uv space.

This converts a region (presumably from ShadowAtlas::find_and_reserve_region) to uv space (0 .. 1 range). This can be used in shaders, since they expect floating point coordinates instead of integer coordinates.

Parameters
regiontile-space region
Returns
uv-space region

Definition at line 136 of file shadowAtlas.I.

Member Data Documentation

◆ get_coverage

float ShadowAtlas::get_coverage
inline

Returns the amount of used tiles in percentage.

This returns in percentage from 0 to 1 how much space of the atlas is used right now. A value of 1 means the atlas is completely full, whereas a value of 0 means the atlas is completely free.

Returns
Atlas usage in percentage

Definition at line 50 of file shadowAtlas.h.

◆ get_num_used_tiles

int ShadowAtlas::get_num_used_tiles
inline

Returns the amount of used tiles.

Returns the amount of used tiles in the atlas

Returns
Amount of used tiles

Definition at line 49 of file shadowAtlas.h.


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