My Project
ShadowVolume.h
1 #pragma once
2 
3 namespace ParaEngine
4 {
8 struct LightParams
9 {
10  Vector3 Position; /* Position in world space */
11  Vector3 Direction; /* Direction in world space */
12  LinearColor Diffuse; /* Diffuse color of light */
13  float Range; /* Cutoff range */
14  bool bIsDirectional; /* true if it is a directional light */
15  LightParams(){
16  bIsDirectional = true;
17  }
18 };
19 
20 class ShadowVolume;
21 
28 {
29 public:
30  virtual bool IsShadowEnabled(){return false;};
31  virtual void BuildShadowVolume(SceneState * sceneState, ShadowVolume * pShadowVolume, LightParams* pLight) = 0;
32 };
33 
34 class CAutoCamera;
35 class CBaseObject;
40 {
41 public:
42  enum ShadowMethod {
43  SHADOW_NONE = 0,
44  SHADOW_Z_PASS,
45  SHADOW_Z_FAIL
46  };
47  static float m_fMinShadowCastDistance;
48 
49 #define INITIAL_SHADOWVOLUME_SIZE 32000
50  ShadowVolume(void);
51  ~ShadowVolume(void);
52 
53  int m_nVertexArraySize;
57  ShadowMethod m_shadowMethod;
59  Plane occlusionPyramid[5];
60 protected:
64 
65 public:
67  void Reset() {
68  m_nNumVertices = 0L;
69  m_shadowMethod = SHADOW_NONE;
70  }
71 
72  void ReserveNewBlock(Vector3** pVertices, int nSize);
73  void CommitBlock(int nSize);
74 
75  void BuildFromShadowCaster( ShadowCaster* pCaster, LightParams* pLight);
76 
78  void ReCalculateOcclusionPyramid(CAutoCamera* pCamera);
79 
81  void UpdateProjectionInfo(const ParaViewport* pViewport,
82  const Matrix4 *pProj,
83  const Matrix4 *pView);
84 
86  void ProjectPoint(Vector3 *pOut, const Vector3 *pV, const Matrix4 *pWorld);
88  bool PointsInsideOcclusionPyramid(Vector3* pVecBounds, int nCount);
89 
91  void SetLightParams(LightParams* l){m_pLightParam = l;};
92 
94  HRESULT Render( SceneState * sceneState );
95 
97  HRESULT RenderZPassShadow( SceneState * sceneState );
99  HRESULT RenderZFailShadow( SceneState * sceneState );
100 };
101 }
void Reset()
current view matrix
Definition: ShadowVolume.h:67
ShadowVolume is a structure for storing shadow volume geometries.
Definition: ShadowVolume.h:39
It's used as parameter to Draw method of each scene object.
Definition: SceneState.h:284
different physics engine has different winding order.
Definition: EventBinding.h:32
Auto Camera is designed to handle smooth transitions between supported camera type, such as first person camera, third person camera, and rotation camera.
Definition: AutoCamera.h:14
ShadowMethod m_shadowMethod
the color of the shadow, alpha enabled.
Definition: ShadowVolume.h:57
The following shadow interface should be implemented for any shadow caster entity in the game engine...
Definition: ShadowVolume.h:27
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
Definition: ParaViewport.h:5
LightParams is a structure for which a shadow volume is built.
Definition: ShadowVolume.h:8
Matrix4 m_matView
current projection matrix
Definition: ShadowVolume.h:63
ParaViewport m_viewport
used to decide whether to use Z-Fail or Z pass method
Definition: ShadowVolume.h:61
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
LightParams * m_pLightParam
in which way, the data in this shadow volume should be drawn
Definition: ShadowVolume.h:58
int m_nNumVertices
Vertex data for rendering shadow volume.
Definition: ShadowVolume.h:55
Vector3 * m_pVertices
initial value is 32000, doubled when exceeded
Definition: ShadowVolume.h:54
Defines a plane in 3D space.
Definition: ParaPlane.h:23
LinearColor m_shadowColor
number of vertices in the shadow volume, it must be multiple of 6, since 6 vertices will describe a f...
Definition: ShadowVolume.h:56
Defines the base class of all scene elements:CBaseObject for Parallel World Engine.
Definition: BaseObject.h:230
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
Matrix4 m_matProjection
current viewport for projection
Definition: ShadowVolume.h:62
void SetLightParams(LightParams *l)
set current light
Definition: ShadowVolume.h:91