]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CShadowVolumeSceneNode.h
Add back lighting system
[irrlicht.git] / source / Irrlicht / CShadowVolumeSceneNode.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef IRR_C_SHADOW_VOLUME_SCENE_NODE_H_INCLUDED\r
6 #define IRR_C_SHADOW_VOLUME_SCENE_NODE_H_INCLUDED\r
7 \r
8 #include "IShadowVolumeSceneNode.h"\r
9 \r
10 namespace irr\r
11 {\r
12 namespace scene\r
13 {\r
14 \r
15         //! Scene node for rendering a shadow volume into a stencil buffer.\r
16         class CShadowVolumeSceneNode : public IShadowVolumeSceneNode\r
17         {\r
18         public:\r
19 \r
20                 //! constructor\r
21                 CShadowVolumeSceneNode(const IMesh* shadowMesh, ISceneNode* parent, ISceneManager* mgr,\r
22                         s32 id, bool zfailmethod=true, f32 infinity=10000.0f);\r
23 \r
24                 //! destructor\r
25                 virtual ~CShadowVolumeSceneNode();\r
26 \r
27                 //! Sets the mesh from which the shadow volume should be generated.\r
28                 /** To optimize shadow rendering, use a simpler mesh for shadows.\r
29                 */\r
30                 virtual void setShadowMesh(const IMesh* mesh) override;\r
31 \r
32                 //! Updates the shadow volumes for current light positions.\r
33                 /** Called each render cycle from Animated Mesh SceneNode render method. */\r
34                 virtual void updateShadowVolumes() override;\r
35 \r
36                 //! Set optimization used to create shadow volumes\r
37                 /** Default is ESV_SILHOUETTE_BY_POS. If the shadow \r
38                 looks bad then give ESV_NONE a try (which will be slower). */\r
39                 virtual void setOptimization(ESHADOWVOLUME_OPTIMIZATION optimization) override;\r
40 \r
41                 //! Get currently active optimization used to create shadow volumes\r
42                 virtual ESHADOWVOLUME_OPTIMIZATION getOptimization() const override\r
43                 {\r
44                         return Optimization;\r
45                 }\r
46 \r
47                 //! pre render method\r
48                 virtual void OnRegisterSceneNode() override;\r
49 \r
50                 //! renders the node.\r
51                 virtual void render() override;\r
52 \r
53                 //! returns the axis aligned bounding box of this node\r
54                 virtual const core::aabbox3d<f32>& getBoundingBox() const override;\r
55 \r
56                 //! Returns type of the scene node\r
57                 virtual ESCENE_NODE_TYPE getType() const override { return ESNT_SHADOW_VOLUME; }\r
58 \r
59         private:\r
60 \r
61                 typedef core::array<core::vector3df> SShadowVolume;\r
62 \r
63                 void createShadowVolume(const core::vector3df& pos, bool isDirectional);\r
64                 u32 createEdgesAndCaps(const core::vector3df& light, bool isDirectional, SShadowVolume* svp, core::aabbox3d<f32>* bb);\r
65 \r
66                 //! Generates adjacency information based on mesh indices.\r
67                 void calculateAdjacency();\r
68 \r
69                 core::aabbox3d<f32> Box;\r
70 \r
71                 // a shadow volume for every light\r
72                 core::array<SShadowVolume> ShadowVolumes;\r
73 \r
74                 // a back cap bounding box for every light\r
75                 core::array<core::aabbox3d<f32> > ShadowBBox;\r
76 \r
77                 core::array<core::vector3df> Vertices;\r
78                 core::array<u16> Indices;\r
79                 core::array<u16> Adjacency;\r
80                 core::array<u16> Edges;\r
81                 // tells if face is front facing\r
82                 std::vector<bool> FaceData;\r
83                 bool AdjacencyDirtyFlag;\r
84 \r
85                 const scene::IMesh* ShadowMesh;\r
86 \r
87                 u32 IndexCount;\r
88                 u32 VertexCount;\r
89                 u32 ShadowVolumesUsed;\r
90 \r
91                 f32 Infinity;\r
92                 bool UseZFailMethod;\r
93                 ESHADOWVOLUME_OPTIMIZATION Optimization;\r
94         };\r
95 \r
96 } // end namespace scene\r
97 } // end namespace irr\r
98 \r
99 #endif\r