HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_Light.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_Light.h (GR Library, C++)
7  *
8  * COMMENTS:
9  * Light list and base class for all lights.
10  * Specific lights are defined in GR_LightTypes.h.
11  */
12 #ifndef GR_Light_h
13 #define GR_Light_h
14 
15 #include "GR_API.h"
16 #include "GR_Defines.h"
17 #include "GR_SceneItem.h"
18 
19 #include <RE/RE_RenderContext.h>
20 #include <UT/UT_Array.h>
21 #include <UT/UT_BoundingBox.h>
22 #include <UT/UT_Map.h>
23 #include <UT/UT_Matrix4.h>
24 #include <UT/UT_Set.h>
25 #include <UT/UT_StringHolder.h>
26 #include <UT/UT_UniquePtr.h>
27 #include <UT/UT_VectorTypes.h>
28 #include <UT/UT_Vector4.h>
29 
30 class RE_LightList;
31 class RV_Instance;
32 class RV_Render;
33 class RV_ShaderBlock;
34 class RV_ShaderProgram;
37 class RV_VKImage;
39 
40 /// Base class for all light types
42 {
43 public:
44  enum LightType
45  {
50  AREA
51  };
52 
53  LightType type() const { return myType; }
54 
55  bool isHeadlight() const { return myIsHeadlight; }
56  void setHeadlight(bool e) { myIsHeadlight = e; }
57 
58  bool isEnabled() const { return myIsEnabled; }
59  void setEnabled(bool e) { myIsEnabled = e; }
60 
61  bool canShadow() const { return myCanShadow; }
62  void setCanShadow(bool e) { myCanShadow = e; }
63 
64  void setLightID(exint id) { setID(id); }
65 
66  void setInstanceTransforms(const UT_Matrix4FArray &transforms,
67  const UT_Vector4FArray &colors);
68  bool isInstanced() const { return (myInstanceParms.size()>0); }
69  int numInstances() const { return myInstanceParms.size(); }
70 
71  bool initSceneSetForRender(
72  RV_Render *r,
74  UT_UniquePtr<RV_ShaderBlock> &scene_block,
76  bool initLightSetForRender(RV_Render *r,
78  bool bindSets(RV_Render *r, RV_ShaderProgramBase *shader);
79  virtual bool initBlocks(RV_Render *r, const GR_CommonDispOption &opts) = 0;
80  bool isDirty() const { return myDirtyFlag; }
81 
82  // returns number of required shadow render passes (see DM_RenderVulkan.C)
83  virtual unsigned setupShadowRenders(RE_RenderContext,
84  GR_RenderMode &out_render_mode,
85  bool scene_changed,
86  unsigned shadowmap_size,
87  const GR_DistantShadowMapParms&) = 0;
88  virtual RV_ShaderProgram *getShader(bool shadows, bool per_sample,
89  bool is_antialiased,
90  bool is_raytrace) = 0;
91  static RV_ShaderProgram *getAmbientOcclusionShader(bool is_raytrace);
92 
93  virtual bool canRayTraceShadow() const { return false; }
94 
95  // Returns true if the shadowmap render was started, false otherwise.
96  // Eg. returns false when the shadowmap is already up-to-date.
98  unsigned shadowmap_index) {}
101  virtual bool needsShadowMap() = 0;
102  virtual bool hasShadowMap() = 0;
104  virtual void clearShadowMap() {}
105 
106  static bool initShaders(RV_Instance *inst);
107  static void cleanupShaders();
108 
109  void setLightLink(const UT_StringHolder &link) { myLightLink=link; }
110  const UT_StringHolder &lightLink() const { return myLightLink; }
111  virtual void setShadowMask(const UT_StringHolder &mask)
112  { myShadowMask=mask; }
113  const UT_StringHolder &shadowMask() const { return myShadowMask; }
114 
115 protected:
116  GR_Light(const UT_StringHolder &name, LightType type);
117  ~GR_Light() override;
118 
120 
121  bool privInitBlocks(RV_Render *r,
122  void *light_block, int light_size,
123  void *shadow_block, int shadow_size);
124  void privBindTexture(RV_Render *r, const UT_StringHolder &map_name,
125  int rel_op_id, RV_TextureRef &map_id,
126  const UT_StringHolder &sampler_name,
127  const GR_CommonDispOption &opts,
128  RV_TextureParms *tex_parms = nullptr,
129  bool is_cube = false);
130  void initTexParms(RV_Render *r, const GR_CommonDispOption &opts,
131  RV_TextureParms &parms) const;
132 
133  static RV_ShaderProgram *privGetShader(exint tags);
134 
135 #ifdef USE_VULKAN
137  UT_UniquePtr<RV_ShaderBlock> myLightBlock;
138  UT_UniquePtr<RV_ShaderBlock> myShadowBlock;
139  UT_UniquePtr<RV_ShaderBlock> myInstanceBlock;
140 #endif
145 
146  enum
147  {
148  GLOBAL_SET = 0,
149  LIGHT_SET = 1
150  };
151 
152  struct LightTag
153  {
154  exint Cube =0;
155  exint Cylinder =0;
156  exint Distant =0;
157  exint Ellipse =0;
158  exint Ellipsoid =0;
159  exint Forward =0;
160  exint Point =0;
161  exint Rectangle =0;
162  exint Shadow =0;
163  exint Spot =0;
164  exint Ambient =0;
165  exint Env =0;
166  exint PerSample =0;
167  exint AmbOcclusion =0;
168  exint RayTrace =0;
169  };
170 
171  static LightTag Tag;
172 private:
173  struct InstanceParms
174  {
177  };
178  UT_Array<InstanceParms> myInstanceParms;
179  UT_StringHolder myLightLink;
180  LightType myType;
181  uint32
182  myIsHeadlight :1,
183  myCanShadow :1,
184  myIsEnabled :1;
185 
186 };
187 
188 static inline void intrusive_ptr_add_ref(GR_Light *gl) { gl->incref(); }
189 static inline void intrusive_ptr_release(GR_Light *gl) { gl->decref(); }
190 
191 // List of lights currently contributing to the scene
193 {
194 public:
195  uint32 getLightMask(const UT_Set<int> &active) const;
196 
197  bool useHeadlights() const { return myUseHeadlights; }
198  void setUseHeadlights(bool v) { myUseHeadlights = v; }
199 
200  void setGLLights(RE_LightList *list) { myGLLights = list; }
201  const RE_LightList *glLights() const { return myGLLights; }
202  RE_LightList *glLights() { return myGLLights; }
203 
204  exint entries() const { return myList.entries(); }
205 
206  bool hasLight(int id) const
207  {
208  auto entry = myLightMap.find(id);
209  return (entry != myLightMap.end());
210  }
211 
212  // Fetch by light ID
213  GR_LightPtr getLight(int id) const
214  {
215  auto entry = myLightMap.find(id);
216  if(entry != myLightMap.end())
217  return myList(entry->second);
218  return GR_LightPtr();
219  }
220 
221  // Fetch by order in the light list (for masking)
222  GR_LightPtr getLightByIndex(int index) const { return myList(index); }
223 
224  void add(int id, GR_Light *new_light)
225  {
226  UT_ASSERT(!myLightMap.contains(id));
227  myLightMap[id] = int(myList.entries());
228  myList.append(new_light);
229  }
230  bool remove(int id)
231  {
232  auto entry = myLightMap.find(id);
233  if(entry != myLightMap.end())
234  {
235  int index = entry->second;
236  myLightMap.clear();
237  myList.removeIndex(index);
238  for(int i=0; i<myList.entries(); i++)
239  myLightMap[myList(i)->id()] = i;
240  return true;
241  }
242  return false;
243  }
244  void removeAll();
245  void removeAllBut(const UT_Set<int> &active_lights);
246 
247 private:
248  bool myUseHeadlights = false;
249  RE_LightList *myGLLights = nullptr;
250  UT_Map<int,int> myLightMap;
251  UT_Array<GR_LightPtr> myList;
252 };
253 
254 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
bool isInstanced() const
Definition: GR_Light.h:68
void setLightID(exint id)
Definition: GR_Light.h:64
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
void setCanShadow(bool e)
Definition: GR_Light.h:62
Base class for various things that can appear in a scene outside of geometry.
Definition: GR_SceneItem.h:19
bool mySetBound
Definition: GR_Light.h:143
const GLdouble * v
Definition: glcorearb.h:837
void decref()
Definition: GR_SceneItem.h:33
const UT_StringHolder & shadowMask() const
Definition: GR_Light.h:113
int64 exint
Definition: SYS_Types.h:125
Opaque reference to a texture stored in the RV_TextureCache.
Definition: RV_Type.h:203
GR_LightPtr getLightByIndex(int index) const
Definition: GR_Light.h:222
virtual void clearShadowMap()
Definition: GR_Light.h:104
bool hasLight(int id) const
Definition: GR_Light.h:206
UT_IntrusivePtr< GR_Light > GR_LightPtr
Definition: GR_Defines.h:402
UT_NON_COPYABLE(GR_SceneItem)
Temporary container for either a RV_Render and an RE_Render.
LightType type() const
Definition: GR_Light.h:53
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void add(int id, GR_Light *new_light)
Definition: GR_Light.h:224
virtual void startShadowRender(RE_RenderContext rc, unsigned shadowmap_index)
Definition: GR_Light.h:97
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
void setID(int id)
Definition: GR_SceneItem.h:40
GR_LightPtr getLight(int id) const
Definition: GR_Light.h:213
GR_RenderMode
Definition: GR_Defines.h:48
bool myDirtyFlag
Definition: GR_Light.h:141
bool canShadow() const
Definition: GR_Light.h:61
GLint GLuint mask
Definition: glcorearb.h:124
virtual bool canRayTraceShadow() const
Definition: GR_Light.h:93
Base class for all light types.
Definition: GR_Light.h:41
RV_API void cleanupShaders()
const UT_StringHolder & lightLink() const
Definition: GR_Light.h:110
bool myShadowDirtyFlag
Definition: GR_Light.h:142
#define GR_API
Definition: GR_API.h:10
static LightTag Tag
Definition: GR_Light.h:171
Wrapper around hboost::intrusive_ptr.
GLuint id
Definition: glcorearb.h:655
bool isEnabled() const
Definition: GR_Light.h:58
GLuint const GLchar * name
Definition: glcorearb.h:786
bool useHeadlights() const
Definition: GR_Light.h:197
void setLightLink(const UT_StringHolder &link)
Definition: GR_Light.h:109
bool isDirty() const
Definition: GR_Light.h:80
GA_API const UT_StringHolder transform
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:44
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
void setEnabled(bool e)
Definition: GR_Light.h:59
int numInstances() const
Definition: GR_Light.h:69
virtual void attachShadowMap(RE_RenderContext)
Definition: GR_Light.h:103
RV_API bool initShaders(RV_Instance *inst)
GLuint shader
Definition: glcorearb.h:785
GA_API const UT_StringHolder parms
virtual void finishShadowRenders(RE_RenderContext)
Definition: GR_Light.h:100
UT_StringHolder myShadowMask
Definition: GR_Light.h:144
GLuint color
Definition: glcorearb.h:1261
void setGLLights(RE_LightList *list)
Definition: GR_Light.h:200
GLuint index
Definition: glcorearb.h:786
unsigned int uint32
Definition: SYS_Types.h:40
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
void setHeadlight(bool e)
Definition: GR_Light.h:56
exint entries() const
Definition: GR_Light.h:204
GLboolean r
Definition: glcorearb.h:1222
virtual void finishShadowRender(RE_RenderContext)
Definition: GR_Light.h:99
bool isHeadlight() const
Definition: GR_Light.h:55
void incref()
Definition: GR_SceneItem.h:31
virtual void setShadowMask(const UT_StringHolder &mask)
Definition: GR_Light.h:111
RE_LightList * glLights()
Definition: GR_Light.h:202
void setUseHeadlights(bool v)
Definition: GR_Light.h:198
const RE_LightList * glLights() const
Definition: GR_Light.h:201