OpenSceneGraph 3.6.5
PrecipitationEffect
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGPARTICLE_PRECIPITATIONEFFECT
15#define OSGPARTICLE_PRECIPITATIONEFFECT
16
17#include <osg/Group>
18#include <osg/BoundingBox>
19#include <osg/Fog>
20#include <osg/Geometry>
21
22#include <osgUtil/CullVisitor>
23
24#include <osgParticle/Export>
25
26namespace osgParticle
27{
29 {
30 public:
31
34
35 virtual const char* libraryName() const { return "osgParticle"; }
36 virtual const char* className() const { return "PrecipitationEffect"; }
37 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const PrecipitationEffect*>(obj) != 0; }
38 virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
39
40 virtual void resizeGLObjectBuffers(unsigned int maxSize);
41 virtual void releaseGLObjects(osg::State* state = 0) const;
42
43 virtual void traverse(osg::NodeVisitor& nv);
44
46 void rain(float intensity);
47
49 void snow(float intensity);
50
51 void setMaximumParticleDensity(float density) { if (_maximumParticleDensity==density) return; _maximumParticleDensity = density; _dirty = true;}
53
54 void setWind(const osg::Vec3& wind) { _wind = wind; }
55 const osg::Vec3& getWind() const { return _wind; }
56
57 void setPosition(const osg::Vec3& position) { _origin = position; }
58 const osg::Vec3& getPosition() const { return _origin; }
59
60 void setCellSize(const osg::Vec3& cellSize) { if (_cellSize==cellSize) return; _cellSize = cellSize; _dirty = true; }
61 const osg::Vec3& getCellSize() const { return _cellSize; }
62
63 void setParticleSpeed(float particleSpeed) { if (_particleSpeed==particleSpeed) return; _particleSpeed = particleSpeed; _dirty = true; }
64 float getParticleSpeed() const { return _particleSpeed; }
65
66 void setParticleSize(float particleSize) { if (_particleSize==particleSize) return; _particleSize = particleSize; _dirty = true;}
67 float getParticleSize() const { return _particleSize; }
68
69 void setParticleColor(const osg::Vec4& color) { if (_particleColor==color) return; _particleColor = color; _dirty = true;}
70 const osg::Vec4& getParticleColor() const { return _particleColor; }
71
72 void setNearTransition(float nearTransition) { _nearTransition = nearTransition; }
73 float getNearTransition() const { return _nearTransition; }
74
75 void setFarTransition(float farTransition) { _farTransition = farTransition; }
76 float getFarTransition() const { return _farTransition; }
77
78 void setUseFarLineSegments(bool useFarLineSegments) { _useFarLineSegments = useFarLineSegments; }
80
81 void setFog(osg::Fog* fog) { _fog = fog; }
82 osg::Fog* getFog() { return _fog.get(); }
83 const osg::Fog* getFog() const { return _fog.get(); }
84
87
90
93
96 {
97 public:
98
101
103
104 virtual bool supports(const osg::PrimitiveFunctor&) const { return false; }
105 virtual void accept(osg::PrimitiveFunctor&) const {}
106 virtual bool supports(const osg::PrimitiveIndexFunctor&) const { return false; }
107 virtual void accept(osg::PrimitiveIndexFunctor&) const {}
108
111
112 void setGeometry(osg::Geometry* geom) { _geometry = geom; }
114 const osg::Geometry* getGeometry() const { return _geometry.get(); }
115
116 void setDrawType(GLenum type) { _drawType = type; }
117 GLenum getDrawType() const { return _drawType; }
118
119 void setNumberOfVertices(unsigned int numVertices) { _numberOfVertices = numVertices; }
120 unsigned int getNumberOfVertices() const { return _numberOfVertices; }
121
122 virtual void resizeGLObjectBuffers(unsigned int maxSize);
123 virtual void releaseGLObjects(osg::State* state) const;
124
125 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
126
127 struct Cell
128 {
129 Cell(int in_i, int in_j, int in_k):
130 i(in_i), j(in_j), k(in_k) {}
131
132 inline bool operator < (const Cell& rhs) const
133 {
134 if (i<rhs.i) return true;
135 if (i>rhs.i) return false;
136 if (j<rhs.j) return true;
137 if (j>rhs.j) return false;
138 if (k<rhs.k) return true;
139 if (k>rhs.k) return false;
140 return false;
141 }
142
143 int i;
144 int j;
145 int k;
146 };
147
149 {
150 inline bool operator < (const DepthMatrixStartTime& rhs) const
151 {
152 return depth < rhs.depth;
153 }
154
155 float depth;
158 };
159
160 typedef std::map< Cell, DepthMatrixStartTime > CellMatrixMap;
161
163 {
164 inline bool operator () (const CellMatrixMap::value_type* lhs,const CellMatrixMap::value_type* rhs) const
165 {
166 return (*lhs).second<(*rhs).second;
167 }
168 };
169
170
173
174 inline void newFrame()
175 {
177 _currentCellMatrixMap.clear();
178 }
179
180 protected:
181
183
185
187
190
191 GLenum _drawType;
192 unsigned int _numberOfVertices;
193
194 };
195
196 protected:
197
199
200 void compileGLObjects(osg::RenderInfo& renderInfo) const;
201
202 void update();
203
204 void createGeometry(unsigned int numParticles,
205 osg::Geometry* quad_geometry,
206 osg::Geometry* line_geometry,
207 osg::Geometry* point_geometry);
208
209 void setUpGeometries(unsigned int numParticles);
210
211
218
220 bool build(const osg::Vec3 eyeLocal, int i, int j, int k, float startTime, PrecipitationDrawableSet& pds, osg::Polytope& frustum, osgUtil::CullVisitor* cv) const;
221
222 // parameters
223 bool _dirty;
234
238
239 typedef std::pair< osg::NodeVisitor*, osg::NodePath > ViewIdentifier;
240 typedef std::map< ViewIdentifier, PrecipitationDrawableSet > ViewDrawableMap;
241
242 OpenThreads::Mutex _mutex;
244
247
250
253
254 // cache variables.
255 float _period;
263
265
266 };
267
268}
269
270#endif
Vec3f Vec3
Definition Vec3:21
Matrixd Matrix
Definition Matrix:27
Vec4f Vec4
Definition Vec4:21
The osgParticle library is a NodeKit that extends the core scene graph to support particle effects.
Definition AccelOperator:27
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Pure virtual base class for drawable geometry.
Definition Drawable:89
Fog - encapsulates OpenGL fog state.
Definition Fog:53
Definition Geometry:31
Base class for all internal nodes in the scene graph.
Definition Node:72
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
virtual void apply(Drawable &drawable)
void pushOntoNodePath(Node *node)
Method called by osg::Node::accept() method before a call to the NodeVisitor::apply(....
Definition NodeVisitor:287
bool validNodeMask(const osg::Node &node) const
Method to called by Node and its subclass' Node::accept() method, if the result is true it is used to...
Definition NodeVisitor:221
void popFromNodePath()
Method called by osg::Node::accept() method after a call to NodeVisitor::apply(..).
Definition NodeVisitor:293
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
A Polytope class for representing convex clipping volumes made up of a set of planes.
Definition Polytope:26
A PrimitiveFunctor is used (in conjunction with osg::Drawable::accept (PrimitiveFunctor&)) to get acc...
Definition PrimitiveSet:54
Definition PrimitiveSet:103
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Definition RenderInfo:28
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
void compileGLObjects(osg::RenderInfo &renderInfo) const
virtual void releaseGLObjects(osg::State *state=0) const
If State is non-zero, this function releases any associated OpenGL objects for the specified graphics...
const osg::Vec4 & getParticleColor() const
Definition PrecipitationEffect:70
osg::ref_ptr< osg::Uniform > _particleColorUniform
Definition PrecipitationEffect:237
void setMaximumParticleDensity(float density)
Definition PrecipitationEffect:51
osg::ref_ptr< osg::Geometry > _pointGeometry
Definition PrecipitationEffect:251
virtual ~PrecipitationEffect()
Definition PrecipitationEffect:198
osg::Vec3 _inverse_dw
Definition PrecipitationEffect:262
virtual const char * className() const
return the name of the node's class type.
Definition PrecipitationEffect:36
float _period
Definition PrecipitationEffect:255
osg::ref_ptr< osg::Geometry > _lineGeometry
Definition PrecipitationEffect:248
float getParticleSpeed() const
Definition PrecipitationEffect:64
void setFarTransition(float farTransition)
Definition PrecipitationEffect:75
virtual const char * libraryName() const
return the name of the node's library.
Definition PrecipitationEffect:35
osg::ref_ptr< osg::Uniform > _inversePeriodUniform
Definition PrecipitationEffect:235
bool _useFarLineSegments
Definition PrecipitationEffect:232
osg::Vec3 _wind
Definition PrecipitationEffect:224
float _farTransition
Definition PrecipitationEffect:231
osg::ref_ptr< osg::Uniform > _particleSizeUniform
Definition PrecipitationEffect:236
osg::Vec3 _dv
Definition PrecipitationEffect:258
void setParticleSpeed(float particleSpeed)
Definition PrecipitationEffect:63
void setUseFarLineSegments(bool useFarLineSegments)
Definition PrecipitationEffect:78
virtual bool isSameKindAs(const osg::Object *obj) const
return true if this and obj are of the same kind of object.
Definition PrecipitationEffect:37
float getMaximumParticleDensity() const
Definition PrecipitationEffect:52
osg::Vec3 _inverse_du
Definition PrecipitationEffect:260
osg::ref_ptr< osg::Fog > _fog
Definition PrecipitationEffect:233
osg::StateSet * getPointStateSet()
Definition PrecipitationEffect:92
osg::Vec4 _particleColor
Definition PrecipitationEffect:227
void setParticleSize(float particleSize)
Definition PrecipitationEffect:66
osg::ref_ptr< osg::StateSet > _pointStateSet
Definition PrecipitationEffect:252
float _particleSize
Definition PrecipitationEffect:226
void setWind(const osg::Vec3 &wind)
Definition PrecipitationEffect:54
osg::Geometry * getLineGeometry()
Definition PrecipitationEffect:88
float getParticleSize() const
Definition PrecipitationEffect:67
float _particleSpeed
Definition PrecipitationEffect:225
osg::Vec3 _origin
Definition PrecipitationEffect:256
void rain(float intensity)
Set all the parameters to create an rain effect of specified intensity.
void setNearTransition(float nearTransition)
Definition PrecipitationEffect:72
double _previousFrameTime
Definition PrecipitationEffect:264
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
void setCellSize(const osg::Vec3 &cellSize)
Definition PrecipitationEffect:60
osg::ref_ptr< osg::StateSet > _quadStateSet
Definition PrecipitationEffect:246
float _nearTransition
Definition PrecipitationEffect:230
ViewDrawableMap _viewDrawableMap
Definition PrecipitationEffect:243
osg::Vec3 _cellSize
Definition PrecipitationEffect:229
osg::ref_ptr< osg::StateSet > _lineStateSet
Definition PrecipitationEffect:249
virtual void accept(osg::NodeVisitor &nv)
Visitor Pattern : calls the apply method of a NodeVisitor with this node's type.
Definition PrecipitationEffect:38
OpenThreads::Mutex _mutex
Definition PrecipitationEffect:242
void setPosition(const osg::Vec3 &position)
Definition PrecipitationEffect:57
float getFarTransition() const
Definition PrecipitationEffect:76
osg::StateSet * getLineStateSet()
Definition PrecipitationEffect:89
osg::Fog * getFog()
Definition PrecipitationEffect:82
osg::Geometry * getQuadGeometry()
Definition PrecipitationEffect:85
const osg::Fog * getFog() const
Definition PrecipitationEffect:83
osg::Vec3 _dw
Definition PrecipitationEffect:259
virtual void traverse(osg::NodeVisitor &nv)
Traverse downwards : calls children's accept method with NodeVisitor.
std::pair< osg::NodeVisitor *, osg::NodePath > ViewIdentifier
Definition PrecipitationEffect:239
osg::Geometry * getPointGeometry()
Definition PrecipitationEffect:91
bool build(const osg::Vec3 eyeLocal, int i, int j, int k, float startTime, PrecipitationDrawableSet &pds, osg::Polytope &frustum, osgUtil::CullVisitor *cv) const
osg::Vec3 _inverse_dv
Definition PrecipitationEffect:261
osg::Vec3 _du
Definition PrecipitationEffect:257
void setFog(osg::Fog *fog)
Definition PrecipitationEffect:81
const osg::Vec3 & getWind() const
Definition PrecipitationEffect:55
PrecipitationEffect(const PrecipitationEffect &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osg::StateSet * getQuadStateSet()
Definition PrecipitationEffect:86
const osg::Vec3 & getCellSize() const
Definition PrecipitationEffect:61
float _maximumParticleDensity
Definition PrecipitationEffect:228
std::map< ViewIdentifier, PrecipitationDrawableSet > ViewDrawableMap
Definition PrecipitationEffect:240
const osg::Vec3 & getPosition() const
Definition PrecipitationEffect:58
float getNearTransition() const
Definition PrecipitationEffect:73
void setUpGeometries(unsigned int numParticles)
void setParticleColor(const osg::Vec4 &color)
Definition PrecipitationEffect:69
bool _dirty
Definition PrecipitationEffect:223
void snow(float intensity)
Set all the parameters to create an snow effect of specified intensity.
osg::ref_ptr< osg::Geometry > _quadGeometry
Definition PrecipitationEffect:245
bool getUseFarLineSegments() const
Definition PrecipitationEffect:79
void cull(PrecipitationDrawableSet &pds, osgUtil::CullVisitor *cv) const
void createGeometry(unsigned int numParticles, osg::Geometry *quad_geometry, osg::Geometry *line_geometry, osg::Geometry *point_geometry)
virtual bool supports(const osg::PrimitiveIndexFunctor &) const
Return true if the Drawable subclass supports accept(PrimitiveIndexFunctor&).
Definition PrecipitationEffect:106
CellMatrixMap _currentCellMatrixMap
Definition PrecipitationEffect:188
unsigned int _numberOfVertices
Definition PrecipitationEffect:192
bool getRequiresPreviousMatrix() const
Definition PrecipitationEffect:110
GLenum _drawType
Definition PrecipitationEffect:191
PrecipitationDrawable(const PrecipitationDrawable &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
CellMatrixMap _previousCellMatrixMap
Definition PrecipitationEffect:189
std::map< Cell, DepthMatrixStartTime > CellMatrixMap
Definition PrecipitationEffect:160
CellMatrixMap & getPreviousCellMatrixMap()
Definition PrecipitationEffect:172
void setNumberOfVertices(unsigned int numVertices)
Definition PrecipitationEffect:119
unsigned int getNumberOfVertices() const
Definition PrecipitationEffect:120
osg::Geometry * getGeometry()
Definition PrecipitationEffect:113
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
virtual bool supports(const osg::PrimitiveFunctor &) const
Return true if the Drawable subclass supports accept(PrimitiveFunctor&).
Definition PrecipitationEffect:104
void newFrame()
Definition PrecipitationEffect:174
const osg::Geometry * getGeometry() const
Definition PrecipitationEffect:114
META_Object(osgParticle, PrecipitationDrawable)
GLenum getDrawType() const
Definition PrecipitationEffect:117
void setGeometry(osg::Geometry *geom)
Definition PrecipitationEffect:112
void setDrawType(GLenum type)
Definition PrecipitationEffect:116
virtual void accept(osg::PrimitiveIndexFunctor &) const
Accept a PrimitiveIndexFunctor and call its methods to tell it about the internal primitives that thi...
Definition PrecipitationEffect:107
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
drawImplementation(RenderInfo&) is a pure virtual method for the actual implementation of OpenGL draw...
bool _requiresPreviousMatrix
Definition PrecipitationEffect:184
osg::ref_ptr< osg::Geometry > _geometry
Definition PrecipitationEffect:186
virtual void accept(osg::PrimitiveFunctor &) const
Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Dra...
Definition PrecipitationEffect:105
virtual void releaseGLObjects(osg::State *state) const
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
CellMatrixMap & getCurrentCellMatrixMap()
Definition PrecipitationEffect:171
void setRequiresPreviousMatrix(bool flag)
Definition PrecipitationEffect:109
Cell(int in_i, int in_j, int in_k)
Definition PrecipitationEffect:129
osg::ref_ptr< PrecipitationDrawable > _linePrecipitationDrawable
Definition PrecipitationEffect:215
osg::ref_ptr< PrecipitationDrawable > _pointPrecipitationDrawable
Definition PrecipitationEffect:216
osg::ref_ptr< PrecipitationDrawable > _quadPrecipitationDrawable
Definition PrecipitationEffect:214
Basic NodeVisitor implementation for rendering a scene.
Definition CullVisitor:49
#define OSGPARTICLE_EXPORT
Definition Export:40

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.