Panda3D
pssmCameraRig.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 #ifndef PSSMCAMERARIG_H
28 #define PSSMCAMERARIG_H
29 
30 #include "pandabase.h"
31 #include "luse.h"
32 #include "camera.h"
33 #include "nodePath.h"
34 #include "pStatCollector.h"
35 
36 #include <vector>
37 
38 /**
39  * @brief Main class used for handling PSSM
40  * @details This is the main class for supporting PSSM, it is used by the PSSM
41  * plugin to compute the position of the splits.
42  *
43  * It supports handling a varying amount of cameras, and fitting those cameras
44  * into the main camera frustum, to render distant shadows. It also supports
45  * various optimizations for fitting the frustum, e.g. rotating the sources
46  * to get a better coverage.
47  *
48  * It also provides methods to get arrays of data about the used cameras
49  * view-projection matrices and their near and far plane, which is required for
50  * processing the data in the shadow sampling shader.
51  *
52  * In this class, there is often referred to "Splits" or also called "Cascades".
53  * These denote the different cameras which are used to split the frustum,
54  * and are a common term related to the PSSM algorithm.
55  *
56  * To understand the functionality of this class, a detailed knowledge of the
57  * PSSM algorithm is helpful.
58  */
60 PUBLISHED:
61  PSSMCameraRig(size_t num_splits);
63 
64  inline void set_pssm_distance(float distance);
65  inline void set_sun_distance(float distance);
66  inline void set_use_fixed_film_size(bool flag);
67  inline void set_resolution(size_t resolution);
68  inline void set_use_stable_csm(bool flag);
69  inline void set_logarithmic_factor(float factor);
70  inline void set_border_bias(float bias);
71 
72  void update(NodePath cam_node, const LVecBase3 &light_vector);
73  inline void reset_film_size_cache();
74 
75  inline NodePath get_camera(size_t index);
76 
77  void reparent_to(NodePath parent);
78  inline const PTA_LMatrix4 &get_mvp_array();
79  inline const PTA_LVecBase2 &get_nearfar_array();
80 
81 public:
82  // Used to access the near and far points in the array
83  enum CoordinateOrigin {
84  UpperLeft = 0,
85  UpperRight,
86  LowerLeft,
87  LowerRight
88  };
89 
90 protected:
91  void init_cam_nodes();
92  void compute_pssm_splits(const LMatrix4& transform, float max_distance,
93  const LVecBase3 &light_vector);
94  inline float get_split_start(size_t split_index);
95  LMatrix4 compute_mvp(size_t cam_index);
96  inline LPoint3 get_interpolated_point(CoordinateOrigin origin, float depth);
97  LVecBase3 get_snap_offset(const LMatrix4& mat, size_t resolution);
98 
99  std::vector<NodePath> _cam_nodes;
100  std::vector<Camera*> _cameras;
101  std::vector<LVecBase2> _max_film_sizes;
102 
103  // Current near and far points
104  // Order: UL, UR, LL, LR (See CoordinateOrigin)
105  LPoint3 _curr_near_points[4];
106  LPoint3 _curr_far_points[4];
107  float _pssm_distance;
108  float _sun_distance;
109  float _logarithmic_factor;
110  float _border_bias;
111  bool _use_fixed_film_size;
112  bool _use_stable_csm;
113  size_t _resolution;
114  size_t _num_splits;
115  NodePath _parent;
116 
117  PTA_LMatrix4 _camera_mvps;
118  PTA_LVecBase2 _camera_nearfar;
119 
120  static PStatCollector _update_collector;
121 };
122 
123 #include "pssmCameraRig.I"
124 
125 #endif // PSSMCAMERARIG_H
RenderPipeline.
Definition: pssmCameraRig.h:59
void update(NodePath cam_node, const LVecBase3 &light_vector)
Updates the PSSM camera rig.
void reparent_to(NodePath parent)
Reparents the camera rig.
~PSSMCameraRig()
Destructs the camera rig.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_border_bias(float bias)
Sets the border bias for each split.
PSSMCameraRig(size_t num_splits)
Constructs a new PSSM camera rig.
void set_use_fixed_film_size(bool flag)
Sets whether to use a fixed film size.
Definition: pssmCameraRig.I:93
void set_pssm_distance(float distance)
RenderPipeline.
Definition: pssmCameraRig.I:37
A lightweight class that represents a single element that may be timed and/or counted via stats.
const PTA_LVecBase2 & get_nearfar_array()
Returns a handle to the near and far planes array.
NodePath get_camera(size_t index)
Returns the n-th camera.
void set_sun_distance(float distance)
Sets the suns distance.
Definition: pssmCameraRig.I:56
const PTA_LMatrix4 & get_mvp_array()
Returns a handle to the MVP array.
void set_resolution(size_t resolution)
Sets the resolution of each split.
void set_logarithmic_factor(float factor)
Sets the logarithmic factor.
Definition: pssmCameraRig.I:77
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
void set_use_stable_csm(bool flag)
Sets whether to use stable CSM snapping.
void reset_film_size_cache()
Resets the film size cache.