Form Wang Rui, "An initial GLSL shader support of rendering particles. Only the POINT
type is supported at present. The attached osgparticleshader.cpp will show how it works. It can also be placed in the examples folder. But I just wonder how this example co-exists with another two (osgparticle and osgparticleeffect)? Member variables in Particle, including _alive, _current_size and _current_alpha, are now merged into one Vec3 variable. Then we can make use of the set...Pointer() methods to treat them as vertex attribtues in GLSL. User interfaces are not changed. Additional methods of ParticleSystem are introduced, including setDefaultAttributesUsingShaders(), setSortMode() and setVisibilityDistance(). You can see how they work in osgparticleshader.cpp. Additional user-defined particle type is introduced. Set the particle type to USER and attach a drawable to the template. Be careful because of possible huge memory consumption. It is highly suggested to use display lists here. The ParticleSystemUpdater can accepts ParticleSystem objects as child drawables now. I myself think it is a little simpler in structure, than creating a new geode for each particle system. Of course, the latter is still compatible, and can be used to transform entire particles in the world. New particle operators: bounce, sink, damping, orbit and explosion. The bounce and sink opeartors both use a concept of domains, and can simulate a very basic collision of particles and objects. New composite placer. It contains a set of placers and emit particles from them randomly. The added virtual method size() of each placer will help determine the probability of generating. New virtual method operateParticles() for the Operator class. It actually calls operate() for each particle, but can be overrode to use speedup techniques like SSE, or even shaders in the future. Partly fix a floating error of 'delta time' in emitter, program and updaters. Previously they keep the _t0 variable seperately and compute different copies of dt by themseleves, which makes some operators, especially the BounceOperator, work incorrectly (because the dt in operators and updaters are slightly different). Now a getDeltaTime() method is maintained in ParticleSystem, and will return the unique dt value (passing by reference) for use. This makes thing better, but still very few unexpected behavours at present... All dotosg and serialzier wrappers for functionalities above are provided. ... According to some simple tests, the new shader support is slightly efficient than ordinary glBegin()/end(). That means, I haven't got a big improvement at present. I think the bottlenack here seems to be the cull traversal time. Because operators go through the particle list again and again (for example, the fountain in the shader example requires 4 operators working all the time). A really ideal solution here is to implement the particle operators in shaders, too, and copy the results back to particle attributes. The concept of GPGPU is good for implementing this. But in my opinion, the Camera class seems to be too heavy for realizing such functionality in a particle system. Myabe a light-weight ComputeDrawable class is enough for receiving data as textures and outputting the results to the FBO render buffer. What do you think then? The floating error of emitters (http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2009-May/028435.html) is not solved this time. But what I think is worth testing is that we could directly compute the node path from the emitter to the particle system rather than multiplying the worldToLocal and LocalToWorld matrices. I'll try this idea later. "
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/GL>
|
||||
#include <osg/GLBeginEndAdapter>
|
||||
|
||||
@@ -47,6 +48,7 @@ namespace osgParticle
|
||||
minimum values are used.
|
||||
*/
|
||||
class OSGPARTICLE_EXPORT Particle {
|
||||
friend class ParticleSystem;
|
||||
public:
|
||||
|
||||
enum
|
||||
@@ -63,7 +65,8 @@ namespace osgParticle
|
||||
QUAD, // uses GL_QUADS as primitive
|
||||
QUAD_TRIANGLESTRIP, // uses GL_TRI_angleSTRIP as primitive, but each particle needs a glBegin/glEnd pair
|
||||
HEXAGON, // may save some filling time, but uses more triangles
|
||||
LINE // uses GL_LINES to draw line segments that point to the direction of motion
|
||||
LINE, // uses GL_LINES to draw line segments that point to the direction of motion
|
||||
USER // uses a user-defined drawable as primitive
|
||||
};
|
||||
|
||||
Particle();
|
||||
@@ -139,7 +142,7 @@ namespace osgParticle
|
||||
inline const osg::Vec4& getCurrentColor() const { return _current_color; }
|
||||
|
||||
/// Get the current alpha
|
||||
inline float getCurrentAlpha() const { return _current_alpha; }
|
||||
inline float getCurrentAlpha() const { return _base_prop.z(); }
|
||||
|
||||
/// Get the s texture coordinate of the bottom left of the particle
|
||||
inline float getSTexCoord() const { return _s_coord; }
|
||||
@@ -226,13 +229,13 @@ namespace osgParticle
|
||||
/// Transform angle and angularVelocity vectors by a matrix.
|
||||
inline void transformAngleVelocity(const osg::Matrix& xform);
|
||||
|
||||
/** Update the particle (don't call this method manually).
|
||||
/** Update the particle (don't call this method manually).
|
||||
This method is called automatically by <CODE>ParticleSystem::update()</CODE>; it
|
||||
updates the graphical properties of the particle for the current time,
|
||||
checks whether the particle is still alive, and then updates its position
|
||||
by computing <I>P = P + V * dt</I> (where <I>P</I> is the position and <I>V</I> is the velocity).
|
||||
*/
|
||||
bool update(double dt);
|
||||
bool update(double dt, bool onlyTimeStamp);
|
||||
|
||||
/// Perform some pre-rendering tasks. Called automatically by particle systems.
|
||||
inline void beginRender(osg::GLBeginEndAdapter* gl) const;
|
||||
@@ -240,6 +243,9 @@ namespace osgParticle
|
||||
/// Render the particle. Called automatically by particle systems.
|
||||
void render(osg::GLBeginEndAdapter* gl, const osg::Vec3& xpos, const osg::Vec3& px, const osg::Vec3& py, float scale = 1.0f) const;
|
||||
|
||||
/// Render the particle with user-defined drawable
|
||||
void render(osg::RenderInfo& renderInfo, const osg::Vec3& xpos, const osg::Vec3& xrot) const;
|
||||
|
||||
/// Perform some post-rendering tasks. Called automatically by particle systems.
|
||||
inline void endRender(osg::GLBeginEndAdapter* gl) const;
|
||||
|
||||
@@ -265,6 +271,21 @@ namespace osgParticle
|
||||
|
||||
/// Get the const next particle
|
||||
inline int getNextParticle() const { return _nextParticle; }
|
||||
|
||||
/// Set the depth of the particle
|
||||
inline void setDepth(double d) { _depth = d; }
|
||||
|
||||
/// Get the depth of the particle
|
||||
inline double getDepth() const { return _depth; }
|
||||
|
||||
/// Set the user-defined particle drawable
|
||||
inline void setDrawable(osg::Drawable* d) { _drawable = d; }
|
||||
|
||||
/// Get the user-defined particle drawable
|
||||
inline osg::Drawable* getDrawable() const { return _drawable.get(); }
|
||||
|
||||
/// Sorting operator
|
||||
bool operator<(const Particle &P) const { return _depth < P._depth; }
|
||||
|
||||
/// Method for initializing a particles texture coords as part of a connected particle system.
|
||||
void setUpTexCoordsAsPartOfConnectedParticleSystem(ParticleSystem* ps);
|
||||
@@ -281,7 +302,7 @@ namespace osgParticle
|
||||
osg::ref_ptr<Interpolator> _ai;
|
||||
osg::ref_ptr<Interpolator> _ci;
|
||||
|
||||
bool _alive;
|
||||
//bool _alive;
|
||||
bool _mustdie;
|
||||
double _lifeTime;
|
||||
|
||||
@@ -298,8 +319,9 @@ namespace osgParticle
|
||||
|
||||
double _t0;
|
||||
|
||||
float _current_size;
|
||||
float _current_alpha;
|
||||
//float _current_size;
|
||||
//float _current_alpha;
|
||||
osg::Vec3 _base_prop; // [0] _alive [1] _current_size [2] _current_alpha
|
||||
osg::Vec4 _current_color;
|
||||
|
||||
float _s_tile;
|
||||
@@ -313,6 +335,12 @@ namespace osgParticle
|
||||
// previous and next Particles are only used in ConnectedParticleSystems
|
||||
int _previousParticle;
|
||||
int _nextParticle;
|
||||
|
||||
// the depth of the particle is used only when sorting is enabled
|
||||
double _depth;
|
||||
|
||||
// the particle drawable is used only when USER shape is enabled
|
||||
osg::ref_ptr<osg::Drawable> _drawable;
|
||||
};
|
||||
|
||||
// INLINE FUNCTIONS
|
||||
@@ -329,7 +357,7 @@ namespace osgParticle
|
||||
|
||||
inline bool Particle::isAlive() const
|
||||
{
|
||||
return _alive;
|
||||
return _base_prop.x()>0.0;
|
||||
}
|
||||
|
||||
inline double Particle::getLifeTime() const
|
||||
@@ -569,7 +597,7 @@ namespace osgParticle
|
||||
|
||||
inline float Particle::getCurrentSize() const
|
||||
{
|
||||
return _current_size;
|
||||
return _base_prop.y();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user