VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgShadowTechnique.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 
16 
17 #include <osgEarth/VirtualProgram>
18 
19 #include <osgShadow/ShadowTechnique>
20 
21 #include <osg/StateSet>
22 #include <osg/Camera>
23 #include <osg/PolygonOffset>
24 #include <osg/FrameBufferObject>
25 #include <osg/Uniform>
26 #include <osg/LightSource>
27 #include <osg/RenderInfo>
28 #include <osg/Vec2>
29 #include <osg/Vec3>
30 #include <osg/Matrix>
31 #include <osg/MatrixTransform>
32 #include <osg/Program>
33 #include <osg/Texture2D>
34 #include <osg/Texture2DArray>
35 #include <osg/Geode>
36 #include <osg/Geometry>
37 #include <osg/GL>
38 
39 #include <vector>
40 #include <map>
41 #include <string>
42 
43 namespace makVrv
44 {
45 
46  class DtShadowTweakables;
47  class DtChannel;
48  class DtOsgChannel;
49  class DtShadowSettingsObject;
50  class TextureApplyAttribute;
51  class DtOsgShadowTechnique;
52  struct DtCurrentPassData;
53  struct DtPerChannelData;
54 
57  class DT_DLL_VRVOSG DtOsgShadowTechnique : public osgShadow::ShadowTechnique
58  {
59  public:
60 
63 
65  DtOsgShadowTechnique(const DtOsgShadowTechnique& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
66 
68  virtual osg::Object* cloneType() const { return new DtOsgShadowTechnique(myDe); }
69 
71  virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new DtOsgShadowTechnique (*this, copyop); }
72 
74  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const DtOsgShadowTechnique *>(obj)!=NULL; }
75 
77  virtual const char* libraryName() const { return "makVrv"; }
78 
80  virtual const char* className() const { return "DtOsgShadowTechnique"; }
81 
83  virtual void init();
84 
86  virtual void postConstructionInit();
87 
89  virtual void update(osg::NodeVisitor& nv);
90 
92  virtual void cull(osgUtil::CullVisitor& cv);
93 
95  virtual void cleanSceneGraph();
96 
98  void setChannelShadowState(DtOsgChannel* osgChannel, bool enable);
99 
101  bool getChannelShadowSettings(DtOsgChannel* osgChannel, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
102 
104  bool getCameraCloudShadowMap(osg::Camera* camera, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix,
105  unsigned int* textureIndex2, osg::Matrix* textureViewProjMatrix2);
106 
108  void setGlobalLight(osg::LightSource* light) { myGlobalLight = light; }
109 
111  const osg::LightSource* getGlobalLight() const { return myGlobalLight.get(); }
112 
113  static const std::string& shadowCameraPrefixString(void);
114  static const std::string& shadowSDSMCameraPrefixString(void);
115 
117  const osg::StateSet * mapCameraToStateSet(const osg::Camera* camera) const;
118 
120 
121  protected:
123  virtual void reInitialize(unsigned int quality);
124 
127  virtual void cleanupOldPerChannelData();
128 
129  virtual bool configureShadowTraversalNodeMask(bool traverseEntities, bool traverseProps, bool traverseTerrain);
130 
131  virtual void slot_refresh_maps();
132 
133 
134  public:
135  // per window info
136  static const int MAX_NUM_CASCADES = 6;
137 
138  protected:
139 
141  virtual std::string generateVertexShader(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
142 
144  virtual std::string generateFragmentShader(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
145 
147  virtual std::string generateCloudShadowVertexShader(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
148 
149 
151  unsigned int getFilterCount(DtShadowSettingsObject* shadowSettingObject);
152 
155  bool getReceiveShadows(const DtShadowSettingsObject* shadowSettings) const;
156 
157  private:
158 
160  std::string generateFragmentComputeShadowFunction(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
161 
163  std::string generateFragmentUniformAndVariables(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
164 
166  std::string generateFragmentMain(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
167 
169  bool getCameraSettings(osg::Camera* viewCamera, DtPerChannelData** perChannelData, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
170 
172  void initPerChannelData(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
173 
174 
176  void installReceiverVPandSharedStateSet(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
177 
178  void triggerExternalModuleShaderRefresh();
179 
180 
182  void installSDSM(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
183 
185  void traverseSDSMCameras( DtCurrentPassData & d, osgUtil::CullVisitor& cv);
186 
188  void installCloudShadows(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
189 
191  void updateCloudShadows(osg::RenderInfo& renderInfo, osg::Camera* camera);
192 
194  void updateCascadeImportance(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject);
195 
197  osg::Program* getProgramFromFile(const std::string& szVertexShader, const std::string& szFragmentShader);
198 
200  void installPreFilter(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject, osg::Camera* depthCamera,
201  osg::Camera* xBlurCamera, osg::Camera* yBlurCamera, osg::Texture2DArray* texture, osg::StateSet* stateSet, unsigned int textureUnit);
202 
204  void installPreFilter(DtPerChannelData* perChannelData, DtShadowSettingsObject* shadowSettingObject, osg::Camera* depthCamera,
205  osg::Camera* xBlurCamera, osg::Camera* yBlurCamera, unsigned int textureLayer, osg::Texture2DArray* texture2DArray,
206  osg::Texture2DArray* preFilterTexture2DArray1, osg::Texture2DArray* preFilterTexture2DArray2);
207 
208  void setupReverseZBuffer(osg::Camera* depthCamera, osg::Camera* xBlurCamera, osg::Camera* yBlurCamera);
209  void setupBlurCamera(osg::Camera* camera, osg::ref_ptr<osg::Program> &blurProgram, const osg::Vec2 & direction);
210 
212  osg::Texture2D* createTexture2D(int width, int height, GLenum internalFormat, GLenum sourceFormat, GLenum sourceType, bool shadowComparisonMode,
213  osg::Texture2D::FilterMode minFilter = osg::Texture2D::NEAREST, osg::Texture2D::FilterMode magFilter = osg::Texture2D::NEAREST);
214 
216  osg::Texture2DArray* createTexture2DArray(int width, int height, int depth, GLenum internalFormat, GLenum sourceFormat, GLenum sourceType,
217  bool shadowComparisonMode, osg::Texture2DArray::FilterMode minFilter = osg::Texture2DArray::NEAREST, osg::Texture2DArray::FilterMode magFilter = osg::Texture2DArray::NEAREST);
218 
220  osg::Camera* createCamera(int width, int height, GLbitfield clearMask);
221 
223  osg::Geode* createFullScreenQuad(const osg::Vec2& size, const osg::Vec2& uvStart, const osg::Vec2& uvStop);
224 
226  osg::Camera* createHudCamera(int width, int height, GLbitfield clearMask, const char * name = NULL);
227 
229  double computeUniformSplit(double nearDistance, double farDistance, unsigned int splitIndex, unsigned int numSplits);
230 
232  double computeLogarithmicSplit(double nearDistance, double farDistance, unsigned int splitIndex, unsigned int numSplits);
233 
235  {
236  osg::Matrix myViewMatrix;
237  osg::Matrix myProjectionMatrix;
239  };
241  CameraDescription constructSplitLightCamera(const DtCurrentPassData & d, int split_index, bool farCascade = false);
242 
243  void updateCameras(const DtCurrentPassData & d);
244 
245  void getSplitCameraDistances(const DtCurrentPassData & d, int split_index, double &splitCamNear, double &splitCamFar);
246 
248  void setDirty(bool dirty) { _dirty = dirty; }
249 
250  // not really used yet.
251  void frustumBoundingBoxLightViewSpace(const DtCurrentPassData & d, int split_index/*for_debug visualization*/, const osg::Matrix & lightViewMatrix,
252  double nearPlane, double farPlane, osg::Vec3d& minFrustum, osg::Vec3d& maxFrustum);
253 
254  friend struct DtCurrentPassData;
256 
257  protected:
258 
260  virtual ~DtOsgShadowTechnique();
261 
262  typedef std::map< const osg::Camera*, osg::ref_ptr<DtPerChannelData> > PerChannelDataMap;
263  typedef std::vector< osg::ref_ptr<DtPerChannelData> > PerChannelDataVector;
264 
267 
271 
273 
274  static const std::string myShadowCameraPrefixString;
275  static const std::string mySDSMShadowCameraPrefixString;
276 
279 
282 
285 
288 
289  bool myMulticastIsSupported; // true if multicast extension is supported
290  bool myShadingRateIsSupported; // true if shading rate extension is supported
291  };
292 }
293 
static const std::string myShadowCameraPrefixString
Definition: DtOsgShadowTechnique.h:274
void setDirty(bool dirty)
Sets dirty for shadow technique&#39;s to true or false.
Definition: DtOsgShadowTechnique.h:248
void setGlobalLight(osg::LightSource *light)
Sets global light source.
Definition: DtOsgShadowTechnique.h:108
Definition: DtShadowSettingsObject.h:24
osg::ref_ptr< osg::Program > myVsmBlurTextureProgram
Definition: DtOsgShadowTechnique.h:277
Definition: DtOsgShadowTechnique.h:234
osg::ref_ptr< osg::Program > myVsmPassthroughArrayProgram
Definition: DtOsgShadowTechnique.h:280
osg::ref_ptr< osg::Program > myVsmPassthroughProgram
Definition: DtOsgShadowTechnique.h:281
Contains makVrv::DtSdsmDrawCallback class.
static const std::string mySDSMShadowCameraPrefixString
Definition: DtOsgShadowTechnique.h:275
osg::ref_ptr< osg::Program > myEsmBlurTexArrayProgram
Definition: DtOsgShadowTechnique.h:284
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
PerChannelDataMap myPerChannelDataMap
Definition: DtOsgShadowTechnique.h:265
voidpf void uLong size
Definition: ioapi.h:39
osg::ref_ptr< osg::Program > myVsmBlurTexArrayProgram
Definition: DtOsgShadowTechnique.h:278
static const int MAX_NUM_CASCADES
Definition: DtPerChannelData.h:47
Contains the DtOsgTextureApplyAttribute class.
DtDe & myDe
Definition: DtOsgShadowTechnique.h:272
osg::ref_ptr< osg::Program > myEVsmBlurTextureProgram
Definition: DtOsgShadowTechnique.h:286
osg::Matrix myProjectionMatrix
Definition: DtOsgShadowTechnique.h:237
This class provides the OSG-specific implementation of a DtChannel.
Definition: DtOsgChannel.h:75
osg::ref_ptr< osg::Uniform > myReceiveShadowsUniform
Definition: DtOsgShadowTechnique.h:270
virtual const char * libraryName() const
Returns the namespace string.
Definition: DtOsgShadowTechnique.h:77
bool myMulticastIsSupported
Definition: DtOsgShadowTechnique.h:289
std::vector< osg::ref_ptr< DtPerChannelData > > PerChannelDataVector
Definition: DtOsgShadowTechnique.h:263
virtual osg::Object * cloneType() const
Creates a new object of Type DtOsgShadowTechnique.
Definition: DtOsgShadowTechnique.h:68
class DtShadowTweakables * myShadowUI
Definition: DtOsgShadowTechnique.h:119
Definition: DtCurrentPassData.h:29
Definition: DtPerChannelData.h:49
osg::ref_ptr< osg::Program > myEsmBlurTextureProgram
Definition: DtOsgShadowTechnique.h:283
osg::Matrix myViewMatrix
Definition: DtOsgShadowTechnique.h:236
Definition: DtShadowTweakables.h:21
PerChannelDataVector myPerChannelDataDeleteList
Definition: DtOsgShadowTechnique.h:266
The DtOsgShadowTechnique class implements a robust shadow mapping system.
Definition: DtOsgShadowTechnique.h:57
osg::ref_ptr< osg::Program > myEVsmBlurTexArrayProgram
Definition: DtOsgShadowTechnique.h:287
Definition: DtCloudShadowPreDrawCallback.h:25
unsigned int GLenum
Definition: DtGlTextureBufferObject.h:18
const osg::LightSource * getGlobalLight() const
Gets global light source.
Definition: DtOsgShadowTechnique.h:111
virtual bool isSameKindAs(const osg::Object *obj) const
Returns true if object is of the DtOsgShadowTechnique class. Otherwise, returns false.
Definition: DtOsgShadowTechnique.h:74
DT_DLL_DEBUGDRAWRENDERER void init(makVrv::DtDe &de)
Work function for the plugin initialization.
std::map< const osg::Camera *, osg::ref_ptr< DtPerChannelData > > PerChannelDataMap
Definition: DtOsgShadowTechnique.h:262
Contains DLL export macros.
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
osg::Matrix myTextureViewProjectionMatrix
Definition: DtOsgShadowTechnique.h:238
bool myShadingRateIsSupported
Definition: DtOsgShadowTechnique.h:290
osg::ref_ptr< osg::LightSource > myGlobalLight
Definition: DtOsgShadowTechnique.h:268
osg::ref_ptr< osg::Uniform > myLightDirectionUniform
Definition: DtOsgShadowTechnique.h:269
virtual osg::Object * clone(const osg::CopyOp &copyop) const
Creates a new copy of DtOsgShadowTechnique object.
Definition: DtOsgShadowTechnique.h:71
virtual const char * className() const
Returns the class name string.
Definition: DtOsgShadowTechnique.h:80

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)