diff --git a/panda/src/particlesystem/Sources.pp b/panda/src/particlesystem/Sources.pp index e6362bd75f..5693e06b49 100644 --- a/panda/src/particlesystem/Sources.pp +++ b/panda/src/particlesystem/Sources.pp @@ -28,7 +28,8 @@ spriteParticleRenderer.h tangentRingEmitter.I \ tangentRingEmitter.h zSpinParticle.I zSpinParticle.h \ zSpinParticleFactory.I zSpinParticleFactory.h \ - particleCommonFuncs.h + particleCommonFuncs.h colorInterpolationManager.I \ + colorInterpolationManager.h // oriented particles currently unimplemented // orientedParticle.I orientedParticle.h \ @@ -46,7 +47,7 @@ sparkleParticleRenderer.cxx sphereSurfaceEmitter.cxx \ sphereVolumeEmitter.cxx spriteParticleRenderer.cxx \ tangentRingEmitter.cxx zSpinParticle.cxx \ - zSpinParticleFactory.cxx + zSpinParticleFactory.cxx colorInterpolationManager.cxx // orientedParticle.cxx orientedParticleFactory.cxx @@ -69,7 +70,8 @@ spriteParticleRenderer.I spriteParticleRenderer.h \ tangentRingEmitter.I tangentRingEmitter.h zSpinParticle.I \ zSpinParticle.h zSpinParticleFactory.I zSpinParticleFactory.h \ - particleCommonFuncs.h + particleCommonFuncs.h colorInterpolationManager.I \ + colorInterpolationManager.h // orientedParticle.I orientedParticle.h \ // orientedParticleFactory.I orientedParticleFactory.h \ diff --git a/panda/src/particlesystem/baseParticleRenderer.I b/panda/src/particlesystem/baseParticleRenderer.I index 245aa515e0..09bf8d5886 100644 --- a/panda/src/particlesystem/baseParticleRenderer.I +++ b/panda/src/particlesystem/baseParticleRenderer.I @@ -65,6 +65,24 @@ get_user_alpha() const { return _user_alpha; } +//////////////////////////////////////////////////////////////////// +// Function : set_color_blend_mode +// Access : public +// Description : sets the ColorBlendAttrib on the _render_node +//////////////////////////////////////////////////////////////////// +INLINE void BaseParticleRenderer:: +set_color_blend_mode(ColorBlendAttrib::Mode bm, ColorBlendAttrib::Operand oa, ColorBlendAttrib::Operand ob) { + CPT(RenderAttrib) ra; + if(bm == ColorBlendAttrib::M_add || bm == ColorBlendAttrib::M_subtract || bm == ColorBlendAttrib::M_inv_subtract) { + ra = ColorBlendAttrib::make(bm,oa,ob); + } else { + ra = ColorBlendAttrib::make(bm); + } + + _render_node->set_attrib(ra); + return; +}; + //////////////////////////////////////////////////////////////////// // Function : get_cur_alpha // Access : public diff --git a/panda/src/particlesystem/baseParticleRenderer.h b/panda/src/particlesystem/baseParticleRenderer.h index 27298043c3..6a032cb921 100644 --- a/panda/src/particlesystem/baseParticleRenderer.h +++ b/panda/src/particlesystem/baseParticleRenderer.h @@ -24,6 +24,7 @@ #include "physicsObject.h" #include "renderState.h" #include "geomNode.h" +#include "colorBlendAttrib.h" #include "particleCommonFuncs.h" #include "baseParticle.h" @@ -61,6 +62,8 @@ PUBLISHED: INLINE void set_user_alpha(float ua); INLINE float get_user_alpha() const; + INLINE void set_color_blend_mode(ColorBlendAttrib::Mode bm, ColorBlendAttrib::Operand oa = ColorBlendAttrib::O_zero, ColorBlendAttrib::Operand ob = ColorBlendAttrib::O_zero); + virtual void output(ostream &out) const; virtual void write(ostream &out, int indent=0) const; diff --git a/panda/src/particlesystem/geomParticleRenderer.I b/panda/src/particlesystem/geomParticleRenderer.I index d3457f96c2..39bb25ef48 100644 --- a/panda/src/particlesystem/geomParticleRenderer.I +++ b/panda/src/particlesystem/geomParticleRenderer.I @@ -42,3 +42,13 @@ INLINE PandaNode *GeomParticleRenderer:: get_geom_node() { return _geom_node; } + +//////////////////////////////////////////////////////////////////// +// Function : get_color_interpolation_manager +// Access : public +//////////////////////////////////////////////////////////////////// + +INLINE ColorInterpolationManager* GeomParticleRenderer:: +get_color_interpolation_manager() const { + return _color_interpolation_manager; +} diff --git a/panda/src/particlesystem/geomParticleRenderer.cxx b/panda/src/particlesystem/geomParticleRenderer.cxx index 2f514d5992..7e817e22c0 100644 --- a/panda/src/particlesystem/geomParticleRenderer.cxx +++ b/panda/src/particlesystem/geomParticleRenderer.cxx @@ -21,6 +21,7 @@ #include "transformState.h" #include "colorScaleAttrib.h" +#include "colorAttrib.h" //////////////////////////////////////////////////////////////////// // Function : GeomParticleRenderer @@ -30,8 +31,11 @@ GeomParticleRenderer:: GeomParticleRenderer(ParticleRendererAlphaMode am, PandaNode *geom_node) : - BaseParticleRenderer(am), _geom_node(geom_node), _pool_size(0) { - + BaseParticleRenderer(am), + _geom_node(geom_node), + _pool_size(0), + _color_interpolation_manager(new ColorInterpolationManager(Colorf(1.0f,1.0f,1.0f,1.0f))) +{ if (_geom_node.is_null()) _geom_node = new PandaNode("empty"); } @@ -182,13 +186,16 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) { cur_node->set_state(_render_state); + float t = cur_particle->get_parameterized_age(); + Colorf c = _color_interpolation_manager->generateColor(t); + if ((_alpha_mode != PR_ALPHA_NONE)) { float alpha_scalar; if(_alpha_mode == PR_ALPHA_USER) { alpha_scalar = get_user_alpha(); } else { - alpha_scalar = cur_particle->get_parameterized_age(); + alpha_scalar = t; if (_alpha_mode == PR_ALPHA_OUT) alpha_scalar = 1.0f - alpha_scalar; else if (_alpha_mode == PR_ALPHA_IN_OUT) @@ -196,10 +203,13 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) { alpha_scalar *= get_user_alpha(); } + c[3] *= alpha_scalar; cur_node->set_attrib(ColorScaleAttrib::make - (Colorf(1.0f, 1.0f, 1.0f, alpha_scalar))); + (Colorf(1.0f, 1.0f, 1.0f, c[3]))); } + cur_node->set_attrib(ColorAttrib::make_flat(c), 0); + cur_node->set_transform(TransformState::make_pos_quat_scale (cur_particle->get_position(), cur_particle->get_orientation(), diff --git a/panda/src/particlesystem/geomParticleRenderer.h b/panda/src/particlesystem/geomParticleRenderer.h index 2dceddd3fb..d95fc948c1 100644 --- a/panda/src/particlesystem/geomParticleRenderer.h +++ b/panda/src/particlesystem/geomParticleRenderer.h @@ -21,6 +21,7 @@ #include "baseParticleRenderer.h" #include "baseParticle.h" +#include "colorInterpolationManager.h" #include "pandaNode.h" #include "pointerTo.h" @@ -37,6 +38,7 @@ PUBLISHED: INLINE void set_geom_node(PandaNode *node); INLINE PandaNode *get_geom_node(); + INLINE ColorInterpolationManager* get_color_interpolation_manager() const; virtual BaseParticleRenderer *make_copy(); @@ -46,6 +48,7 @@ PUBLISHED: private: PT(PandaNode) _geom_node; + PT(ColorInterpolationManager) _color_interpolation_manager; pvector< PT(PandaNode) > _node_vector; diff --git a/panda/src/particlesystem/particlesystem_composite1.cxx b/panda/src/particlesystem/particlesystem_composite1.cxx index 1e6eec0024..31448c71fe 100644 --- a/panda/src/particlesystem/particlesystem_composite1.cxx +++ b/panda/src/particlesystem/particlesystem_composite1.cxx @@ -14,4 +14,4 @@ #include "tangentRingEmitter.cxx" #include "zSpinParticle.cxx" #include "zSpinParticleFactory.cxx" - +#include "colorInterpolationManager.cxx" diff --git a/panda/src/particlesystem/spriteParticleRenderer.I b/panda/src/particlesystem/spriteParticleRenderer.I index a150b04d42..62ee51351b 100644 --- a/panda/src/particlesystem/spriteParticleRenderer.I +++ b/panda/src/particlesystem/spriteParticleRenderer.I @@ -362,3 +362,12 @@ INLINE bool SpriteParticleRenderer:: get_alpha_disable() const { return _alpha_disable; } + +//////////////////////////////////////////////////////////////////// +// Function : SpriteParticleRenderer::get_color_interpolation_manager +// Access : public +//////////////////////////////////////////////////////////////////// +INLINE ColorInterpolationManager* SpriteParticleRenderer:: +get_color_interpolation_manager() const { + return _color_interpolation_manager; +} diff --git a/panda/src/particlesystem/spriteParticleRenderer.cxx b/panda/src/particlesystem/spriteParticleRenderer.cxx index cae0d29603..031e53ffe0 100644 --- a/panda/src/particlesystem/spriteParticleRenderer.cxx +++ b/panda/src/particlesystem/spriteParticleRenderer.cxx @@ -56,9 +56,15 @@ SpriteParticleRenderer(Texture *tex) : _alpha_disable(false), _blend_method(PP_BLEND_LINEAR), _pool_size(0), - _source_type(ST_texture) + _source_type(ST_texture), + _color_interpolation_manager(new ColorInterpolationManager(_color)) { init_geoms(); + + if(use_qpgeom) + cout<<"using qpgeoms"<& po_vector, int ttl_particles) { else if (position[2] < _aabb_min[2]) _aabb_min[2] = position[2]; + + float t = cur_particle->get_parameterized_age(); + // Calculate the color - Colorf c = _color; + // This is where we'll want to give the renderer the new color + //Colorf c = _color; + Colorf c = _color_interpolation_manager->generateColor(t); + int alphamode=get_alpha_mode(); if (alphamode != PR_ALPHA_NONE) { - float t = cur_particle->get_parameterized_age(); - if (alphamode == PR_ALPHA_OUT) - c[3] = (1.0f - t) * get_user_alpha(); + c[3] *= (1.0f - t) * get_user_alpha(); else if (alphamode == PR_ALPHA_IN) - c[3] = t * get_user_alpha(); + c[3] *= t * get_user_alpha(); else if (alphamode == PR_ALPHA_IN_OUT) { - c[3] = 2.0f * min(t, 1.0f - t) * get_user_alpha(); + c[3] *= 2.0f * min(t, 1.0f - t) * get_user_alpha(); } else { assert(alphamode == PR_ALPHA_USER); - c[3] = get_user_alpha(); + c[3] *= get_user_alpha(); } } - + if (use_qpgeom) { vertex.add_data3f(position); color.add_data4f(c); diff --git a/panda/src/particlesystem/spriteParticleRenderer.h b/panda/src/particlesystem/spriteParticleRenderer.h index e8d66f2522..14326143b7 100644 --- a/panda/src/particlesystem/spriteParticleRenderer.h +++ b/panda/src/particlesystem/spriteParticleRenderer.h @@ -30,6 +30,7 @@ #include "geomSprite.h" #include "qpgeomVertexData.h" #include "qpgeomPoints.h" +#include "colorInterpolationManager.h" class NodePath; @@ -75,6 +76,7 @@ PUBLISHED: INLINE void set_alpha_disable(bool ad); INLINE Texture *get_texture() const; + INLINE ColorInterpolationManager* get_color_interpolation_manager() const; INLINE const TexCoordf &get_ll_uv() const; INLINE const TexCoordf &get_ur_uv() const; INLINE float get_width() const; @@ -89,7 +91,7 @@ PUBLISHED: INLINE float get_final_y_scale() const; INLINE float get_nonanimated_theta() const; INLINE ParticleRendererBlendMethod get_alpha_blend_method() const; - INLINE bool get_alpha_disable() const; + INLINE bool get_alpha_disable() const; virtual void output(ostream &out) const; virtual void write(ostream &out, int indent=0) const; @@ -126,6 +128,7 @@ private: bool _alpha_disable; ParticleRendererBlendMethod _blend_method; + PT(ColorInterpolationManager) _color_interpolation_manager; Vertexf _aabb_min; Vertexf _aabb_max;