H3D API  2.4.1
ShadowGeometry.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __SHADOWGEOMETRY_H__
30 #define __SHADOWGEOMETRY_H__
31 
33 #include <H3D/DirectionalLight.h>
34 #include <H3D/PointLight.h>
35 #include <H3D/SFRotation.h>
36 #include <H3D/MatrixTransform.h>
37 #include <H3D/X3DGeometryNode.h>
38 #include <H3D/ComposedShader.h>
39 
40 namespace H3D {
41 
59  class H3DAPI_API ShadowGeometry : public H3DShadowObjectNode {
60  public:
61 
66  class H3DAPI_API SFGeometryNode: public TypedSFNode< X3DGeometryNode > {
67  protected:
68  virtual void onAdd( Node *n );
69  virtual void onRemove( Node *n );
70  };
71 
73  ShadowGeometry( Inst< SFNode > _metadata = 0,
74  Inst< SFTransformNode > _transform = 0,
75  Inst< SFGeometryNode > _geometry = 0,
76  Inst< SFBool > _enabled = 0 );
77 
78  virtual void update();
79  protected:
82  // This field has to be defined before geometry in the node since when
83  // geometry is destructed this field is used and have to exist.
84  H3DUniquePtr<Field> triangles_changed;
85  public:
86 
92  H3DUniquePtr< SFGeometryNode > geometry;
93 
96 
97  virtual void computeShadowVolumeInformationCPU( const LightDataStruct& light_data, Matrix4f accumulated_fwd, bool render_caps, std::vector< Vec4d >& coord );
98 
99  virtual void renderShadowGPU( const LightDataStruct& light_data, Matrix4f accumulated_fwd, bool render_caps );
100 
101  protected:
102 
103  void buildShadowVolumeDataCPU( LightDataStruct light_data,
104  bool render_caps,
105  const Matrix4f &local_to_global,
106  const Matrix4f &global_to_local,
107  bool rebuild_triangle_info,
108  std::vector< Vec4d >& coord );
109 
113  void addDirectionalLightQuadPoints( vector< Vec4d > &triangle_points,
114  const Vec3d &v1, const Vec3d &v2,
115  const Vec3d& dir );
116 
120  void addPointLightQuadPoints( vector< Vec4d > &triangle_points,
121  const Vec3d &v1, const Vec3d &v2,
122  const Vec3d& light_pos );
123 
124 
125 
128  void updateNeighbours( const vector< HAPI::Collision::Triangle > &triangles);
129 
133  void updateSilhouetteEdgesDirectionalLight( const vector< HAPI::Collision::Triangle > &,
134  const vector<int> &neighbours,
135  const Vec3d &direction );
136 
139  void updateSilhouetteEdgesPointLight( const vector< HAPI::Collision::Triangle > &,
140  const vector<int> &neighbours,
141  const Vec3d &pos );
142 
146  void updateAdjacentVertexArray( const vector< HAPI::Collision::Triangle > &triangles,
147  vector< Vec3d > &triangle_points,
148  vector< unsigned int > &adjacency_index );
149 
154  int getMissingPointIndex( const HAPI::Collision::Triangle &t,
155  const Vec3d &p0, const Vec3d &p1 );
156 
159  vector< int > neighbours;
160 
163  vector< HAPI::Collision::Triangle > triangles;
164 
167 
170  std::map< X3DLightNode *, pair< H3DTime, vector< Vec4d > > > triangle_points_fallback;
171 
173  vector< unsigned int > index_geom_shader;
174 
180  vector< bool > is_silhouette_edge;
181 
184  vector< bool > triangle_facing_light;
185 
188 
189  // copies of fields that are updated in traverse and are used in computation of shadow volumes
190  // these are thread safe copies
191  Matrix4f transform_matrix_ts;
192  bool is_enabled_ts;
193  bool rebuild_triangles_ts;
194 
197  std::vector< HAPI::Collision::Triangle > triangles_ts;
198 
199 
200  };
201 }
202 
203 #endif
Header file for ComposedShader, X3D scene-graph node.
Header file for DirectionalLight, X3D scene-graph node.
Header file for H3DShadowObjectNode.
Header file for MatrixTransform, X3D scene-graph node.
Header file for PointLight, X3D scene-graph node.
Contains the SFRotation field class.
Header file for X3DGeometryNode, X3D scene-graph node.
The H3DShadowObjectNode is the base class for all shadow objects for use in the ShadowCaster node.
Definition: H3DShadowObjectNode.h:49
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
SFGeometryNode is specialized to route the boundTree field from the X3DGeometryNodes that are put int...
Definition: ShadowGeometry.h:66
The ShadowGeometry object specifies a X3DGeometryNode that should be used for casting a shadow when u...
Definition: ShadowGeometry.h:59
static H3DNodeDatabase database
The H3DNodeDatabase object for this node.
Definition: ShadowGeometry.h:95
std::vector< HAPI::Collision::Triangle > triangles_ts
The triangles of the geometry.
Definition: ShadowGeometry.h:197
std::map< X3DLightNode *, pair< H3DTime, vector< Vec4d > > > triangle_points_fallback
Points to be used for each light vertex array rendering if CPU based.
Definition: ShadowGeometry.h:170
vector< int > neighbours
Array of 3*nr_triangles triangle indices specifying for each triangle edge which triangle is its neig...
Definition: ShadowGeometry.h:159
H3DUniquePtr< SFGeometryNode > geometry
The geometry field specifies the X3DGeometryNode that should cast a shadow.
Definition: ShadowGeometry.h:92
H3DUniquePtr< Field > triangles_changed
This field will be sent an event when the triangles in the geometry field have changed.
Definition: ShadowGeometry.h:84
vector< bool > is_silhouette_edge
Array of 3*nr_triangles values, one for each triangle edge.
Definition: ShadowGeometry.h:180
vector< bool > triangle_facing_light
Array of nr_triangle values indicating if the triangle is facing the light source or not.
Definition: ShadowGeometry.h:184
bool use_geometry_shader_last_loop
True if geometry shader was used last time this ShadowGeometry was rendered.
Definition: ShadowGeometry.h:187
vector< Vec3d > triangle_points_geom_shader
Points to be used for vertex array rendering with adjacency info.
Definition: ShadowGeometry.h:166
vector< unsigned int > index_geom_shader
Index to be used for vertex array rendering with adjacency info.
Definition: ShadowGeometry.h:173
vector< HAPI::Collision::Triangle > triangles
The triangles of the geometry.
Definition: ShadowGeometry.h:163
Template to make sure that the Node that is set in a SFNode is of a specified Node type.
Definition: SFNode.h:97
Vec3d()
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194