Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SHADOW_MAPPER_H__
00009 #define __SP_SHADOW_MAPPER_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spDimension.hpp"
00014 #include "RenderSystem/spTextureFlags.hpp"
00015 #include "SceneGraph/spSceneCamera.hpp"
00016
00017
00018 namespace sp
00019 {
00020
00021 namespace scene
00022 {
00023 class SceneGraph;
00024 class Light;
00025 }
00026
00027 namespace video
00028 {
00029
00030
00031 class Texture;
00032
00041 class SP_EXPORT ShadowMapper
00042 {
00043
00044 public:
00045
00046 ShadowMapper();
00047 virtual ~ShadowMapper();
00048
00049
00050
00064 virtual bool createShadowMaps(
00065 s32 TexSize, u32 MaxPointLightCount, u32 MaxSpotLightCount, bool UseVSM = true, bool UseRSM = false
00066 );
00068 virtual void deleteShadowMaps();
00069
00082 virtual bool renderShadowMap(
00083 scene::SceneGraph* Graph, scene::Camera* Cam, scene::Light* LightObj, u32 Index
00084 );
00085
00086 virtual void bind(const s32 ShadowMapLayerBase);
00087 virtual void unbind(const s32 ShadowMapLayerBase);
00088
00089
00090
00102 static bool renderCubeMap(
00103 scene::SceneGraph* Graph, scene::Camera* Cam, Texture* Tex, const dim::vector3df &Position
00104 );
00105
00117 static bool renderCubeMapDirection(
00118 scene::SceneGraph* Graph, scene::Camera* Cam, Texture* Tex,
00119 dim::matrix4f CamDir, const ECubeMapDirections Direction
00120 );
00121
00130 static bool renderCubeMap(
00131 scene::SceneGraph* Graph, Texture* Tex, const dim::vector3df &Position
00132 );
00133
00134
00135
00137 inline Texture* getSpotLightTexArray()
00138 {
00139 return ShadowMapArray_.getDepthMap();
00140 }
00142 inline Texture* getPointLightTexArray()
00143 {
00144 return ShadowCubeMapArray_.getDepthMap();
00145 }
00146
00147 protected:
00148
00149
00150
00151 static const dim::matrix4f CUBEMAP_ROTATIONS[6];
00152
00153
00154
00155 struct SP_EXPORT SShadowMap
00156 {
00157 SShadowMap();
00158 ~SShadowMap();
00159
00160
00161 void clear();
00162
00163 void createTexture(u32 Index, const STextureCreationFlags &CreationFlags);
00164 void createRSMs(STextureCreationFlags CreationFlags);
00165
00166 bool setupRenderTargets(bool UseRSM);
00167
00168
00169 inline Texture* getDepthMap() const
00170 {
00171 return TexList[0];
00172 }
00173 inline Texture* getColorMap() const
00174 {
00175 return TexList[1];
00176 }
00177 inline Texture* getNormalMap() const
00178 {
00179 return TexList[2];
00180 }
00181
00182 inline bool valid() const
00183 {
00184 return TexList[0] != 0 && TexList[1] != 0 && TexList[2] != 0;
00185 }
00186
00187
00188 Texture* TexList[3];
00189 };
00190
00191
00192
00194 bool renderPointLightShadowMap(
00195 scene::SceneGraph* Graph, scene::Camera* Cam, scene::Light* LightObj, u32 Index
00196 );
00198 bool renderSpotLightShadowMap(
00199 scene::SceneGraph* Graph, scene::Camera* Cam, scene::Light* LightObj, u32 Index
00200 );
00201
00203 bool checkLightFrustumCulling(scene::Camera* Cam, scene::Light* LightObj) const;
00204
00205 void renderSceneIntoDepthTexture(scene::SceneGraph* Graph, SShadowMap &ShadowMap, u32 Index);
00206 void renderSceneIntoGBuffer (scene::SceneGraph* Graph, SShadowMap &ShadowMap, u32 Index);
00207
00208 static void renderCubeMapDirection(
00209 scene::SceneGraph* Graph, Texture* Tex, const ECubeMapDirections Direction
00210 );
00211
00212
00213
00214 SShadowMap ShadowMapArray_;
00215 SShadowMap ShadowCubeMapArray_;
00216
00217 scene::Camera DepthCam_;
00218
00219 s32 TexSize_;
00220
00221 u32 MaxPointLightCount_;
00222 u32 MaxSpotLightCount_;
00223
00224 bool UseVSM_;
00225 bool UseRSM_;
00226
00227 static scene::Camera ViewCam_;
00228
00229 };
00230
00231
00232 }
00233
00234 }
00235
00236
00237 #endif
00238
00239
00240
00241