VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtTritonDrawable.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2016 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <osg/Camera>
13 #include <osg/Drawable>
14 #include <osg/TextureCubeMap>
17 #include <vrvOsg/DtOsgRenderer.h>
20 #include <matrix/vlVector.h>
21 #include <osg/StateSet>
22 
23 #include <vrvTriton/vrvTriton.h>
25 
27 
28 #include <map>
29 
30 
31 //this is based on the enum Shaders in Ocean.h
32 #define NUM_TRITON_SHADER_TYPES 6
33 
34 namespace Triton
35 {
36  class Ocean;
37  class Environment;
38  class ResourceLoader;
39 }
40 
41 namespace makVrv
42 {
43  class DtPlanarReflection;
44  class DtObserverObject;
45 
47  struct TritonUpdateCallback : public virtual osg::Drawable::UpdateCallback
48  {
51 
54  virtual void update(osg::NodeVisitor* nv, osg::Drawable*);
55 
58  };
59 
61  class DT_DLL_VRVTRITON DtTritonDrawable : public osg::Drawable
62  {
63  public:
65  DtTritonDrawable( makVrv::DtDe& de, const DtTritonManager& tritonManager,
66  DtEnvironmentInfo& environmentInfo, bool geocentric,
67  osg::TextureCubeMap * environmentMap = NULL,
69 
70  virtual bool isSameKindAs(const Object* obj) const {
71  return dynamic_cast<const DtTritonDrawable*>(obj)!=NULL;
72  }
73  virtual Object* cloneType() const
74  {
75  return new DtTritonDrawable(myDe, myTritonManager,
76  myEnvironmentInfo, myGeocentricFlag);
77  }
78  virtual Object* clone(const osg::CopyOp& copyop) const
79  {
80  return new DtTritonDrawable(myDe, myTritonManager,
81  myEnvironmentInfo, myGeocentricFlag);
82  }
83 
85  virtual Triton::Ocean* ocean() { return myOcean; }
86 
88  virtual Triton::Environment* environment() { return myEnvironment; }
89 
91  virtual void setBeach(const osg::Vec3& beachOrigin, const osg::Vec3& normal);
92 
94  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
95 
97  virtual void setPlanarReflections(bool enabled);
98  virtual bool planarReflections() const;
99 
101  virtual void setBreakingWaveAmplitude(float meters);
102  virtual float getBreakingWaveAmplitude() const;
103 
107  virtual void setHeightMap(bool enabled);
108  virtual bool heightMap() const;
109 
113  virtual void setQuality(DtTritonManager::TritonQuality quality);
114  virtual DtTritonManager::TritonQuality getQuality() const;
115 
119  virtual void setBreakingWavesMap(bool enabled);
120  virtual bool breakingWavesMap() const;
121 
123  virtual void setWaveDampingDistance(float meters);
124  virtual float waveDampingDistance() const;
125 
128  virtual void setMaxReflectionWindSpeed(double metersPerSecond)
129  {
130  myMaxWindForReflections = metersPerSecond;
131  }
132 
134  virtual void setUnderwaterFogColor(const osg::Vec4& color)
135  {
136  myUnderwaterFogColor = color;
137  }
138 
139  virtual const osg::Vec4& getUnderwaterFogColor() const
140  {
141  return myUnderwaterFogColor;
142  }
143 
145  virtual void setUnderwaterVisibility(double visibility)
146  {
147  myUnderwaterVisibility = visibility;
148  }
149 
150  virtual double getUnderwaterVisibility() const
151  {
152  return myUnderwaterVisibility;
153  }
154 
157  virtual void setWaterVisibility(double visibility)
158  {
159  myDefaultVisibility = visibility;
160  }
161 
162  virtual double getWaterVisibility() const
163  {
164  return myDefaultVisibility;
165  }
166 
168  virtual void setSurgeDepth(float depth)
169  {
170  mySurgeDepth = std::max( 0.2f, depth );
171  }
172 
173  virtual float getSurgeDepth() const
174  {
175  return mySurgeDepth;
176  }
177 
179  virtual bool getIsInitialized() const
180  {
181  return myInitializationComplete;
182  }
183 
186  void setAllowUnderwaterEffects(bool allow)
187  {
188  myAllowUnderwater = allow;
189  }
190 
192  bool getAllowUnderwaterEffects() const
193  {
194  return myAllowUnderwater;
195  }
196 
199  virtual void setHeightMapResolution(float metersPerTexel);
200 
201  virtual float getHeightMapResolution() const;
202 
205  virtual void setBreakingWavesMapResolution(float metersPerTexel);
206 
207  virtual float getBreakingWavesMapResolution() const;
208 
210  virtual void enableReflections(bool enabled);
211 
213  boost::signal<void ()> signal_postInitialize;
214 
216  virtual void releaseGLObjects(osg::State* state=0) const;
217 
219  void heightMapChanged();
220 
222  void breakingWavesMapChanged();
223 
226  osg::ref_ptr<DtPlanarReflection> getPlanarReflection( osg::Camera* camera);
227 
229  osg::Group* getTritonGeode();
230  const osg::Group* getTritonGeode() const;
231 
232  protected:
233  void shaderUpdateLightUniforms(osg::RenderInfo& info, osg::State &state, GLint shader, int shaderType) const;
234 
235  void shaderUpdateViewMatrices(osg::State &state, GLint shader, int shaderType
236  , const Matrix4_32& view_matrix_32
237  , const Matrix4_32& view_inverse_transpose_matrix_32) const;
238 
239  void updateCloudShadows(osg::State &state, GLint shader, int shaderType
240  , GLboolean bIsCloudShadowActive
241  , unsigned int cloudshadowTextureUnit
242  , unsigned int cloudshadowTextureIndex
243  , osg::Matrixf textureViewProjMatrix
244  , unsigned int cloudshadowTextureUnit2
245  , unsigned int cloudshadowTextureIndex2
246  , osg::Matrixf textureViewProjMatrix2) const;
247 
248  void updateOcean(double simTime);
249 
250  void GetShaderUniformHandles(GLint shader, int shaderType) const;
251 
252  osg::ref_ptr<DtPlanarReflection> getOrCreatePlanarReflection(osg::RenderInfo& renderInfo);
253 
254  osg::ref_ptr<DtPlanarReflection> setupPlanarReflections( osg::RenderInfo &renderInfo );
255 
256  DtTritonHeightMapManager *getOrCreateHeightMapManager(osg::RenderInfo& renderInfo);
257 
258  DtTritonBreakingWavesMapManager *getOrCreateBreakingWavesMapManager(osg::RenderInfo& renderInfo);
259 
260  void setup(osg::RenderInfo& renderInfo);
261  void cleanup( void );
262  void removePlanarReflections();
263  osg::Node * createReflectionWorldGraph( makVrv::DtOsgRenderer& osgRenderer,
264  const osg::Matrix & localToWorld, const osg::Vec3& currentPos );
265 
266  void slot_reloadShader();
267 
268  void computeReflectionMatrix( const osg::Vec3& currentPosition );
269 
270  void GetShaderUniformHandles() const;
271 
272  void applyLighting(osg::RenderInfo& info) const;
273 
274  void applyQuality() const;
275 
276  void updateShader(osg::Node *node, osg::State& state) const;
277 
278  void computeReflectionBlend( const osg::Vec3& currentPosition );
279 
280  void adjustDisplacementDampingDistance( float viewMag );
281 
283  void updateReflectionCamFogColor(osg::Camera *reflectionCam, bool skyEnabled) const;
284 
286  void setSpecularThreshold(float threshold);
287 
288  float specularThreshold() const;
289 
290  virtual ~DtTritonDrawable();
291 
292  osg::ref_ptr< osg::TextureCubeMap > myCubeMap;
293 
294  Triton::ResourceLoader *myResourceLoader;
295  Triton::Environment *myEnvironment;
297 
307  bool myHeightMapFlag, myHeightMapChangedFlag;
308  bool myBreakingWavesMapFlag, myBreakingWavesMapChangedFlag;
312  bool myPrecipitationOverridden, mySavedPrecipitationState;
313  float myHeightMapResolution, myBreakingWavesMapResolution;
317 
318  //when the quality changes the shaders have to be reloaded.
319  // This flag lets the updateShaders function know to force a reload.
320  mutable bool myShadersDirty;
321 
322  //This flag lets triton know that it is using custom shaders. This
323  // prevents the shaders from being reloaded by accident.
324  mutable bool myUsingCustomShaders;
325 
326  // This boolean indicates whether or not planar reflections have been requested,
327  // regardless of the internal state of the drawable. When it finally gets around
328  // to setting up planar reflections, this flag is checked
330 
333 
335 
337 
339 
340  std::map<osg::Camera *, osg::ref_ptr<makVrv::DtPlanarReflection> > myPlanarReflectionCameraMap;
341  std::map<osg::Camera *, makVrv::DtTritonHeightMapManager *> myHeightMapManagerMap;
342  std::map<osg::Camera *, makVrv::DtTritonBreakingWavesMapManager *> myBreakingWavesMapManagerMap;
343 
344  osg::ref_ptr< osg::ClipNode > myClipNode;
345  osg::Plane myReflectionPlane;
346  osg::Matrix myReflectionMatrix;
348 
349  double myWindSpeed;
350 
351  mutable bool myDisableDrawing;
352  mutable int myViewPortSizeUniform[NUM_TRITON_SHADER_TYPES];
353 
354  mutable int myLightTextureUniform[NUM_TRITON_SHADER_TYPES];
355  mutable int myTileLightIndexListTextureUniform[NUM_TRITON_SHADER_TYPES];
356  mutable int myTileLightGridCountOffsetsTextureUniform[NUM_TRITON_SHADER_TYPES];
357  mutable int myColorRampTextureUniform[NUM_TRITON_SHADER_TYPES];
358 
359  mutable int myModelViewMatrixUniform[NUM_TRITON_SHADER_TYPES];
360  mutable int myModelViewInverseTransposeMatrixUniform[NUM_TRITON_SHADER_TYPES];
361 
362  mutable int myLightGridTileDimUniform[NUM_TRITON_SHADER_TYPES];
363  mutable int myLightGridMaxDimUniform[NUM_TRITON_SHADER_TYPES];
364 
365  mutable int myCloudShadowTextureUniform[NUM_TRITON_SHADER_TYPES];
366  mutable int myCloudShadowTextureUniform2[NUM_TRITON_SHADER_TYPES];
367  mutable int myCloudShadowTexGenUniform[NUM_TRITON_SHADER_TYPES];
368  mutable int myCloudShadowTexGenUniform2[NUM_TRITON_SHADER_TYPES];
369  mutable int myCloudShadowActive[NUM_TRITON_SHADER_TYPES];
370  mutable bool mySimFrozen;
371 
372  mutable std::vector<unsigned int> myUserShaderVector;
373 
376 
378 
381 
382  std::vector<osg::ref_ptr<osg::Camera> > myDebugVisualsCameras;
383  std::vector<osg::ref_ptr<osg::Texture> > myDebugVisualsTextures;
384 
385  };
386 }

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)