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
5 #ifndef IRR_C_SHADOW_VOLUME_SCENE_NODE_H_INCLUDED
\r
6 #define IRR_C_SHADOW_VOLUME_SCENE_NODE_H_INCLUDED
\r
8 #include "IShadowVolumeSceneNode.h"
\r
15 //! Scene node for rendering a shadow volume into a stencil buffer.
\r
16 class CShadowVolumeSceneNode : public IShadowVolumeSceneNode
\r
21 CShadowVolumeSceneNode(const IMesh* shadowMesh, ISceneNode* parent, ISceneManager* mgr,
\r
22 s32 id, bool zfailmethod=true, f32 infinity=10000.0f);
\r
25 virtual ~CShadowVolumeSceneNode();
\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
30 virtual void setShadowMesh(const IMesh* mesh) override;
\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
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
41 //! Get currently active optimization used to create shadow volumes
\r
42 virtual ESHADOWVOLUME_OPTIMIZATION getOptimization() const override
\r
44 return Optimization;
\r
47 //! pre render method
\r
48 virtual void OnRegisterSceneNode() override;
\r
50 //! renders the node.
\r
51 virtual void render() override;
\r
53 //! returns the axis aligned bounding box of this node
\r
54 virtual const core::aabbox3d<f32>& getBoundingBox() const override;
\r
56 //! Returns type of the scene node
\r
57 virtual ESCENE_NODE_TYPE getType() const override { return ESNT_SHADOW_VOLUME; }
\r
61 typedef core::array<core::vector3df> SShadowVolume;
\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
66 //! Generates adjacency information based on mesh indices.
\r
67 void calculateAdjacency();
\r
69 core::aabbox3d<f32> Box;
\r
71 // a shadow volume for every light
\r
72 core::array<SShadowVolume> ShadowVolumes;
\r
74 // a back cap bounding box for every light
\r
75 core::array<core::aabbox3d<f32> > ShadowBBox;
\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
85 const scene::IMesh* ShadowMesh;
\r
89 u32 ShadowVolumesUsed;
\r
92 bool UseZFailMethod;
\r
93 ESHADOWVOLUME_OPTIMIZATION Optimization;
\r
96 } // end namespace scene
\r
97 } // end namespace irr
\r