Changes to allow color interpolation on sprite and geom renderers

This commit is contained in:
Josh Wilson 2005-06-15 19:03:53 +00:00
parent e3ac4a7782
commit e6193365b9
10 changed files with 86 additions and 18 deletions

View File

@ -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 \

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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(),

View File

@ -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;

View File

@ -14,4 +14,4 @@
#include "tangentRingEmitter.cxx"
#include "zSpinParticle.cxx"
#include "zSpinParticleFactory.cxx"
#include "colorInterpolationManager.cxx"

View File

@ -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;
}

View File

@ -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"<<endl;
else
cout<<"not using qpgeoms"<<endl;
}
////////////////////////////////////////////////////////////////////
@ -515,26 +521,30 @@ render(pvector< PT(PhysicsObject) >& 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);

View File

@ -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;