HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 = nullptr,
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  void setupCascadeMap(RE_Render *r,
86  RE_Shader *sh,
87  RE_UniformBlock *block);
88 
89  // Sets up a distribution of point cube maps to approximate the area shape.
90  void setAreaLightShape(RE_LightAreaShape sh) { myAreaShape=sh; }
91  RE_LightAreaShape getAreaLightShape() const { return myAreaShape; }
92 
93  // Returns the number of area maps for a given light shape.
94  int getNumAreaMaps() const;
95 
96  // View frustum points (near plane TL, TR, BL, BR; then ditto for far plane)
97  // Will swap out the contents of pnts.
98  void setViewFrustum(UT_Vector3FArray &pnts, UT_Vector3F &campos);
99  void setSceneBounds(const UT_BoundingBox &scene_bounds);
100 
101  // Single point lights have one shadow map, while area lights have 4.
102  RE_Texture *getShadowMap(int area_index = 0);
103 
104  // Allows for versioned updates to shadow maps.
105  void setVersion(int64 version) { myVersion = version; }
106  int64 getVersion() const { return myVersion; }
107 
108  void setFrameTime(fpreal t) { myTime = t; }
109  fpreal getFrameTime() const { return myTime; }
110 
111  // Only valid after the shadowmap has been created.
112  void getZClipRange(fpreal &n, fpreal &f) { n = myZNear; f=myZFar; }
113 
114  // generic method which can be used to rotate a view toward a specific cube
115  // face.
116  static UT_Matrix4D computeCubeTransform(RE_TextureCubeFace face,
119 private:
120  bool prepShadowCubeRender(RE_Render *r, int area_index);
121  void finishShadowCubeRender(RE_Render *r, int area_index);
122 
123  bool prepCascadeMapRender(RE_Render *r);
124  void finishCascadeMapRender(RE_Render *r);
125 
126  void clearMaps(bool keep_first_map);
127 
128  RE_OGLFramebuffer *getShadowFrameBuffer(RE_Render *r,
129  RE_OGLTexture *&tex,
130  bool cube,
131  RE_TextureCubeFace face,
132  int area_index);
133 
134  static bool shTexDeleted(RE_Texture *tex, void *shmapobj);
135 
136  UT_Vector4 getAreaLinePos(int index);
137  UT_Vector4 getAreaGridPos(int index);
138  UT_Vector4 getAreaDiskPos(int index);
139  UT_Vector4 getAreaCubePos(int index);
140  UT_Vector4 getAreaSpherePos(int index);
141 
142  const RE_Light *myLight;
143  int myShadowMapSize;
144  RE_OGLFramebuffer *myShadowMapFBO;
145  RE_OGLFramebuffer *myShadowCubeFBO;
146  RE_OGLFramebuffer *myShadowCascadeFBO;
147  RE_Texture2DMap *myShadowHandle[RE_SHADOW_MAX_MAPS];
148  RE_OGLTexture *myShadowMap[RE_SHADOW_MAX_MAPS];
149  RE_TextureCubeMap *myShadowCubeHandle[RE_SHADOW_MAX_AREA_MAPS];
150  RE_OGLTexture *myShadowCube[RE_SHADOW_MAX_AREA_MAPS];
151  RE_OGLTexture *myCascadeMap;
152  RE_OGLTexture *myShadowCubeZ;
153  RE_Uniform *myViewMatrix;
154  RE_Uniform *myProjMatrix;
155  int64 myVersion;
156  fpreal myTime;
157  bool myIsMultiMap;
158  bool myLinearDepthMap;
159  UT_DimRect myPrevViewport;
160  RE_LightAreaShape myAreaShape;
161  fpreal myZNear, myZFar;
162  UT_Vector3FArray myViewFrustum;
163  UT_Vector3F myViewCamPos;
164  UT_BoundingBox mySceneBounds;
165  UT_Vector4F myCascadeBias;
166  UT_Matrix4FArray myCascadeTransforms;
167 };
168 
169 #endif
void setVersion(int64 version)
Definition: RE_ShadowMap.h:105
#define RE_SHADOW_MAX_AREA_MAPS
Definition: RE_Light.h:36
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:106
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
void setAreaLightShape(RE_LightAreaShape sh)
Definition: RE_ShadowMap.h:90
fpreal getFrameTime() const
Definition: RE_ShadowMap.h:109
void getZClipRange(fpreal &n, fpreal &f)
Definition: RE_ShadowMap.h:112
void setFrameTime(fpreal t)
Definition: RE_ShadowMap.h:108
long long int64
Definition: SYS_Types.h:116
GA_API const UT_StringHolder transform
GLdouble t
Definition: glad.h:2397
GT_API const UT_StringHolder version
RE_LightAreaShape
Definition: RE_Light.h:40
fpreal64 fpreal
Definition: SYS_Types.h:277
RE_LightAreaShape getAreaLightShape() const
Definition: RE_ShadowMap.h:91
GLuint index
Definition: glcorearb.h:786
SIM_API const UT_StringHolder position
GLsizei mapsize
Definition: glad.h:2748
GLboolean r
Definition: glcorearb.h:1222