VR-Forces Development_Version 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) 2014 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>
26 
28 
29 #include <map>
30 
31 
32 //this is based on the enum Shaders in Ocean.h
33 #define NUM_TRITON_SHADER_TYPES 4
34 
35 namespace Triton
36 {
37  class Ocean;
38  class Environment;
39  class ResourceLoader;
40 }
41 
42 namespace makVrv
43 {
44  class DtPlanarReflection;
45  class DtObserverObject;
46  class DtTritonManager;
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 DtTritonDrawable : public osg::Drawable
64  {
65  public:
67  DtTritonDrawable( makVrv::DtDe& de, const DtTritonManager& tritonManager,
68  DtEnvironmentInfo& environmentInfo, bool geocentric,
69  osg::TextureCubeMap * cubeMap = NULL );
70 
71  virtual bool isSameKindAs(const Object* obj) const {
72  return dynamic_cast<const DtTritonDrawable*>(obj)!=NULL;
73  }
74  virtual Object* cloneType() const
75  {
78  }
79  virtual Object* clone(const osg::CopyOp& copyop) const
80  {
83  }
84 
86  virtual Triton::Ocean* ocean() { return myOcean; }
87 
89  virtual Triton::Environment* environment() { return myEnvironment; }
90 
92  virtual void setBeach(osg::Vec3 beachOrigin, osg::Vec3 normal);
93 
95  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
96 
98  virtual void setPlanarReflections(bool enabled);
99  virtual bool planarReflections() const;
100 
102  virtual void setBreakingWaveAmplitude(float meters);
103  virtual float getBreakingWaveAmplitude() const;
104 
108  virtual void setHeightMap(bool enabled);
109  virtual bool heightMap() const;
110 
115  };
116 
120  virtual void setQuality(TritonQuality quality);
121  virtual TritonQuality getQuality() const;
122 
126  virtual void setBreakingWavesMap(bool enabled);
127  virtual bool breakingWavesMap() const;
128 
130  virtual void setWaveDampingDistance(float meters);
131  virtual float waveDampingDistance() const;
132 
135  virtual void setMaxReflectionWindSpeed(double metersPerSecond)
136  {
137  myMaxWindForReflections = metersPerSecond;
138  }
139 
141  virtual void setUnderwaterFogColor(const osg::Vec4& color)
142  {
143  myUnderwaterFogColor = color;
144  }
145 
146  virtual const osg::Vec4& getUnderwaterFogColor() const
147  {
148  return myUnderwaterFogColor;
149  }
150 
152  virtual void setUnderwaterVisibility(double visibility)
153  {
154  myUnderwaterVisibility = visibility;
155  }
156 
157  virtual double getUnderwaterVisibility() const
158  {
159  return myUnderwaterVisibility;
160  }
161 
164  virtual void setWaterVisibility(double visibility)
165  {
166  myDefaultVisibility = visibility;
167  }
168 
169  virtual double getWaterVisibility() const
170  {
171  return myDefaultVisibility;
172  }
173 
175  virtual void setSurgeDepth(float depth)
176  {
177  mySurgeDepth = std::max( 0.2f, depth );
178  }
179 
180  virtual float getSurgeDepth() const
181  {
182  return mySurgeDepth;
183  }
184 
186  virtual bool getIsInitialized() const
187  {
189  }
190 
193  void setAllowUnderwaterEffects(bool allow)
194  {
195  myAllowUnderwater = allow;
196  }
197 
200  {
201  return myAllowUnderwater;
202  }
203 
206  virtual void setHeightMapResolution(float metersPerTexel);
207 
208  virtual float getHeightMapResolution() const;
209 
212  virtual void setBreakingWavesMapResolution(float metersPerTexel);
213 
214  virtual float getBreakingWavesMapResolution() const;
215 
217  virtual void enableReflections(bool enabled);
218 
220  boost::signal<void ()> signal_postInitialize;
221 
223  virtual void releaseGLObjects(osg::State* state=0) const;
224 
226  void heightMapChanged();
227 
230 
231  protected:
232  void shaderUpdateLightUniforms(osg::RenderInfo& info, osg::State &state, GLint shader, int shaderType) const;
233 
234  void shaderUpdateViewMatrices(osg::State &state, GLint shader, int shaderType
235  , const Matrix4_32& view_matrix_32
236  , const Matrix4_32& view_inverse_transpose_matrix_32) const;
237 
238  void updateCloudShadows(osg::State &state, GLint shader, int shaderType
239  , GLboolean bIsCloudShadowActive
240  , unsigned int cloudshadowTextureUnit
241  , unsigned int cloudshadowTextureIndex
242  , osg::Matrixf textureViewProjMatrix) const;
243 
244  void GetShaderUniformHandles(GLint shader, int shaderType) const;
245 
246  osg::ref_ptr<DtPlanarReflection> getOrCreatePlanarReflection(osg::RenderInfo& renderInfo);
247 
248  osg::ref_ptr<DtPlanarReflection> setupPlanarReflections( osg::RenderInfo &renderInfo );
249 
250  DtTritonHeightMapManager *getOrCreateHeightMapManager(osg::RenderInfo& renderInfo);
251 
253 
254  void setup( void );
255  void cleanup( void );
257  osg::Node * createReflectionWorldGraph( makVrv::DtOsgRenderer& osgRenderer,
258  const osg::Matrix & localToWorld, const osg::Vec3 currentPos );
259 
260  void computeReflectionMatrix( const osg::Vec3& currentPosition );
261 
262  void GetShaderUniformHandles() const;
263 
264  void applyLighting(osg::RenderInfo& info) const;
265 
266  void applyQuality() const;
267 
268  void updateShader(osg::Node *node, osg::State& state) const;
269 
270  void computeReflectionBlend( const osg::Vec3& currentPosition );
271 
273 
275  void updateReflectionCamFogColor(osg::Camera *reflectionCam) const;
276 
277  virtual ~DtTritonDrawable();
278 
279  osg::ref_ptr< osg::TextureCubeMap > myCubeMap;
280 
281  Triton::ResourceLoader *myResourceLoader;
282  Triton::Environment *myEnvironment;
284 
303 
304  //when the quality changes the shaders have to be reloaded.
305  // This flag lets the updateShaders function know to force a reload.
306  mutable bool myShadersDirty;
307 
308  // This boolean indicates whether or not planar reflections have been requested,
309  // regardless of the internal state of the drawable. When it finally gets around
310  // to setting up planar reflections, this flag is checked
312 
315 
317 
319 
321 
322  std::map<osg::Camera *, osg::ref_ptr<makVrv::DtPlanarReflection> > myPlanarReflectionCameraMap;
323  std::map<osg::Camera *, makVrv::DtTritonHeightMapManager *> myHeightMapManagerMap;
324  std::map<osg::Camera *, makVrv::DtTritonBreakingWavesMapManager *> myBreakingWavesMapManagerMap;
325 
326  osg::ref_ptr< osg::ClipNode > myClipNode;
327  osg::Plane myReflectionPlane;
328  osg::Matrix myReflectionMatrix;
330 
331  double myWindSpeed;
332 
334 
339 
342 
345 
349 
350  mutable std::vector<unsigned int> myUserShaderVector;
351 
354 
356 
359  };
360 }

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)