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 RV_Instance;
31 class RV_Render;
32 class RV_ShaderBlock;
33 class RV_ShaderProgram;
36 class RV_TextureRef;
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  bool shadowEnabled() const { return myShadowEnabled; }
65  void setShadowEnabled(bool s) { myShadowEnabled = s; }
66 
67  void setLightID(exint id) { setID(id); }
68 
69  void setInstanceTransforms(const UT_Matrix4FArray &transforms,
70  const UT_Vector4FArray &colors);
71  bool isInstanced() const { return (myInstanceParms.size()>0); }
72  int numInstances() const { return myInstanceParms.size(); }
73 
74  bool initSceneSetForRender(
75  RV_Render *r,
77  UT_UniquePtr<RV_ShaderBlock> &scene_block,
79  bool initLightSetForRender(RV_Render *r,
81  bool bindSets(RV_Render *r, RV_ShaderProgramBase *shader);
82  virtual bool initBlocks(RV_Render *r, const GR_CommonDispOption &opts) = 0;
83  bool isDirty() const { return myDirtyFlag; }
84 
85  // returns number of required shadow render passes (see DM_RenderVulkan.C)
86  virtual unsigned setupShadowRenders(RE_RenderContext,
87  GR_RenderMode &out_render_mode,
88  bool scene_changed,
89  unsigned shadowmap_size,
90  const GR_DistantShadowMapParms&) = 0;
91  virtual RV_ShaderProgram *getShader(bool shadows, bool per_sample,
92  bool is_antialiased,
93  bool is_raytrace) = 0;
94  static RV_ShaderProgram *getAmbientOcclusionShader(bool is_raytrace);
95 
96  virtual bool canRayTraceShadow() const { return false; }
97 
98  // Returns true if the shadowmap render was started, false otherwise.
99  // Eg. returns false when the shadowmap is already up-to-date.
101  unsigned shadowmap_index) {}
104  virtual bool needsShadowMap() = 0;
105  virtual bool hasShadowMap() = 0;
107  virtual void clearShadowMap() {}
108 
109  // Secondary "gsplats-excluded" shadow map used to suppress gsplats
110  // self-shadowing.
112  GR_RenderMode &out_render_mode,
113  bool scene_changed,
114  unsigned shadowmap_size,
116  { return 0; }
118  unsigned shadowmap_index) {}
121  virtual bool hasGsplatShadowMap() { return false; }
123  virtual void clearGsplatShadowMap() {}
124 
125  static bool initShaders(RV_Instance *inst);
126  static void cleanupShaders();
127 
128  void setLightLink(const UT_StringHolder &link) { myLightLink=link; }
129  const UT_StringHolder &lightLink() const { return myLightLink; }
130  virtual void setShadowMask(const UT_StringHolder &mask)
131  { myShadowMask=mask; }
132  const UT_StringHolder &shadowMask() const { return myShadowMask; }
133 
134 protected:
135  GR_Light(const UT_StringHolder &name, LightType type);
136  ~GR_Light() override;
137 
139 
140  bool privInitBlocks(RV_Render *r,
141  void *light_block, int light_size,
142  void *shadow_block, int shadow_size);
143  void privBindTexture(RV_Render *r, const UT_StringHolder &map_name,
144  int rel_op_id, RV_TextureRef &map_id,
145  const UT_StringHolder &sampler_name,
146  const GR_CommonDispOption &opts,
147  RV_TextureParms *tex_parms = nullptr,
148  bool is_cube = false);
149  void initTexParms(RV_Render *r, const GR_CommonDispOption &opts,
150  RV_TextureParms &parms) const;
151 
152  static RV_ShaderProgram *privGetShader(exint tags);
153 
158 
163 
164  enum
165  {
166  GLOBAL_SET = 0,
167  LIGHT_SET = 1
168  };
169 
170  struct LightTag
171  {
172  exint Cube =0;
174  exint Distant =0;
175  exint Ellipse =0;
177  exint Forward =0;
178  exint Point =0;
179  exint Rectangle =0;
180  exint Shadow =0;
181  exint Spot =0;
182  exint Ambient =0;
183  exint Env =0;
184  exint PerSample =0;
185  exint AmbOcclusion =0;
186  exint RayTrace =0;
187  exint QualityShadows =0;
188  };
189 
190  static LightTag Tag;
191 private:
192  struct InstanceParms
193  {
196  };
197  UT_Array<InstanceParms> myInstanceParms;
198  UT_StringHolder myLightLink;
199  LightType myType;
200  uint32
201  myIsHeadlight :1,
202  myCanShadow :1,
203  myShadowEnabled: 1,
204  myIsEnabled :1;
205 
206 };
207 
208 static inline void intrusive_ptr_add_ref(GR_Light *gl) { gl->incref(); }
209 static inline void intrusive_ptr_release(GR_Light *gl) { gl->decref(); }
210 
211 // List of lights currently contributing to the scene
213 {
214 public:
215  uint32 getLightMask(const UT_Set<int> &active) const;
216 
217  bool useHeadlights() const { return myUseHeadlights; }
218  void setUseHeadlights(bool v) { myUseHeadlights = v; }
219 
220  void setShadowingLight(int id) { myShadowingLight = id; }
222  { return getLight(myShadowingLight).get(); }
223 
224  exint entries() const { return myList.entries(); }
225 
226  bool hasLight(int id) const
227  {
228  auto entry = myLightMap.find(id);
229  return (entry != myLightMap.end());
230  }
231 
232  // Fetch by light ID
233  GR_LightPtr getLight(int id) const
234  {
235  auto entry = myLightMap.find(id);
236  if(entry != myLightMap.end())
237  return myList(entry->second);
238  return GR_LightPtr();
239  }
240 
241  // Fetch by order in the light list (for masking)
242  GR_LightPtr getLightByIndex(int index) const { return myList(index); }
243 
244  void add(int id, GR_Light *new_light)
245  {
246  UT_ASSERT(!myLightMap.contains(id));
247  myLightMap[id] = int(myList.entries());
248  myList.append(new_light);
249  }
250  bool remove(int id)
251  {
252  auto entry = myLightMap.find(id);
253  if(entry != myLightMap.end())
254  {
255  int index = entry->second;
256  myLightMap.clear();
257  myList.removeIndex(index);
258  for(int i=0; i<myList.entries(); i++)
259  myLightMap[myList(i)->id()] = i;
260  return true;
261  }
262  return false;
263  }
264  void removeAll();
265  void removeAllBut(const UT_Set<int> &active_lights);
266 
267 private:
268  bool myUseHeadlights = false;
269  UT_Map<int,int> myLightMap;
270  UT_Array<GR_LightPtr> myList;
271  int myShadowingLight = -1;
272 };
273 
274 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
bool isInstanced() const
Definition: GR_Light.h:71
void setLightID(exint id)
Definition: GR_Light.h:67
virtual void finishGsplatShadowRenders(RE_RenderContext)
Definition: GR_Light.h:120
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
void setCanShadow(bool e)
Definition: GR_Light.h:62
UT_UniquePtr< RV_ShaderBlock > myShadowBlock
Definition: GR_Light.h:156
UT_UniquePtr< RV_ShaderBlock > myInstanceBlock
Definition: GR_Light.h:157
Base class for various things that can appear in a scene outside of geometry.
Definition: GR_SceneItem.h:19
virtual void startGsplatShadowRender(RE_RenderContext, unsigned shadowmap_index)
Definition: GR_Light.h:117
bool mySetBound
Definition: GR_Light.h:161
const GLdouble * v
Definition: glcorearb.h:837
void decref()
Definition: GR_SceneItem.h:33
const UT_StringHolder & shadowMask() const
Definition: GR_Light.h:132
int64 exint
Definition: SYS_Types.h:125
GLdouble s
Definition: glad.h:3009
Opaque reference to a texture stored in the RV_TextureCache.
Definition: RV_TextureRef.h:21
GR_LightPtr getLightByIndex(int index) const
Definition: GR_Light.h:242
virtual void clearShadowMap()
Definition: GR_Light.h:107
bool hasLight(int id) const
Definition: GR_Light.h:226
UT_IntrusivePtr< GR_Light > GR_LightPtr
Definition: GR_Defines.h:412
virtual unsigned setupGsplatShadowRenders(RE_RenderContext, GR_RenderMode &out_render_mode, bool scene_changed, unsigned shadowmap_size, const GR_DistantShadowMapParms &)
Definition: GR_Light.h:111
UT_NON_COPYABLE(GR_SceneItem)
Temporary container for either a RV_Render and an RE_Render.
virtual void clearGsplatShadowMap()
Definition: GR_Light.h:123
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 setShadowEnabled(bool s)
Definition: GR_Light.h:65
void add(int id, GR_Light *new_light)
Definition: GR_Light.h:244
virtual void startShadowRender(RE_RenderContext rc, unsigned shadowmap_index)
Definition: GR_Light.h:100
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:233
GR_RenderMode
Definition: GR_Defines.h:48
const GR_Light * getShadowingLight() const
Definition: GR_Light.h:221
bool myDirtyFlag
Definition: GR_Light.h:159
bool canShadow() const
Definition: GR_Light.h:61
GLint GLuint mask
Definition: glcorearb.h:124
virtual bool canRayTraceShadow() const
Definition: GR_Light.h:96
Base class for all light types.
Definition: GR_Light.h:41
RV_API void cleanupShaders()
const UT_StringHolder & lightLink() const
Definition: GR_Light.h:129
bool myShadowDirtyFlag
Definition: GR_Light.h:160
#define GR_API
Definition: GR_API.h:10
static LightTag Tag
Definition: GR_Light.h:190
Wrapper around hboost::intrusive_ptr.
UT_UniquePtr< RV_ShaderBlock > myLightBlock
Definition: GR_Light.h:155
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:217
void setLightLink(const UT_StringHolder &link)
Definition: GR_Light.h:128
virtual void finishGsplatShadowRender(RE_RenderContext)
Definition: GR_Light.h:119
bool isDirty() const
Definition: GR_Light.h:83
GA_API const UT_StringHolder transform
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
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:72
virtual bool hasGsplatShadowMap()
Definition: GR_Light.h:121
virtual void attachShadowMap(RE_RenderContext)
Definition: GR_Light.h:106
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:103
UT_StringHolder myShadowMask
Definition: GR_Light.h:162
GLuint color
Definition: glcorearb.h:1261
UT_UniquePtr< RV_ShaderVariableSet > myLightSet
Definition: GR_Light.h:154
GLuint index
Definition: glcorearb.h:786
void setShadowingLight(int id)
Definition: GR_Light.h:220
unsigned int uint32
Definition: SYS_Types.h:40
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
bool shadowEnabled() const
Definition: GR_Light.h:64
void setHeadlight(bool e)
Definition: GR_Light.h:56
exint entries() const
Definition: GR_Light.h:224
GLboolean r
Definition: glcorearb.h:1222
virtual void finishShadowRender(RE_RenderContext)
Definition: GR_Light.h:102
virtual void attachGsplatShadowMap(RE_RenderContext)
Definition: GR_Light.h:122
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:130
void setUseHeadlights(bool v)
Definition: GR_Light.h:218