SuperTuxKart
shadow_matrices.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2014-2015 SuperTuxKart-Team
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 
19 #ifndef HEADER_SHADOW_MATRICES_HPP
20 #define HEADER_SHADOW_MATRICES_HPP
21 
22 #include "graphics/gl_headers.hpp"
23 
24 #include <matrix4.h>
25 #include <tuple>
26 #include <vector>
27 #include <vector3d.h>
28 
29 namespace irr
30 {
31  namespace scene { class ICameraSceneNode; }
32 }
33 
34 using namespace irr;
35 
36 class FrameBuffer;
37 class PostProcessing;
38 
40 {
41 public:
42  static float m_shadow_split[5];
43  static float m_shadow_overlap_proportion;
44 
45 private:
46  std::vector<core::matrix4> m_sun_ortho_matrices;
47  scene::ICameraSceneNode *m_sun_cam;
48  scene::ICameraSceneNode *m_shadow_cam_nodes[4];
49  core::matrix4 m_rsm_matrix;
50  bool m_rsm_matrix_initialized;
51  float m_shadows_cam[4][24];
52  bool m_rsm_map_available;
53  float m_mat_ubo[16 * 9 + 2];
54  core::vector3df m_frustum_box_extent[4];
55 
56  core::matrix4 getTightestFitOrthoProj(const core::matrix4 &transform,
57  const std::vector<core::vector3df> &pointsInside,
58  core::vector3df& bounding_box_extent);
59  void renderWireFrameFrustrum(float *tmp, unsigned i);
60 public:
61 
63  ~ShadowMatrices();
64 
65  void computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode,
66  unsigned int width, unsigned int height);
67  void addLight(const core::vector3df &pos);
68  void updateSunOrthoMatrices();
69  void renderShadowsDebug(const FrameBuffer* shadow_framebuffer,
70  const PostProcessing *post_processing);
71 
72  // ------------------------------------------------------------------------
73  void resetShadowCamNodes();
74  // ------------------------------------------------------------------------
75  scene::ICameraSceneNode** getShadowCamNodes()
76  {
77  return m_shadow_cam_nodes;
78  } // getShadowCamNodes
79  // ------------------------------------------------------------------------
80  core::vector3df* getShadowFrustumBoxExtent()
81  {
82  return m_frustum_box_extent;
83  } // getShadowCamNodes
84  // ------------------------------------------------------------------------
85  scene::ICameraSceneNode* getSunCam() { return m_sun_cam; }
86  // ------------------------------------------------------------------------
87  std::vector<core::matrix4>& getSunOrthoMatrices()
88  {
89  return m_sun_ortho_matrices;
90  }
91  // ------------------------------------------------------------------------
92  const float* getMatricesData() const { return m_mat_ubo; }
93 
94 }; // class ShadowMatrices
95 
96 #endif
Definition: frame_buffer.hpp:33
Handles post processing, eg motion blur.
Definition: post_processing.hpp:42
Definition: shadow_matrices.hpp:40