VR-Forces 4.10 Class Documentation
 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) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
19 
22 
24 
26 
27 #include <osg/Uniform>
28 #include <osg/Texture2D>
29 
30 #include <vector>
31 #include <unordered_map>
32 #include <array>
33 
34 #include <tbb/atomic.h>
35 
36 namespace osg
37 {
38  class Matrixd;
39 }
40 
41 namespace makVrv
42 {
43  class DtLight;
44  class DtLightData;
45  class DtTileSpaceLightGrid;
46  class DtGlSimpleTexture;
47  class DtGlBuffer;
48  class DtGlTextureBufferObject;
49  class DeDe;
50 
51  class TextureApplyAttribute;
52  class TextureBufferObjectApplyAttribute;
53  class DtUniformBufferObjectApplyAttribute;
54  class DtShaderStorageBufferApplyAttribute;
55 
63  {
64  public:
67 
69  virtual ~DtOsgLightingComponent();
70  private:
72  DtOsgLightingComponent() = delete;
73 
76 
78  DtOsgLightingComponent& operator=(const DtOsgLightingComponent&) = delete;
79 
80  public:
82  virtual void update(const VectorLights& lights, const osg::State& state, const osg::Camera* camera);
83 
85  virtual const Vector2_uint32& tileSize(void) const;
86 
88  virtual const Vector2_uint32& gridMaxDims(void) const;
89 
91  virtual void updateLightSourceIndexBufferHandle(const osg::Camera* camera, DtGlBuffer* handle, int maxNumLightSources);
92 
94  virtual osg::Uniform* getEnableLightingUniform() const;
95 
97  virtual void setAmbientFactor(float ambientFactor);
98 
100  virtual void setUseGlobalAmbient(bool useGlobalAmbient);
101 
103  virtual void setDiffuseFactor(float diffuseFactor);
104 
106  virtual void setUseGlobalDiffuse(bool useGlobalDiffuse);
107 
109  virtual void setUseHDR(bool useHDR);
110 
112  virtual void slot_reloadShader();
113 
115  virtual void setDirty(bool isDirty) { myDirty = isDirty; }
116 
118  virtual void setEmissionFactor(float emissionFactor);
119 
121  virtual bool dirty() const { return myDirty; }
122 
123  virtual void releaseGLObjects(void);
124 
125  // DtOsgStateComponent interface
127  virtual bool install(osg::StateSet* stateset);
128 
130  virtual bool uninstall(osg::StateSet* stateset);
131 
133  virtual bool isInstalled(void) const;
134 
136  virtual void setComponentVisualizationMode(int mode);
137  public:
138  static int textureStartOffset(void);
139 
140  protected:
141  virtual void setLightPointScale(double scale);
142  virtual void setDynamicLightScale(double scale);
143  virtual void setEmissiveTextureScale(double scale);
144  virtual void setSpecularScale(double scale);
145  virtual void setShininessScale(double scale);
146 
147  virtual osg::ref_ptr<osg::Uniform> createUniform(const std::string& name, osg::Uniform::Type type, int count=1);
148 
149  virtual void packLights(const osg::Matrixd& normalMatrix, const VectorLights& lights, const osg::State& state);
150  virtual void updateTextureLightDataGrid(void);
152  virtual void updateTiledShadingData(const VectorLights& lights, const osg::State& state, const osg::Camera* camera);
153 
155  virtual void updateTileLightIndexList(const std::vector<Matrix4_64>& projectionMatrix
156  , const std::vector<Vector3_64>& vWorldEye
157  , const std::vector<Vector3_64>& vWorldCenter
158  , const std::vector<Vector3_64>& vWorldUp
159  , const Vector2_uint32& viewportSize
160  , const osg::Camera* camera);
162  virtual void initializeColorRampTexture( );
163 
165  virtual int lightGridSize();
167  virtual int maxUboSize();
168 
169  protected:
170 
173 
174  std::vector< osg::ref_ptr<osg::Uniform> > myUniforms;
175 
176  // Parameters of lights are stored in this structure
178 
179  std::array<DtGlBuffer*, DtBindingManager::theLightBlockCount> myLightUBO;
180 
182 
189 
190  typedef std::unordered_map<DtGlBuffer*, int> BufferToLightIndexMap;
191 
194  {
195  public:
197  : myBufferToLightIndexMap()
198  , myBufferChunkCount(0)
199  , myTotalCount(0)
200  {
201  //intentional nop
202  }
203  public:
204  //Map of buffers for each indirect geoemetry, buffer pointer to number of lights in the buffer
208  };
209 
210  //map for holding a TileLightIndexInfo for each camera
211  typedef std::unordered_map<const osg::Camera*, TileLightIndexInfo> CameraToTileLightIndexMapInfoMap;
213 
216 
220 
222 
226 
233  bool myUseHDR;
234  bool myDirty;
236 
239 
245 
250 
252 
254 
256 
258 
260 
262 
263  GLint myMaxUboSizeInBytes; // queried from GL
264  int myLightGridSize; // max size of light grid
265 
266  const DtBindingManager& myBindingManager; // reference to the binding manager
267 
269 
270  //Constants for scaling the HDR scalars to values so the GUI can be a single decimal digit.
271  static const float theLightPointHdrScalar;
272  static const float theDynamicLightHdrScalar;
273  static const float theEmissiveTextureHdrScalar;
274 
276  };
277 
278 
281 
283  template <>
284  inline const char* creatorTypeName<DtOsgLightingComponent>(void) { return "DtOsgLightingComponentCreator"; }
285 }
Contains the DtOsgTextureBufferObjectApplyAttribute class.
osg::ref_ptr< osg::Uniform > myLightPointScaleUniform
Definition: DtOsgLightingComponent.h:240
std::vector< osg::ref_ptr< osg::Uniform > > myUniforms
Definition: DtOsgLightingComponent.h:174
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:115
bool myUseGlobalAmbient
Definition: DtOsgLightingComponent.h:228
osg::ref_ptr< osg::Uniform > myDynamicLightScaleUniform
Definition: DtOsgLightingComponent.h:241
DtGlSimpleTexture * myColorRampTexture
Definition: DtOsgLightingComponent.h:214
osg::ref_ptr< osg::Uniform > myEnableLightingUniform
Definition: DtOsgLightingComponent.h:171
DtLightData * myLightGrid
Definition: DtOsgLightingComponent.h:177
CameraToTileLightIndexMapInfoMap myCameraToTileLightIndexMapInfoMap
Definition: DtOsgLightingComponent.h:212
osg::ref_ptr< osg::Uniform > myBDRFLutUniform
Definition: DtOsgLightingComponent.h:247
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
bool myUseHDR
Definition: DtOsgLightingComponent.h:233
osg::ref_ptr< osg::Uniform > mySpecularScaleUniform
Definition: DtOsgLightingComponent.h:243
osg::ref_ptr< osg::Uniform > myLightGridTileDimUniform
Definition: DtOsgLightingComponent.h:223
Wrapper for OpenGL Texture.
Definition: DtGlSimpleTexture.h:35
osg::ref_ptr< osg::Uniform > myEmissionFactorUniform
Definition: DtOsgLightingComponent.h:235
const DtBindingManager & myBindingManager
Definition: DtOsgLightingComponent.h:266
Contains the vrvOsg::DtBindingManager class.
Contains the DtOsgTextureApplyAttribute class.
osg::ref_ptr< osg::Uniform > myAmbientFactorUniform
Definition: DtOsgLightingComponent.h:227
osg::ref_ptr< osg::Uniform > myDiffuseFactorUniform
Definition: DtOsgLightingComponent.h:230
osg::ref_ptr< osg::Uniform > myLightPerViewOffsetUniform
Definition: DtOsgLightingComponent.h:225
struct for holding information about a camera&#39;s tile light index map
Definition: DtOsgLightingComponent.h:193
4 dimensional vector
bool myDirty
Definition: DtOsgLightingComponent.h:234
const char * creatorTypeName< DtOsgLightingComponent >(void)
template specialization for the creator (pass the class being created to the creatorTypeName template...
Definition: DtOsgLightingComponent.h:284
osg::ref_ptr< osg::Uniform > myUseGlobalDiffuseUniform
Definition: DtOsgLightingComponent.h:232
osg::ref_ptr< osg::Uniform > myModelTransmittanceUniform
Definition: DtOsgLightingComponent.h:238
TileLightIndexInfo()
Definition: DtOsgLightingComponent.h:196
osg::ref_ptr< osg::Image > myBrdfLutImage
Definition: DtOsgLightingComponent.h:249
osg::ref_ptr< osg::Uniform > myLightingOffClampUniform
Definition: DtOsgLightingComponent.h:172
DtSignalConnectionManager myConnections
Definition: DtOsgLightingComponent.h:259
static const float theEmissiveTextureHdrScalar
Definition: DtOsgLightingComponent.h:273
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:22
Manage interface block bindings.
Definition: DtBindingManager.h:43
osg::ref_ptr< osg::Uniform > myViewportSizeUniform
Definition: DtOsgLightingComponent.h:221
osg::ref_ptr< osg::Uniform > myEmissiveTextureScaleUniform
Definition: DtOsgLightingComponent.h:242
int myBufferChunkCount
Definition: DtOsgLightingComponent.h:206
osg::ref_ptr< DtUniformBufferObjectApplyAttribute > myUniformBufferObjectApplyAttribute
Definition: DtOsgLightingComponent.h:218
osg::ref_ptr< osg::Uniform > myModelTypeDefaultUniform
Definition: DtOsgLightingComponent.h:253
osg::ref_ptr< osg::Texture2D > myBDRFLutTexture
Definition: DtOsgLightingComponent.h:248
Light class.
osg::ref_ptr< osg::Uniform > myUseGlobalAmbientUniform
Definition: DtOsgLightingComponent.h:229
DtGlBuffer * myTileLightIntersectionDataSsbo
Definition: DtOsgLightingComponent.h:187
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
osg::ref_ptr< osg::Uniform > myTransmittanceFactorUniform
Definition: DtOsgLightingComponent.h:237
osg::ref_ptr< osg::Texture > myDebugTexture
Definition: DtOsgLightingComponent.h:275
bool myIsInstalled
Definition: DtOsgLightingComponent.h:257
std::unordered_map< DtGlBuffer *, int > BufferToLightIndexMap
Definition: DtOsgLightingComponent.h:190
osg::ref_ptr< osg::Uniform > myUpVectorUniform
Definition: DtOsgLightingComponent.h:246
static const float theDynamicLightHdrScalar
Definition: DtOsgLightingComponent.h:272
DtLightComputeProgram * myLightComputeProgram
Definition: DtOsgLightingComponent.h:268
Contains makVrv::DtLightComputeProgram class.
osg::ref_ptr< osg::Uniform > myColorRampTextureUniform
Definition: DtOsgLightingComponent.h:215
Class doing all the heavy lifting in regards of forward+ lighting.
Definition: DtTileSpaceLightGrid.h:40
static const float theLightPointHdrScalar
Definition: DtOsgLightingComponent.h:271
bool myUseGlobalDiffuse
Definition: DtOsgLightingComponent.h:231
int myLightGridSize
Definition: DtOsgLightingComponent.h:264
A generic OpenGL buffer.
Definition: DtGlBuffer.h:27
DtVirtualBaseClassCreator< DtOsgLightingComponent > DtOsgLightingComponentCreator
creator
Definition: DtOsgLightingComponent.h:280
osg::ref_ptr< DtShaderStorageBufferApplyAttribute > myShaderStorageBufferApplyAttribute
Definition: DtOsgLightingComponent.h:219
osg::ref_ptr< osg::Uniform > myShininessScaleUniform
Definition: DtOsgLightingComponent.h:244
VectorLights myViewSpaceLightsScratchPad
Definition: DtOsgLightingComponent.h:255
Base class to provide boost signal/slot management.
osg::ref_ptr< TextureApplyAttribute > myTextureApplyAttribute
Definition: DtOsgLightingComponent.h:217
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:207
const char int mode
Definition: ioapi.h:38
std::array< DtGlBuffer *, DtBindingManager::theLightBlockCount > myLightUBO
Definition: DtOsgLightingComponent.h:179
Contains DLL export macros.
DtTileSpaceLightGrid * myTileSpaceLightGrid
Definition: DtOsgLightingComponent.h:181
DtGlBuffer * myTileLightIndexBuffersInfoSsbo
Definition: DtOsgLightingComponent.h:188
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
Contains makVrv::DtOsgStateComponent class.
DtGlBuffer * myTileLightIndexListSsboPreCompute
Definition: DtOsgLightingComponent.h:186
DtGlBuffer * myTileLightIndexListSsbo
Holds a set of indexes, one per light tile.
Definition: DtOsgLightingComponent.h:185
osg::ref_ptr< osg::Uniform > myComponentDebugUniform
Definition: DtOsgLightingComponent.h:251
virtual bool dirty() const
Checks if component needs to be re-installed.
Definition: DtOsgLightingComponent.h:121
std::unordered_map< const osg::Camera *, TileLightIndexInfo > CameraToTileLightIndexMapInfoMap
Definition: DtOsgLightingComponent.h:211
osg::ref_ptr< osg::Uniform > myLightGridMaxDimUniform
Definition: DtOsgLightingComponent.h:224
BufferToLightIndexMap myBufferToLightIndexMap
Definition: DtOsgLightingComponent.h:205
static bool bColorRampTextureWasTried
Definition: DtOsgLightingComponent.h:261
State component that injects lighting shaders and uniforms into a state set.
Definition: DtOsgLightingComponent.h:62
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:263

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)