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_Matrix4.h>
28 
29 class RE_LightList;
30 class RV_Instance;
31 class RV_Render;
32 class RV_ShaderBlock;
33 class RV_ShaderProgram;
36 class RV_VKImage;
38 
39 /// Base class for all light types
41 {
42 public:
43  enum LightType
44  {
49  AREA
50  };
51 
52  LightType type() const { return myType; }
53 
54  bool isHeadlight() const { return myIsHeadlight; }
55  void setHeadlight(bool e) { myIsHeadlight = e; }
56 
57  bool isEnabled() const { return myIsEnabled; }
58  void setEnabled(bool e) { myIsEnabled = e; }
59 
60  void setLightID(exint id) { setID(id); }
61 
62  bool initSceneSetForRender(
63  RV_Render *r,
65  UT_UniquePtr<RV_ShaderBlock> &scene_block,
67  bool initLightSetForRender(RV_Render *r,
69  bool bindSets(RV_Render *r, RV_ShaderProgramBase *shader);
70  virtual bool initBlocks(RV_Render *r, const GR_CommonDispOption &opts) = 0;
71 
72  // returns number of required shadow render passes (see DM_RenderVulkan.C)
73  virtual unsigned setupShadowRenders(RE_RenderContext,
74  GR_RenderMode &out_render_mode,
75  bool scene_changed,
76  unsigned shadowmap_size,
77  const GR_DistantShadowMapParms&) = 0;
78  virtual RV_ShaderProgram *getShader(bool shadows, bool per_sample,
79  bool is_antialiased) = 0;
80  static RV_ShaderProgram *getAmbientOcclusionShader();
81  // Returns true if the shadowmap render was started, false otherwise.
82  // Eg. returns false when the shadowmap is already up-to-date.
84  unsigned shadowmap_index) {}
87  virtual bool hasShadowMap() = 0;
89 
90  static bool initShaders(RV_Instance *inst);
91  static void cleanupShaders();
92 
93  void setLightLink(const UT_StringHolder &link) { myLightLink=link; }
94  const UT_StringHolder &lightLink() const { return myLightLink; }
95  void setShadowMask(const UT_StringHolder &mask) { myShadowMask=mask; }
96  const UT_StringHolder &shadowMask() const { return myShadowMask; }
97 
98 protected:
99  GR_Light(const UT_StringHolder &name, LightType type);
100  ~GR_Light() override;
101 
103 
104  bool privInitBlocks(RV_Render *r,
105  void *light_block, int light_size,
106  void *shadow_block, int shadow_size);
107  void privBindTexture(RV_Render *r, const UT_StringHolder &map_name,
108  int rel_op_id, RV_TextureRef &map_id,
109  const UT_StringHolder &sampler_name,
110  const GR_CommonDispOption &opts,
111  RV_TextureParms *tex_parms = nullptr,
112  bool is_cube = false);
113  void initTexParms(RV_Render *r, const GR_CommonDispOption &opts,
114  RV_TextureParms &parms) const;
115 
116  static RV_ShaderProgram *privGetShader(exint tags);
117 
118 #ifdef USE_VULKAN
120  UT_UniquePtr<RV_ShaderBlock> myLightBlock;
121  UT_UniquePtr<RV_ShaderBlock> myShadowBlock;
122 #endif
126 
127  enum
128  {
129  GLOBAL_SET = 0,
130  LIGHT_SET = 1
131  };
132 
133 private:
134  UT_StringHolder myLightLink;
135  UT_StringHolder myShadowMask;
136  LightType myType;
137  uint32
138  myIsHeadlight :1,
139  myIsEnabled :1;
140 };
141 
142 static inline void intrusive_ptr_add_ref(GR_Light *gl) { gl->incref(); }
143 static inline void intrusive_ptr_release(GR_Light *gl) { gl->decref(); }
144 
145 // List of lights currently contributing to the scene
147 {
148 public:
149  uint32 getLightMask(const UT_Set<int> &active) const;
150 
151  void setGLLights(RE_LightList *list) { myGLLights = list; }
152  const RE_LightList *glLights() const { return myGLLights; }
153  RE_LightList *glLights() { return myGLLights; }
154 
155  exint entries() const { return myList.entries(); }
156 
157  bool hasLight(int id) const
158  {
159  auto entry = myLightMap.find(id);
160  return (entry != myLightMap.end());
161  }
162 
163  // Fetch by light ID
164  GR_LightPtr getLight(int id) const
165  {
166  auto entry = myLightMap.find(id);
167  if(entry != myLightMap.end())
168  return myList(entry->second);
169  return GR_LightPtr();
170  }
171 
172  // Fetch by order in the light list (for masking)
173  GR_LightPtr getLightByIndex(int index) const { return myList(index); }
174 
175  void add(int id, GR_Light *new_light)
176  {
177  myLightMap[id] = int(myList.entries());
178  myList.append(new_light);
179  }
180  bool remove(int id)
181  {
182  auto entry = myLightMap.find(id);
183  if(entry != myLightMap.end())
184  {
185  int index = entry->second;
186  myLightMap.clear();
187  myList.removeIndex(index);
188  for(int i=0; i<myList.entries(); i++)
189  myLightMap[myList(i)->id()] = i;
190  return true;
191  }
192  return false;
193  }
194  void removeAll();
195  void removeAllBut(const UT_Set<int> &active_lights);
196 
197 private:
198  RE_LightList *myGLLights = nullptr;
199  UT_Map<int,int> myLightMap;
200  UT_Array<GR_LightPtr> myList;
201 };
202 
203 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
void setLightID(exint id)
Definition: GR_Light.h:60
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
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:125
void decref()
Definition: GR_SceneItem.h:33
const UT_StringHolder & shadowMask() const
Definition: GR_Light.h:96
int64 exint
Definition: SYS_Types.h:125
Opaque reference to a texture stored in the RV_TextureCache.
Definition: RV_Type.h:182
GR_LightPtr getLightByIndex(int index) const
Definition: GR_Light.h:173
bool hasLight(int id) const
Definition: GR_Light.h:157
UT_IntrusivePtr< GR_Light > GR_LightPtr
Definition: GR_Defines.h:400
UT_NON_COPYABLE(GR_SceneItem)
Temporary container for either a RV_Render and an RE_Render.
LightType type() const
Definition: GR_Light.h:52
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:175
virtual void startShadowRender(RE_RenderContext rc, unsigned shadowmap_index)
Definition: GR_Light.h:83
void setID(int id)
Definition: GR_SceneItem.h:40
GR_LightPtr getLight(int id) const
Definition: GR_Light.h:164
GR_RenderMode
Definition: GR_Defines.h:48
bool myDirtyFlag
Definition: GR_Light.h:123
GLint GLuint mask
Definition: glcorearb.h:124
Base class for all light types.
Definition: GR_Light.h:40
const UT_StringHolder & lightLink() const
Definition: GR_Light.h:94
bool myShadowDirtyFlag
Definition: GR_Light.h:124
#define GR_API
Definition: GR_API.h:10
Wrapper around hboost::intrusive_ptr.
GLuint id
Definition: glcorearb.h:655
bool isEnabled() const
Definition: GR_Light.h:57
GLuint const GLchar * name
Definition: glcorearb.h:786
void setLightLink(const UT_StringHolder &link)
Definition: GR_Light.h:93
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:38
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:58
virtual void attachShadowMap(RE_RenderContext)
Definition: GR_Light.h:88
GLuint shader
Definition: glcorearb.h:785
virtual void finishShadowRenders(RE_RenderContext)
Definition: GR_Light.h:86
void setGLLights(RE_LightList *list)
Definition: GR_Light.h:151
GLuint index
Definition: glcorearb.h:786
unsigned int uint32
Definition: SYS_Types.h:40
void setShadowMask(const UT_StringHolder &mask)
Definition: GR_Light.h:95
void setHeadlight(bool e)
Definition: GR_Light.h:55
exint entries() const
Definition: GR_Light.h:155
GLboolean r
Definition: glcorearb.h:1222
virtual void finishShadowRender(RE_RenderContext)
Definition: GR_Light.h:85
type
Definition: core.h:1059
bool isHeadlight() const
Definition: GR_Light.h:54
void incref()
Definition: GR_SceneItem.h:31
RE_LightList * glLights()
Definition: GR_Light.h:153
const RE_LightList * glLights() const
Definition: GR_Light.h:152