HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_LightTypes.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: GR_LightTypes.h (GR Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 #ifndef GR_LightTypes_h
12 #define GR_LightTypes_h
13 
14 #include "GR_Light.h"
15 #include "GR_Defines.h"
16 
17 #include <UT/UT_StringHolder.h>
18 #include <UT/UT_VectorTypes.h>
19 #include <UT/UT_Vector3.h>
20 #include <UT/UT_Matrix4.h>
21 
22 class RV_Render;
23 class RV_ShaderProgram;
24 
25 #define LIGHTPARM(TYPE, NAME) \
26  TYPE get##NAME() const { return myLight.NAME; } \
27  void set##NAME(const TYPE &v) \
28  { if(myLight.NAME != v) { myLight.NAME=v; myDirtyFlag=true; } }
29 
30 #define SHADOWPARM(TYPE, NAME) \
31  TYPE get##NAME() const { return myShadow.NAME; } \
32  void set##NAME(const TYPE &v) \
33  { if(myShadow.NAME != v) { myShadow.NAME=v; myShadowDirtyFlag=true; } }
34 
35 
36 /// Distant (infinite) light. Rays parallel
38 {
39 public:
41  : GR_Light(name, DISTANT)
42  {}
43  ~GR_DistantLight() override; // For UT_UniquePtr<> on WIN
45 
48  LIGHTPARM(int32, WorldSpace);
49  LIGHTPARM(int32, UseSpecular);
50 
51  SHADOWPARM(UT_Matrix4F, ShadowTransform1);
52  SHADOWPARM(UT_Matrix4F, ShadowTransform2);
53  SHADOWPARM(UT_Matrix4F, ShadowTransform3);
54  SHADOWPARM(UT_Matrix4F, ShadowTransform4);
55  SHADOWPARM(fpreal32, ShadowBias);
56  SHADOWPARM(fpreal32, ShadowIntensity);
57 
58  bool initBlocks(RV_Render *r) override
59  {
60  return privInitBlocks(r, &myLight, sizeof(Light),
61  &myShadow, sizeof(Shadow));
62  }
63 
64  RV_ShaderProgram *getShader(bool shadows, bool per_sample) override;
65 
66 private:
67  struct Light
68  {
69  UT_Vector3F Dir = {0.0, 0.0, 1.0};
70  fpreal32 unused1 = 0.0;
71  UT_Vector3F Color = {1.0, 1.0, 1.0};
72  int32 WorldSpace = true;
73  int32 UseSpecular = true;
74  } myLight;
75 
76  struct Shadow
77  {
78  UT_Matrix4F ShadowTransform1;
79  UT_Matrix4F ShadowTransform2;
80  UT_Matrix4F ShadowTransform3;
81  UT_Matrix4F ShadowTransform4;
82  fpreal32 ShadowBias;
83  fpreal32 ShadowIntensity;
84  } myShadow;
85 };
86 
87 // Point Light (spot or omni). Inifinitely small source.
89 {
90 public:
92  : GR_Light(name, POINT)
93  {}
94  ~GR_PointLight() override; // For UT_UniquePtr<> on WIN
96 
97  LIGHTPARM(UT_Matrix4F, Projection);
98  LIGHTPARM(UT_Vector4F, Focus);
99  LIGHTPARM(UT_Vector3F, Pos);
101  LIGHTPARM(UT_Vector3F, LightX);
102  LIGHTPARM(UT_Vector3F, LightY);
104  LIGHTPARM(UT_Vector3F, Atten);
105  LIGHTPARM(UT_Vector2F, ActiveRadius);
106  LIGHTPARM(UT_Vector2F, AttenRange);
107  LIGHTPARM(UT_Vector2F, AttenRampRange);
108  LIGHTPARM(UT_Vector2F, LeftBarn);
109  LIGHTPARM(UT_Vector2F, RightBarn);
110  LIGHTPARM(UT_Vector2F, TopBarn);
111  LIGHTPARM(UT_Vector2F, BottomBarn);
112  LIGHTPARM(fpreal32, Cutoff);
113  LIGHTPARM(fpreal32, Falloff);
114  LIGHTPARM(fpreal32, SpotRolloff);
115  LIGHTPARM(int32, HasSpot);
116  LIGHTPARM(int32, HasProject);
117  LIGHTPARM(int32, ProjectClamp);
118  LIGHTPARM(int32, HasAttenRamp);
119 
120  SHADOWPARM(UT_Matrix4F, ShadowTransform);
121  SHADOWPARM(fpreal32, ShadowBias);
122  SHADOWPARM(fpreal32, ShadowIntensity);
123 
124  void setProjectMap(const UT_StringHolder &map_name, int op_id)
125  {
126  if(myProjectMap != map_name || myProjectMapOpId != op_id)
127  {
128  myProjectMap = map_name;
129  myProjectMapOpId = op_id;
130 #ifdef USE_VULKAN
131  myProjectMapId.reset();
132 #endif
133  myTexDirty = true;
134  }
135  }
136  const UT_StringHolder &projectMap() const { return myProjectMap; }
137  int projectMapOpId() const { return myProjectMapOpId; }
138 
139  bool initBlocks(RV_Render *r) override
140  {
141  if(myTexDirty)
142  {
143  myTexDirty = false;
144 #ifdef USE_VULKAN
145  privBindTexture(r, myProjectMap, myProjectMapOpId, myProjectMapId,
146  "projectMap");
147 #endif
148  }
149  return privInitBlocks(r, &myLight, sizeof(Light),
150  &myShadow, sizeof(Shadow));
151  }
152 
153  RV_ShaderProgram *getShader(bool shadows, bool per_sample) override;
154 
155 private:
156  struct Light
157  {
158  UT_Matrix4F Projection;
159  UT_Vector4F Focus = {0.0, 0.0, 0.0, 0.0};
160  UT_Vector3F Pos = {0.0, 0.0, 1.0};
161  fpreal32 unused1 = 0.0;
162  UT_Vector3F Dir = {0.0, 0.0, 1.0};
163  fpreal32 unused2 = 0.0;
164  UT_Vector3F LightX= {1.0, 0.0, 0.0};
165  fpreal32 unused3 = 0.0;
166  UT_Vector3F LightY= {0.0, 1.0, 0.0};
167  fpreal32 unused4 = 0.0;
168  UT_Vector3F Color = {1.0, 1.0, 1.0};
169  fpreal32 unused5 = 0.0;
170  UT_Vector3F Atten = {0.0, 0.0, 1.0};
171  fpreal32 unused6 = 0;
172  UT_Vector2F ActiveRadius = { 0.0, 1e20 };
173  UT_Vector2F LeftBarn = { 0.0, 0.0 };
174  UT_Vector2F RightBarn = { 0.0, 0.0 };
175  UT_Vector2F TopBarn = { 0.0, 0.0 };
176  UT_Vector2F BottomBarn = { 0.0, 0.0 };
177  UT_Vector2F AttenRange = { 0.0, 1e20 };
178  UT_Vector2F AttenRampRange = { 0.0, 0.0 };
179  fpreal32 Cutoff = -1.0;
180  fpreal32 Falloff = -1.0;
181  fpreal32 SpotRolloff = 1.0;
182  int32 HasSpot = false;
183  int32 HasProject = false;
184  int32 ProjectClamp = false;
185  int32 HasAttenRamp = false;
186  } myLight;
187 
188  struct Shadow
189  {
190  UT_Matrix4F ShadowTransform;
191  fpreal32 ShadowBias = 0.01;
192  fpreal32 ShadowIntensity = 1.0;
193  } myShadow;
194 
195  bool myTexDirty = true;
196  UT_StringHolder myProjectMap;
197  int myProjectMapOpId = -999;
198  RV_TextureRef myProjectMapId;
199 };
200 
201 /// Distant (infinite) light. Rays parallel
203 {
204 public:
206  : GR_Light(name, AMBIENT)
207  {}
208  ~GR_AmbientLight() override; // For UT_UniquePtr<> on WIN
210 
212 
213  bool initBlocks(RV_Render *r) override
214  {
215  return privInitBlocks(r, &myLight, sizeof(Light), nullptr, 0);
216  }
217 
218  RV_ShaderProgram *getShader(bool shadows, bool per_sample) override;
219 
220 private:
221  struct Light
222  {
223  UT_Vector3F Color = {1.0, 1.0, 1.0};
224  } myLight;
225 };
226 
227 /// Environment light. Infinitely far away incoming rays from all directions.
229 {
230 public:
232  : GR_Light(name, ENVIRONMENT)
233  {}
234  ~GR_EnvLight() override; // For UT_UniquePtr<> on WIN
236 
237  LIGHTPARM(UT_Matrix4F, EnvRotate);
239 
240  void setEnvMap(const UT_StringHolder &map_name, int op_id)
241  {
242  if(myEnvMap != map_name || myEnvMapOpId != op_id)
243  {
244  myEnvMap = map_name;
245  myEnvMapOpId = op_id;
246  if(map_name.isstring() != (myLight.HasMap!=0))
247  {
248  myLight.HasMap = map_name.isstring();
249  myDirtyFlag = true;
250  }
251 
252 #ifdef USE_VULKAN
253  myEnvMapId.reset();
254 #else
255  myEnvMapId = 0; // to suppress unused member warning
256 #endif
257  myTexDirty = true;
258  }
259  }
260  const UT_StringHolder &envMap() const { return myEnvMap; }
261  int envMapOpId() const { return myEnvMapOpId; }
262 
263  bool initBlocks(RV_Render *r) override
264  {
265  if(myTexDirty)
266  {
267  myTexDirty = false;
268 #ifdef USE_VULKAN
269  RV_TextureParms parms;
270  parms.MipMap = true;
271  privBindTexture(r, myEnvMap, myEnvMapOpId, myEnvMapId, "envMap",
272  &parms, true);
273 #endif
274  }
275  return privInitBlocks(r, &myLight, sizeof(Light), nullptr, 0);
276  }
277 
278  RV_ShaderProgram *getShader(bool shadows, bool per_sample) override;
279 
280 private:
281  struct Light
282  {
283  UT_Matrix4F EnvRotate;
284  UT_Vector3F Color = {1.0, 1.0, 1.0};
285  int32 HasMap = 0;
286  } myLight;
287 
288  bool myTexDirty = true;
289  UT_StringHolder myEnvMap;
290  int myEnvMapOpId = -999;
291  RV_TextureRef myEnvMapId;
292 };
293 
294 #endif
bool initBlocks(RV_Render *r) override
Definition: GR_LightTypes.h:58
GR_AmbientLight(const UT_StringHolder &name)
int int32
Definition: SYS_Types.h:39
Distant (infinite) light. Rays parallel.
bool initBlocks(RV_Render *r) override
bool initBlocks(RV_Render *r) override
GR_PointLight(const UT_StringHolder &name)
Definition: GR_LightTypes.h:91
Opaque reference to a texture stored in the RV_TextureCache.
Definition: RV_Type.h:175
Distant (infinite) light. Rays parallel.
Definition: GR_LightTypes.h:37
float fpreal32
Definition: SYS_Types.h:200
int projectMapOpId() const
int envMapOpId() const
bool privInitBlocks(RV_Render *r, void *light_block, int light_size, void *shadow_block, int shadow_size)
const UT_StringHolder & envMap() const
const UT_StringHolder & projectMap() const
Base class for all light types.
Definition: GR_Light.h:36
#define GR_API
Definition: GR_API.h:10
GR_DistantLight(const UT_StringHolder &name)
Definition: GR_LightTypes.h:40
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_NON_COPYABLE(GR_Light)
#define SHADOWPARM(TYPE, NAME)
Definition: GR_LightTypes.h:30
void setEnvMap(const UT_StringHolder &map_name, int op_id)
void privBindTexture(RV_Render *r, const UT_StringHolder &map_name, int rel_op_id, RV_TextureRef &map_id, const UT_StringHolder &sampler_name, RV_TextureParms *tex_parms=nullptr, bool is_cube=false)
GR_EnvLight(const UT_StringHolder &name)
#define LIGHTPARM(TYPE, NAME)
Definition: GR_LightTypes.h:25
bool initBlocks(RV_Render *r) override
GLboolean r
Definition: glcorearb.h:1222
virtual RV_ShaderProgram * getShader(bool shadows, bool per_sample)=0
Environment light. Infinitely far away incoming rays from all directions.
void setProjectMap(const UT_StringHolder &map_name, int op_id)
SYS_FORCE_INLINE bool isstring() const