Panda3D
shadowSource.h
1 /**
2  *
3  * RenderPipeline
4  *
5  * Copyright (c) 2014-2016 tobspr <tobias.springer1@gmail.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  */
26 
27 
28 #ifndef SHADOWSOURCE_H
29 #define SHADOWSOURCE_H
30 
31 #include "pandabase.h"
32 #include "luse.h"
33 #include "transformState.h"
34 #include "look_at.h"
35 #include "compose_matrix.h"
36 #include "perspectiveLens.h"
37 #include "boundingVolume.h"
38 #include "boundingSphere.h"
39 #include "boundingHexahedron.h"
41 
42 #include "gpuCommand.h"
43 
44 /**
45  * @brief This class represents a single shadow source.
46  * @details The ShadowSource can be seen as a Camera. It is used by the Lights
47  * to render their shadows. Each ShadowSource has a position in the atlas,
48  * and a view-projection matrix. The shadow manager regenerates the shadow maps
49  * using the data from the shadow sources.
50  */
51 class ShadowSource {
52 public:
53  ShadowSource();
54 
55  inline void write_to_command(GPUCommand &cmd) const;
56 
57  inline void set_needs_update(bool flag);
58  inline void set_slot(int slot);
59  inline void set_region(const LVecBase4i& region, const LVecBase4& region_uv);
60  inline void set_resolution(size_t resolution);
61  inline void set_perspective_lens(PN_stdfloat fov, PN_stdfloat near_plane,
62  PN_stdfloat far_plane, LVecBase3 pos,
63  LVecBase3 direction);
64  inline void set_matrix_lens(const LMatrix4& mvp);
65 
66  inline bool has_region() const;
67  inline bool has_slot() const;
68 
69  inline void clear_region();
70 
71  inline int get_slot() const;
72  inline bool get_needs_update() const;
73  inline size_t get_resolution() const;
74  inline const LMatrix4& get_mvp() const;
75  inline const LVecBase4i& get_region() const;
76  inline const LVecBase4& get_uv_region() const;
77 
78  inline const BoundingSphere& get_bounds() const;
79 
80 private:
81  int _slot;
82  bool _needs_update;
83  size_t _resolution;
84  LMatrix4 _mvp;
85  LVecBase4i _region;
86  LVecBase4 _region_uv;
87 
88  BoundingSphere _bounds;
89 };
90 
91 #include "shadowSource.I"
92 
93 #endif // SHADOWSOURCE_H
perspectiveLens.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ShadowSource::get_needs_update
bool get_needs_update() const
RenderPipeline.
Definition: shadowSource.I:38
BoundingSphere
This defines a bounding sphere, consisting of a center and a radius.
Definition: boundingSphere.h:25
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ShadowSource::ShadowSource
ShadowSource()
RenderPipeline.
Definition: shadowSource.cxx:34
ShadowSource::set_needs_update
void set_needs_update(bool flag)
Sets the update flag of the source.
Definition: shadowSource.I:131
ShadowSource::get_mvp
const LMatrix4 & get_mvp() const
Returns the View-Projection matrix of the source.
Definition: shadowSource.I:214
ShadowSource
RenderPipeline.
Definition: shadowSource.h:51
compose_matrix.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ShadowSource::has_region
bool has_region() const
Returns whether the source has a valid region.
Definition: shadowSource.I:142
ShadowSource::set_resolution
void set_resolution(size_t resolution)
Sets the resolution of the source.
Definition: shadowSource.I:239
ShadowSource::get_slot
int get_slot() const
Returns the slot of the shadow source.
Definition: shadowSource.I:49
ShadowSource::get_resolution
size_t get_resolution() const
Returns the resolution of the source.
Definition: shadowSource.I:152
ShadowSource::set_region
void set_region(const LVecBase4i &region, const LVecBase4 &region_uv)
Sets the assigned region of the source in atlas and uv space.
Definition: shadowSource.I:194
transformState.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
boundingHexahedron.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
boundingSphere.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GPUCommand
Class for storing data to be transferred to the GPU.
Definition: gpuCommand.h:47
ShadowSource::clear_region
void clear_region()
Clears the assigned region of the source.
Definition: shadowSource.I:259
ShadowSource::get_region
const LVecBase4i & get_region() const
Returns the assigned region of the source in atlas space.
Definition: shadowSource.I:165
ShadowSource::has_slot
bool has_slot() const
Returns whether the source has a slot.
Definition: shadowSource.I:61
ShadowSource::write_to_command
void write_to_command(GPUCommand &cmd) const
Writes the source to a GPUCommand.
Definition: shadowSource.I:225
ShadowSource::set_perspective_lens
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.
Definition: shadowSource.I:89
ShadowSource::get_uv_region
const LVecBase4 & get_uv_region() const
Returns the assigned region of the source in UV space.
Definition: shadowSource.I:178
look_at.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ShadowSource::set_slot
void set_slot(int slot)
Assigns the source a slot.
Definition: shadowSource.I:73
ShadowSource::get_bounds
const BoundingSphere & get_bounds() const
Returns the shadow sources bounds.
Definition: shadowSource.I:250
boundingVolume.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ShadowSource::set_matrix_lens
void set_matrix_lens(const LMatrix4 &mvp)
Sets a custom matrix for the source.
Definition: shadowSource.I:117
geometricBoundingVolume.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.