HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RE_ShadowMap.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RE_ShadowMap.h ( RE Library, C++)
7  *
8  * COMMENTS:
9  * Contains the texture map and the code for generating a shadow map from
10  * a light.
11  */
12 #ifndef RE_ShadowMap_h
13 #define RE_ShadowMap_h
14 
15 class RE_Render;
16 class RE_Shader;
17 class RE_OGLTexture;
18 class RE_OGLFramebuffer;
19 class RE_Texture2DMap;
20 class RE_TextureCubeMap;
21 class RE_Uniform;
22 
23 #include <UT/UT_VectorTypes.h>
24 
25 #include <SYS/SYS_Types.h>
26 #include <UT/UT_Rect.h>
27 
28 #include "RE_API.h"
29 #include "RE_Texture.h"
30 #include "RE_Light.h"
31 
32 #define RE_SHADOW_MAX_MAPS \
33  (RE_SHADOW_MAX_AREA_MAPS > RE_SHADOW_NUM_CUBE_MAPS ? \
34  RE_SHADOW_MAX_AREA_MAPS : RE_SHADOW_NUM_CUBE_MAPS)
35 
37 {
38 public:
39  RE_ShadowMap(const RE_Light *light, int mapsize);
40  ~RE_ShadowMap();
41 
42  // If true, this shadow map contains multiple maps for doing blurry
43  // shadows.
44  void setMultiMap(bool m);
45  bool isMultiMap() const;
46 
47 
48  // If true, this shadow map renders to an 32b R32F texture, without
49  // the non-linear clamping depth to [0,1]. OpenGL3 hardware required.
50  void useLinearDepthMap(bool ld);
51  bool usesLinearDepthMap() const;
52 
53 
54  // Multiplies the current GL matrix by the transformation that maps a
55  // world space point to a light space point. If 'mat' is supplied, the
56  // transform is assigned to it rather than affecting the current GL matrix.
57  void getShadowMapTransform(RE_Render *r, bool bias,
58  UT_Matrix4F *mat = NULL,
59  bool cube=false,
62  int area_index = 0,
63  int xform_mask = 0x3);
64 
65  // Sets up GL to render the light's shadow map. The proper transform
66  // will be set for you. If this returns false, shadow maps are not
67  // supported and no further shadow map calls should be made (including
68  // finishShadowMapRender). If this returns true, the shadow map is
69  // ready to be rendered to and finishShadowMapRender must be called
70  // after rendering to it. When rendering a point light, the scene must be
71  // rendered 6x for each face of the cube map, so 'face' is used to indicate
72  // which cube face is currently being rendered. 'samples' allows for
73  // multisampled shadow maps, providing better edge antialiaing.
74  bool prepShadowMapRender(RE_Render *r,
76  int area_index = 0);
77 
78  // When you are done rendering from the light's view, call this
79  // to clean up your GL state and return you to the main viewport.
80  void finishShadowMapRender(RE_Render *r,
82  int area_index = 0);
83 
84 
85  // Enables or disables the use of shadow maps for the specified light.
86  // If 'compare' is on, then the texture must be accessed by the shadow
87  // versions of samplers (otherwise, off, uses normal texture2D() sampling)
88  // area_index specifies the map to use for blurred area light shadows.
89  void useShadowMap(RE_Render *r, RE_Shader *sh, bool ison);
90 
91  // Returns true if 6 separate shadow maps are used instead of a cube map,
92  // for hardware that does not support cube shadow maps.
93  bool useSeparatePointShadowMaps(RE_Render *r) const;
94 
95  // Sets up a distribution of point cube maps to approximate the area shape.
96  void setAreaLightShape(RE_LightAreaShape sh) { myAreaShape=sh; }
97  RE_LightAreaShape getAreaLightShape() const { return myAreaShape; }
98 
99  // Returns the number of area maps for a given light shape.
100  int getNumAreaMaps() const;
101 
102  // Single point lights have one shadow map, while area lights have 4.
103  RE_Texture *getShadowMap(int area_index = 0);
104 
105  // Allows for versioned updates to shadow maps.
106  void setVersion(int64 version) { myVersion = version; }
107  int64 getVersion() const { return myVersion; }
108 
109  void setFrameTime(fpreal t) { myTime = t; }
110  fpreal getFrameTime() const { return myTime; }
111 
112  // Only valid after the shadowmap has been created.
113  void getZClipRange(fpreal &n, fpreal &f) { n = myZNear; f=myZFar; }
114 
115  // generic method which can be used to rotate a view toward a specific cube
116  // face.
117  static UT_Matrix4D computeCubeTransform(RE_TextureCubeFace face,
118  UT_Vector4 position,
120 private:
121  bool prepShadowCubeRender(RE_Render *r, int area_index);
122  void finishShadowCubeRender(RE_Render *r, int area_index);
123 
124  void clearMaps(bool keep_first_map);
125 
126  RE_OGLFramebuffer *getShadowFrameBuffer(RE_Render *r,
127  RE_OGLTexture *&tex,
128  bool cube,
129  RE_TextureCubeFace face,
130  int area_index);
131 
132  static bool shTexDeleted(RE_Texture *tex, void *shmapobj);
133 
134  UT_Vector4 getAreaLinePos(int index);
135  UT_Vector4 getAreaGridPos(int index);
136  UT_Vector4 getAreaDiskPos(int index);
137  UT_Vector4 getAreaCubePos(int index);
138  UT_Vector4 getAreaSpherePos(int index);
139 
140  const RE_Light *myLight;
141  int myShadowMapSize;
142  RE_OGLFramebuffer *myShadowMapFBO;
143  RE_OGLFramebuffer *myShadowCubeFBO;
144  RE_Texture2DMap *myShadowHandle[RE_SHADOW_MAX_MAPS];
145  RE_OGLTexture *myShadowMap[RE_SHADOW_MAX_MAPS];
146  RE_TextureCubeMap *myShadowCubeHandle[RE_SHADOW_MAX_AREA_MAPS];
147  RE_OGLTexture *myShadowCube[RE_SHADOW_MAX_AREA_MAPS];
148  RE_OGLTexture *myShadowCubeZ;
149  RE_Uniform *myCubeView;
150  int64 myVersion;
151  fpreal myTime;
152  bool myIsMultiMap;
153  bool myIsSeparateMaps;
154  bool myLinearDepthMap;
155  UT_DimRect myPrevViewport;
156  RE_LightAreaShape myAreaShape;
157  fpreal myZNear, myZFar;
158 };
159 
160 #endif
161 
162 
void setVersion(int64 version)
Definition: RE_ShadowMap.h:106
#define RE_SHADOW_MAX_AREA_MAPS
Definition: RE_Light.h:35
RE_TextureCubeFace
#define RE_API
Definition: RE_API.h:10
#define RE_SHADOW_MAX_MAPS
Definition: RE_ShadowMap.h:32
int64 getVersion() const
Definition: RE_ShadowMap.h:107
long long int64
Definition: SYS_Types.h:100
GLdouble n
Definition: glcorearb.h:2007
GLfloat f
Definition: glcorearb.h:1925
void setAreaLightShape(RE_LightAreaShape sh)
Definition: RE_ShadowMap.h:96
fpreal getFrameTime() const
Definition: RE_ShadowMap.h:110
void getZClipRange(fpreal &n, fpreal &f)
Definition: RE_ShadowMap.h:113
void setFrameTime(fpreal t)
Definition: RE_ShadowMap.h:109
GA_API const UT_StringHolder transform
double fpreal
Definition: SYS_Types.h:263
RE_LightAreaShape
Definition: RE_Light.h:39
RE_LightAreaShape getAreaLightShape() const
Definition: RE_ShadowMap.h:97
GLuint index
Definition: glcorearb.h:785
GLboolean r
Definition: glcorearb.h:1221