VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
24 
25 #include <vrvTriton/vrvTriton.h>
27 
29 
30 #include <map>
31 
32 
33 //this is based on the enum Shaders in Ocean.h
34 #define NUM_TRITON_SHADER_TYPES 6
35 
36 namespace Triton
37 {
38  class Ocean;
39  class Environment;
40  class ResourceLoader;
41 }
42 
43 namespace makVrv
44 {
45  class DtPlanarReflection;
46  class DtObserverObject;
47 
49  struct TritonUpdateCallback : public virtual osg::Drawable::UpdateCallback
50  {
53 
56  virtual void update(osg::NodeVisitor* nv, osg::Drawable*);
57 
60  };
61 
63  class DT_DLL_VRVTRITON DtTritonDrawable : public osg::Drawable
64  {
65  public:
67  DtTritonDrawable( makVrv::DtDe& de, const DtTritonManager& tritonManager,
68  DtEnvironmentInfo& environmentInfo, bool geocentric,
69  osg::TextureCubeMap * environmentMap = NULL,
71 
72  virtual bool isSameKindAs(const Object* obj) const {
73  return dynamic_cast<const DtTritonDrawable*>(obj)!=NULL;
74  }
75  virtual Object* cloneType() const
76  {
77  return new DtTritonDrawable(myDe, myTritonManager,
78  myEnvironmentInfo, myGeocentricFlag);
79  }
80  virtual Object* clone(const osg::CopyOp& copyop) const
81  {
82  return new DtTritonDrawable(myDe, myTritonManager,
83  myEnvironmentInfo, myGeocentricFlag);
84  }
85 
87  virtual Triton::Ocean* ocean() { return myOcean; }
88 
90  virtual Triton::Environment* environment() { return myEnvironment; }
91 
93  virtual void setBeach(const osg::Vec3& beachOrigin, osg::Vec3 normal);
94 
96  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
97 
99  virtual void setPlanarReflections(bool enabled);
100  virtual bool planarReflections() const;
101 
103  virtual void setBreakingWaveAmplitude(float meters);
104  virtual float getBreakingWaveAmplitude() const;
105 
109  virtual void setHeightMap(bool enabled);
110  virtual bool heightMap() const;
111 
115  virtual void setQuality(DtTritonManager::TritonQuality quality);
116  virtual DtTritonManager::TritonQuality getQuality() const;
117 
121  virtual void setBreakingWavesMap(bool enabled);
122  virtual bool breakingWavesMap() const;
123 
125  virtual void setWaveDampingDistance(float meters);
126  virtual float waveDampingDistance() const;
127 
130  virtual void setMaxReflectionWindSpeed(double metersPerSecond)
131  {
132  myMaxWindForReflections = metersPerSecond;
133  }
134 
136  virtual void setUnderwaterFogColor(const osg::Vec4& color)
137  {
138  myUnderwaterFogColor = color;
139  }
140 
141  virtual const osg::Vec4& getUnderwaterFogColor() const
142  {
143  return myUnderwaterFogColor;
144  }
145 
147  virtual void setUnderwaterVisibility(double visibility)
148  {
149  myUnderwaterVisibility = visibility;
150  }
151 
152  virtual double getUnderwaterVisibility() const
153  {
154  return myUnderwaterVisibility;
155  }
156 
159  virtual void setWaterVisibility(double visibility)
160  {
161  myDefaultVisibility = visibility;
162  }
163 
164  virtual double getWaterVisibility() const
165  {
166  return myDefaultVisibility;
167  }
168 
170  virtual void setSurgeDepth(float depth)
171  {
172  mySurgeDepth = std::max( 0.2f, depth );
173  }
174 
175  virtual float getSurgeDepth() const
176  {
177  return mySurgeDepth;
178  }
179 
181  virtual bool getIsInitialized() const
182  {
183  return myInitializationComplete;
184  }
185 
188  void setAllowUnderwaterEffects(bool allow)
189  {
190  myAllowUnderwater = allow;
191  }
192 
194  bool getAllowUnderwaterEffects() const
195  {
196  return myAllowUnderwater;
197  }
198 
201  virtual void setHeightMapResolution(float metersPerTexel);
202 
203  virtual float getHeightMapResolution() const;
204 
207  virtual void setBreakingWavesMapResolution(float metersPerTexel);
208 
209  virtual float getBreakingWavesMapResolution() const;
210 
212  virtual void enableReflections(bool enabled);
213 
215  boost::signal<void ()> signal_postInitialize;
216 
218  virtual void releaseGLObjects(osg::State* state=0) const;
219 
221  void heightMapChanged();
222 
224  void breakingWavesMapChanged();
225 
228  osg::ref_ptr<DtPlanarReflection> getPlanarReflection( osg::Camera* camera);
229 
230  protected:
231  void shaderUpdateLightUniforms(osg::RenderInfo& info, osg::State &state, GLint shader, int shaderType) const;
232 
233  void shaderUpdateViewMatrices(osg::State &state, GLint shader, int shaderType
234  , const Matrix4_32& view_matrix_32
235  , const Matrix4_32& view_inverse_transpose_matrix_32) const;
236 
237  void updateCloudShadows(osg::State &state, GLint shader, int shaderType
238  , GLboolean bIsCloudShadowActive
239  , unsigned int cloudshadowTextureUnit
240  , unsigned int cloudshadowTextureIndex
241  , osg::Matrixf textureViewProjMatrix) const;
242 
243  void GetShaderUniformHandles(GLint shader, int shaderType) const;
244 
245  osg::ref_ptr<DtPlanarReflection> getOrCreatePlanarReflection(osg::RenderInfo& renderInfo);
246 
247  osg::ref_ptr<DtPlanarReflection> setupPlanarReflections( osg::RenderInfo &renderInfo );
248 
249  DtTritonHeightMapManager *getOrCreateHeightMapManager(osg::RenderInfo& renderInfo);
250 
251  DtTritonBreakingWavesMapManager *getOrCreateBreakingWavesMapManager(osg::RenderInfo& renderInfo);
252 
253  void setup( void );
254  void cleanup( void );
255  void removePlanarReflections();
256  osg::Node * createReflectionWorldGraph( makVrv::DtOsgRenderer& osgRenderer,
257  const osg::Matrix & localToWorld, const osg::Vec3& currentPos );
258 
259  void computeReflectionMatrix( const osg::Vec3& currentPosition );
260 
261  void GetShaderUniformHandles() const;
262 
263  void applyLighting(osg::RenderInfo& info) const;
264 
265  void applyQuality() const;
266 
267  void updateShader(osg::Node *node, osg::State& state) const;
268 
269  void computeReflectionBlend( const osg::Vec3& currentPosition );
270 
271  void adjustDisplacementDampingDistance();
272 
274  void updateReflectionCamFogColor(osg::Camera *reflectionCam, bool skyEnabled) const;
275 
277  void setSpecularThreshold(float threshold);
278 
279  float specularThreshold() const;
280 
281  virtual ~DtTritonDrawable();
282 
283  osg::ref_ptr< osg::TextureCubeMap > myCubeMap;
284 
285  Triton::ResourceLoader *myResourceLoader;
286  Triton::Environment *myEnvironment;
288 
298  bool myHeightMapFlag, myHeightMapChangedFlag;
299  bool myBreakingWavesMapFlag, myBreakingWavesMapChangedFlag;
303  bool myPrecipitationOverridden, mySavedPrecipitationState;
304  float myHeightMapResolution, myBreakingWavesMapResolution;
308 
309  //when the quality changes the shaders have to be reloaded.
310  // This flag lets the updateShaders function know to force a reload.
311  mutable bool myShadersDirty;
312 
313  //This flag lets triton know that it is using custom shaders. This
314  // prevents the shaders from being reloaded by accident.
315  mutable bool myUsingCustomShaders;
316 
317  // This boolean indicates whether or not planar reflections have been requested,
318  // regardless of the internal state of the drawable. When it finally gets around
319  // to setting up planar reflections, this flag is checked
321 
324 
326 
328 
330 
331  std::map<osg::Camera *, osg::ref_ptr<makVrv::DtPlanarReflection> > myPlanarReflectionCameraMap;
332  std::map<osg::Camera *, makVrv::DtTritonHeightMapManager *> myHeightMapManagerMap;
333  std::map<osg::Camera *, makVrv::DtTritonBreakingWavesMapManager *> myBreakingWavesMapManagerMap;
334 
335  osg::ref_ptr< osg::ClipNode > myClipNode;
336  osg::Plane myReflectionPlane;
337  osg::Matrix myReflectionMatrix;
339 
340  double myWindSpeed;
341 
342  mutable int myViewPortSizeUniform[NUM_TRITON_SHADER_TYPES];
343 
344  mutable int myLightTextureUniform[NUM_TRITON_SHADER_TYPES];
345  mutable int myTileLightIndexListTextureUniform[NUM_TRITON_SHADER_TYPES];
346  mutable int myTileLightGridCountOffsetsTextureUniform[NUM_TRITON_SHADER_TYPES];
347  mutable int myColorRampTextureUniform[NUM_TRITON_SHADER_TYPES];
348 
349  mutable int myModelViewMatrixUniform[NUM_TRITON_SHADER_TYPES];
350  mutable int myModelViewInverseTransposeMatrixUniform[NUM_TRITON_SHADER_TYPES];
351 
352  mutable int myLightGridTileDimUniform[NUM_TRITON_SHADER_TYPES];
353  mutable int myLightGridMaxDimUniform[NUM_TRITON_SHADER_TYPES];
354 
355  mutable int myCloudShadowTextureUniform[NUM_TRITON_SHADER_TYPES];
356  mutable int myCloudShadowTexGenUniform[NUM_TRITON_SHADER_TYPES];
357  mutable int myCloudShadowActive[NUM_TRITON_SHADER_TYPES];
358 
359  mutable std::vector<unsigned int> myUserShaderVector;
360 
363 
365 
368  };
369 }

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)