VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgLightingComponent.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2022 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
18 
21 
24 
26 
28 
29 #include <osg/Uniform>
30 #include <osg/Texture2D>
31 
32 #include <vector>
33 #include <unordered_map>
34 #include <array>
35 
36 #include <tbb/atomic.h>
37 
38 namespace osg
39 {
40  class Matrixd;
41 }
42 
43 namespace makVrv
44 {
45  class DtLight;
46  class DtLightData;
47  class DtTileSpaceLightGrid;
48  class DtGlSimpleTexture;
49  class DtGlBuffer;
50  class DtGlTextureBufferObject;
51  class DeDe;
52 
53  class TextureApplyAttribute;
54  class TextureBufferObjectApplyAttribute;
55  class DtUniformBufferObjectApplyAttribute;
56  class DtShaderStorageBufferApplyAttribute;
57 
58  class DtLightingComponentShaderConstants;
59 
60  class DtOsgLightingComponentUboCallback;
61 
69  {
70  public:
73 
75  virtual ~DtOsgLightingComponent();
76  private:
78  DtOsgLightingComponent() = delete;
79 
82 
84  DtOsgLightingComponent& operator=(const DtOsgLightingComponent&) = delete;
85 
86  public:
88  virtual void update(const VectorLights& lights, const osg::State& state, const osg::Camera* camera);
89 
91  virtual const Vector2_uint32& tileSize(void) const;
92 
94  virtual const Vector2_uint32& gridMaxDims(void) const;
95 
97  virtual void updateLightSourceIndexBufferHandle(const osg::Camera* camera, DtGlBuffer* handle, int maxNumLightSources);
98 
100  virtual osg::Uniform* getEnableLightingUniform() const;
101 
103  virtual void setAmbientFactor(float ambientFactor);
104 
106  virtual void setUseGlobalAmbient(bool useGlobalAmbient);
107 
109  virtual void setDiffuseFactor(float diffuseFactor);
110 
112  virtual void setUseGlobalDiffuse(bool useGlobalDiffuse);
113 
115  virtual void setUseHDR(bool useHDR);
116 
118  virtual void slot_reloadShader();
119 
121  virtual void setDirty(bool isDirty) { myDirty = isDirty; }
122 
124  virtual void setEmissionFactor(float emissionFactor);
125 
127  virtual bool dirty() const { return myDirty; }
128 
129  virtual void releaseGLObjects(void);
130 
131  // DtOsgStateComponent interface
133  virtual bool install(osg::StateSet* stateset);
134 
136  virtual bool uninstall(osg::StateSet* stateset);
137 
139  virtual bool isInstalled(void) const;
140 
142  virtual void setComponentVisualizationMode(int mode);
143 
145  virtual const DtLightingComponentShaderConstants* shaderConstants(void) const;
146 
148  virtual DtLightingComponentShaderConstants* shaderConstants(void);
149  public:
150  static int textureStartOffset(void);
151 
152  protected:
153  virtual void setLightPointScale(double scale);
154  virtual void setDynamicLightScale(double scale);
155  virtual void setEmissiveTextureScale(double scale);
156  virtual void setSpecularScale(double scale);
157  virtual void setShininessScale(double scale);
158 
159  virtual osg::ref_ptr<osg::Uniform> createUniform(const std::string& name, osg::Uniform::Type type, int count=1);
160 
161  virtual void packLights(const osg::Matrixd& normalMatrix, const VectorLights& lights, const osg::State& state);
162  virtual void updateTextureLightDataGrid(void);
164  virtual void updateTiledShadingData(const VectorLights& lights, const osg::State& state, const osg::Camera* camera);
165 
167  virtual void updateTileLightIndexList(const std::vector<Matrix4_64>& projectionMatrix
168  , const std::vector<Vector3_64>& vWorldEye
169  , const std::vector<Vector3_64>& vWorldCenter
170  , const std::vector<Vector3_64>& vWorldUp
171  , const Vector2_uint32& viewportSize
172  , const osg::Camera* camera);
174  virtual void initializeColorRampTexture( );
175 
177  virtual int lightGridSize();
178 
180  virtual int maxUboSize();
181 
183  virtual void setUpDebugTextureComponentMode(void);
184 
186  virtual std::string findDebugTexturePath(void) const;
187 
188  protected:
189 
192 
193  std::vector< osg::ref_ptr<osg::Uniform> > myUniforms;
194 
195  // Parameters of lights are stored in this structure
197 
198  std::array<DtGlBuffer*, DtBindingManager::theLightBlockCount> myLightUBO;
199 
201 
208 
209  typedef std::unordered_map<DtGlBuffer*, int> BufferToLightIndexMap;
210 
213  {
214  public:
216  : myBufferToLightIndexMap()
217  , myBufferChunkCount(0)
218  , myTotalCount(0)
219  {
220  //intentional nop
221  }
222  public:
223  //Map of buffers for each indirect geoemetry, buffer pointer to number of lights in the buffer
227  };
228 
229  //map for holding a TileLightIndexInfo for each camera
230  typedef std::unordered_map<const osg::Camera*, TileLightIndexInfo> CameraToTileLightIndexMapInfoMap;
232 
235 
239 
240  DtGlBuffer* myGpuShaderUbo = nullptr;
242  DtLightingComponentShaderConstants* myShaderConstants = nullptr;
243 
244  friend class DtOsgLightingComponentUboCallback;
245  DtOsgLightingComponentUboCallback* myUboCallback = nullptr;
246 
250 
254 
255  bool myUseHDR;
256  bool myDirty;
257 
262 
264 
266 
268 
270 
272 
273  GLint myMaxUboSizeInBytes; // queried from GL
274  int myLightGridSize; // max size of light grid
275 
276  const DtBindingManager& myBindingManager; // reference to the binding manager
277 
279 
280  //Constants for scaling the HDR scalars to values so the GUI can be a single decimal digit.
281  static const float theLightPointHdrScalar;
282  static const float theDynamicLightHdrScalar;
283  static const float theEmissiveTextureHdrScalar;
284 
286  };
287 
288 
291 
293  template <>
294  inline const char* creatorTypeName<DtOsgLightingComponent>(void) { return "DtOsgLightingComponentCreator"; }
295 }
Contains the DtOsgTextureBufferObjectApplyAttribute class.
std::vector< osg::ref_ptr< osg::Uniform > > myUniforms
Definition: DtOsgLightingComponent.h:193
Helper class to pack lights into a buffer/texture.
Definition: DtLightData.h:41
virtual void setDirty(bool isDirty)
Sets dirty state for reinstallation.
Definition: DtOsgLightingComponent.h:121
bool myUseGlobalAmbient
Definition: DtOsgLightingComponent.h:248
DtGlSimpleTexture * myColorRampTexture
Definition: DtOsgLightingComponent.h:233
Definition: DtLightingComponentShaderConstants.h:28
osg::ref_ptr< osg::Uniform > myEnableLightingUniform
Definition: DtOsgLightingComponent.h:190
DtLightData * myLightGrid
Definition: DtOsgLightingComponent.h:196
CameraToTileLightIndexMapInfoMap myCameraToTileLightIndexMapInfoMap
Definition: DtOsgLightingComponent.h:231
osg::ref_ptr< osg::Uniform > myBDRFLutUniform
Definition: DtOsgLightingComponent.h:259
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
bool myUseHDR
Definition: DtOsgLightingComponent.h:255
Wrapper for OpenGL Texture.
Definition: DtGlSimpleTexture.h:35
Contains the DtBufferObjectApplyAttribute class.
const DtBindingManager & myBindingManager
Definition: DtOsgLightingComponent.h:276
Contains the vrvOsg::DtBindingManager class.
Contains the DtOsgTextureApplyAttribute class.
osg::ref_ptr< osg::Uniform > myAmbientFactorUniform
Definition: DtOsgLightingComponent.h:247
osg::ref_ptr< osg::Uniform > myDiffuseFactorUniform
Definition: DtOsgLightingComponent.h:251
struct for holding information about a camera&#39;s tile light index map
Definition: DtOsgLightingComponent.h:212
4 dimensional vector
bool myDirty
Definition: DtOsgLightingComponent.h:256
const char * creatorTypeName< DtOsgLightingComponent >(void)
template specialization for the creator (pass the class being created to the creatorTypeName template...
Definition: DtOsgLightingComponent.h:294
osg::ref_ptr< osg::Uniform > myUseGlobalDiffuseUniform
Definition: DtOsgLightingComponent.h:253
TileLightIndexInfo()
Definition: DtOsgLightingComponent.h:215
osg::ref_ptr< osg::Image > myBrdfLutImage
Definition: DtOsgLightingComponent.h:261
osg::ref_ptr< osg::Uniform > myLightingOffClampUniform
Definition: DtOsgLightingComponent.h:191
DtSignalConnectionManager myConnections
Definition: DtOsgLightingComponent.h:269
static const float theEmissiveTextureHdrScalar
Definition: DtOsgLightingComponent.h:283
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:22
Manage interface block bindings. This knowledge was previously distributed several places in the code...
Definition: DtBindingManager.h:43
int myBufferChunkCount
Definition: DtOsgLightingComponent.h:225
osg::ref_ptr< DtUniformBufferObjectApplyAttribute > myUniformBufferObjectApplyAttribute
Definition: DtOsgLightingComponent.h:237
osg::ref_ptr< osg::Uniform > myModelTypeDefaultUniform
Definition: DtOsgLightingComponent.h:263
osg::ref_ptr< osg::Texture2D > myBDRFLutTexture
Definition: DtOsgLightingComponent.h:260
Light class.
osg::ref_ptr< osg::Uniform > myUseGlobalAmbientUniform
Definition: DtOsgLightingComponent.h:249
DtGlBuffer * myTileLightIntersectionDataSsbo
Definition: DtOsgLightingComponent.h:206
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
osg::ref_ptr< osg::Texture > myDebugTexture
Definition: DtOsgLightingComponent.h:285
bool myIsInstalled
Definition: DtOsgLightingComponent.h:267
std::unordered_map< DtGlBuffer *, int > BufferToLightIndexMap
Definition: DtOsgLightingComponent.h:209
osg::ref_ptr< osg::Uniform > myUpVectorUniform
Definition: DtOsgLightingComponent.h:258
static const float theDynamicLightHdrScalar
Definition: DtOsgLightingComponent.h:282
DtLightComputeProgram * myLightComputeProgram
Definition: DtOsgLightingComponent.h:278
Contains makVrv::DtLightComputeProgram class.
osg::ref_ptr< osg::Uniform > myColorRampTextureUniform
Definition: DtOsgLightingComponent.h:234
Class doing all the heavy lifting in regards of forward+ lighting.
Definition: DtTileSpaceLightGrid.h:40
static const float theLightPointHdrScalar
Definition: DtOsgLightingComponent.h:281
bool myUseGlobalDiffuse
Definition: DtOsgLightingComponent.h:252
int myLightGridSize
Definition: DtOsgLightingComponent.h:274
A generic OpenGL buffer. This can be: -&gt; a vertex buffer -&gt; an index buffer -&gt; a shader storage buffe...
Definition: DtGlBuffer.h:29
DtVirtualBaseClassCreator< DtOsgLightingComponent > DtOsgLightingComponentCreator
creator
Definition: DtOsgLightingComponent.h:290
osg::ref_ptr< DtShaderStorageBufferApplyAttribute > myShaderStorageBufferApplyAttribute
Definition: DtOsgLightingComponent.h:238
VectorLights myViewSpaceLightsScratchPad
Definition: DtOsgLightingComponent.h:265
Base class to provide boost signal/slot management.
int myGpuShaderUboBinding
Definition: DtOsgLightingComponent.h:241
osg::ref_ptr< TextureApplyAttribute > myTextureApplyAttribute
Definition: DtOsgLightingComponent.h:236
Base class for components that affect the state on a subset of the scene graph, injecting state...
Definition: DtOsgStateComponent.h:34
int myTotalCount
Definition: DtOsgLightingComponent.h:226
const char int mode
Definition: ioapi.h:38
std::array< DtGlBuffer *, DtBindingManager::theLightBlockCount > myLightUBO
Definition: DtOsgLightingComponent.h:198
Contains DLL export macros.
DtTileSpaceLightGrid * myTileSpaceLightGrid
Definition: DtOsgLightingComponent.h:200
DtGlBuffer * myTileLightIndexBuffersInfoSsbo
Definition: DtOsgLightingComponent.h:207
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:70
Contains makVrv::DtOsgStateComponent class.
DtGlBuffer * myTileLightIndexListSsboPreCompute
Definition: DtOsgLightingComponent.h:205
DtGlBuffer * myTileLightIndexListSsbo
Holds a set of indexes, one per light tile. This can get big, so cannot fit in a UBO.
Definition: DtOsgLightingComponent.h:204
virtual bool dirty() const
Checks if component needs to be re-installed.
Definition: DtOsgLightingComponent.h:127
std::unordered_map< const osg::Camera *, TileLightIndexInfo > CameraToTileLightIndexMapInfoMap
Definition: DtOsgLightingComponent.h:230
BufferToLightIndexMap myBufferToLightIndexMap
Definition: DtOsgLightingComponent.h:224
static bool bColorRampTextureWasTried
Definition: DtOsgLightingComponent.h:271
State component that injects lighting shaders and uniforms into a state set. It also has a DtLightCom...
Definition: DtOsgLightingComponent.h:68
Class that encapsulates the 2 pass (setup, sort) computation of lights affecting the screen space til...
Definition: DtLightComputeProgram.h:46
GLint myMaxUboSizeInBytes
Definition: DtOsgLightingComponent.h:273

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)