Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
shadows.h
1 #pragma once
2 
3 #include "renderers/batching/renderable.h"
4 
5 namespace smlt {
6 
7 
8 enum ShadowMethod {
9  SHADOW_METHOD_STENCIL_DEPTH_FAIL, // Standard
10  SHADOW_METHOD_STENCIL_EXCLUSIVE_OR // Really for the Dreamcast modifier volume stuff
11 };
12 
13 enum ShadowCast {
14  SHADOW_CAST_ALWAYS,
15  SHADOW_CAST_NEVER
16 };
17 
18 enum ShadowReceive {
19  SHADOW_RECEIVE_ALWAYS,
20  SHADOW_RECEIVE_NEVER
21 };
22 
24  SilhouetteEdge(const smlt::Vec3& v1, const smlt::Vec3& v2):
25  first(v1), second(v2) {
26 
27  }
28 
29  smlt::Vec3 first;
30  smlt::Vec3 second;
31 
32  const smlt::Vec3& operator[](std::size_t i) const {
33  if(i == 0) {
34  return first;
35  } else if(i == 1) {
36  return second;
37  } else {
38  throw std::out_of_range("Invalid edge index");
39  }
40  }
41 };
42 
44  /*
45  * Stores the chain of edges that form a silohette from a particular light
46  *
47  * INVALIDATED:
48  * - When the mesh adjacency is invalided
49  * - When the light moves
50  */
51 public:
52 
53  /*
54  * mesh - The mesh that this silhouette is for
55  * mesh_rotation - The rotation of the mesh to calculate (normally from the Actor)
56  * light - The light to calculate the silhoutte from
57  */
58  MeshSilhouette(MeshPtr mesh, const Mat4& mesh_transformation, const LightPtr light);
59 
60  /*
61  * Returns the list of vertex pairs which make up the calculated silhouette. Returns
62  * an empty list if the mesh isn't influenced by the light
63  */
64  const std::vector<SilhouetteEdge>& edge_list();
65 
66 private:
67  void recalculate_silhouette();
68  void calculate_directional_silhouette();
69  void calculate_point_silhouette();
70  void calculate_spot_silhouette();
71 
72  std::vector<SilhouetteEdge> edge_list_;
73 
74  smlt::MeshPtr mesh_;
75  smlt::Vec3 inverse_mesh_position_;
76  smlt::Quaternion inverse_mesh_rotation_;
77  smlt::Vec3 light_direction_or_position_;
78  LightType light_type_;
79 };
80 
82  /*
83  * Calculates and stores the shadow volumes for a stage. ShadowManager::update should be
84  * called with the visible lights and shadow-casting renderables each time a camera view
85  * is rendered.
86  *
87  * Shadow volumes will not be updated in the following situations:
88  *
89  * 1. The light <> renderable volume has already been calculated this frame
90  * 2. The light and renderable haven't moved since a previous frame
91  *
92  * ShadowVolumes are destroyed when the light or renderable are destroyed.
93  */
94 public:
95  void update(uint64_t frame_id, const std::vector<Light>& lights, const std::vector<RenderablePtr>& renderables);
96 
97 };
98 
99 
100 
101 
102 }
smlt::Mat4
Definition: mat4.h:25
smlt::Vec3
Definition: vec3.h:23
smlt::SilhouetteEdge
Definition: shadows.h:23
smlt::Quaternion
Definition: quaternion.h:24
smlt::MeshSilhouette
Definition: shadows.h:43
smlt
Definition: animation.cpp:25
smlt::default_init_ptr< Light >
smlt::ShadowVolumeManager
Definition: shadows.h:81