mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
Changes to allow color interpolation on sprite and geom renderers
This commit is contained in:
parent
e3ac4a7782
commit
e6193365b9
@ -28,7 +28,8 @@
|
|||||||
spriteParticleRenderer.h tangentRingEmitter.I \
|
spriteParticleRenderer.h tangentRingEmitter.I \
|
||||||
tangentRingEmitter.h zSpinParticle.I zSpinParticle.h \
|
tangentRingEmitter.h zSpinParticle.I zSpinParticle.h \
|
||||||
zSpinParticleFactory.I zSpinParticleFactory.h \
|
zSpinParticleFactory.I zSpinParticleFactory.h \
|
||||||
particleCommonFuncs.h
|
particleCommonFuncs.h colorInterpolationManager.I \
|
||||||
|
colorInterpolationManager.h
|
||||||
|
|
||||||
// oriented particles currently unimplemented
|
// oriented particles currently unimplemented
|
||||||
// orientedParticle.I orientedParticle.h \
|
// orientedParticle.I orientedParticle.h \
|
||||||
@ -46,7 +47,7 @@
|
|||||||
sparkleParticleRenderer.cxx sphereSurfaceEmitter.cxx \
|
sparkleParticleRenderer.cxx sphereSurfaceEmitter.cxx \
|
||||||
sphereVolumeEmitter.cxx spriteParticleRenderer.cxx \
|
sphereVolumeEmitter.cxx spriteParticleRenderer.cxx \
|
||||||
tangentRingEmitter.cxx zSpinParticle.cxx \
|
tangentRingEmitter.cxx zSpinParticle.cxx \
|
||||||
zSpinParticleFactory.cxx
|
zSpinParticleFactory.cxx colorInterpolationManager.cxx
|
||||||
|
|
||||||
// orientedParticle.cxx orientedParticleFactory.cxx
|
// orientedParticle.cxx orientedParticleFactory.cxx
|
||||||
|
|
||||||
@ -69,7 +70,8 @@
|
|||||||
spriteParticleRenderer.I spriteParticleRenderer.h \
|
spriteParticleRenderer.I spriteParticleRenderer.h \
|
||||||
tangentRingEmitter.I tangentRingEmitter.h zSpinParticle.I \
|
tangentRingEmitter.I tangentRingEmitter.h zSpinParticle.I \
|
||||||
zSpinParticle.h zSpinParticleFactory.I zSpinParticleFactory.h \
|
zSpinParticle.h zSpinParticleFactory.I zSpinParticleFactory.h \
|
||||||
particleCommonFuncs.h
|
particleCommonFuncs.h colorInterpolationManager.I \
|
||||||
|
colorInterpolationManager.h
|
||||||
|
|
||||||
// orientedParticle.I orientedParticle.h \
|
// orientedParticle.I orientedParticle.h \
|
||||||
// orientedParticleFactory.I orientedParticleFactory.h \
|
// orientedParticleFactory.I orientedParticleFactory.h \
|
||||||
|
@ -65,6 +65,24 @@ get_user_alpha() const {
|
|||||||
return _user_alpha;
|
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
|
// Function : get_cur_alpha
|
||||||
// Access : public
|
// Access : public
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "physicsObject.h"
|
#include "physicsObject.h"
|
||||||
#include "renderState.h"
|
#include "renderState.h"
|
||||||
#include "geomNode.h"
|
#include "geomNode.h"
|
||||||
|
#include "colorBlendAttrib.h"
|
||||||
|
|
||||||
#include "particleCommonFuncs.h"
|
#include "particleCommonFuncs.h"
|
||||||
#include "baseParticle.h"
|
#include "baseParticle.h"
|
||||||
@ -61,6 +62,8 @@ PUBLISHED:
|
|||||||
INLINE void set_user_alpha(float ua);
|
INLINE void set_user_alpha(float ua);
|
||||||
INLINE float get_user_alpha() const;
|
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 output(ostream &out) const;
|
||||||
virtual void write(ostream &out, int indent=0) const;
|
virtual void write(ostream &out, int indent=0) const;
|
||||||
|
|
||||||
|
@ -42,3 +42,13 @@ INLINE PandaNode *GeomParticleRenderer::
|
|||||||
get_geom_node() {
|
get_geom_node() {
|
||||||
return _geom_node;
|
return _geom_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function : get_color_interpolation_manager
|
||||||
|
// Access : public
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
INLINE ColorInterpolationManager* GeomParticleRenderer::
|
||||||
|
get_color_interpolation_manager() const {
|
||||||
|
return _color_interpolation_manager;
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "transformState.h"
|
#include "transformState.h"
|
||||||
#include "colorScaleAttrib.h"
|
#include "colorScaleAttrib.h"
|
||||||
|
#include "colorAttrib.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function : GeomParticleRenderer
|
// Function : GeomParticleRenderer
|
||||||
@ -30,8 +31,11 @@
|
|||||||
|
|
||||||
GeomParticleRenderer::
|
GeomParticleRenderer::
|
||||||
GeomParticleRenderer(ParticleRendererAlphaMode am, PandaNode *geom_node) :
|
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())
|
if (_geom_node.is_null())
|
||||||
_geom_node = new PandaNode("empty");
|
_geom_node = new PandaNode("empty");
|
||||||
}
|
}
|
||||||
@ -182,13 +186,16 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
|
|||||||
|
|
||||||
cur_node->set_state(_render_state);
|
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)) {
|
if ((_alpha_mode != PR_ALPHA_NONE)) {
|
||||||
float alpha_scalar;
|
float alpha_scalar;
|
||||||
|
|
||||||
if(_alpha_mode == PR_ALPHA_USER) {
|
if(_alpha_mode == PR_ALPHA_USER) {
|
||||||
alpha_scalar = get_user_alpha();
|
alpha_scalar = get_user_alpha();
|
||||||
} else {
|
} else {
|
||||||
alpha_scalar = cur_particle->get_parameterized_age();
|
alpha_scalar = t;
|
||||||
if (_alpha_mode == PR_ALPHA_OUT)
|
if (_alpha_mode == PR_ALPHA_OUT)
|
||||||
alpha_scalar = 1.0f - alpha_scalar;
|
alpha_scalar = 1.0f - alpha_scalar;
|
||||||
else if (_alpha_mode == PR_ALPHA_IN_OUT)
|
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();
|
alpha_scalar *= get_user_alpha();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c[3] *= alpha_scalar;
|
||||||
cur_node->set_attrib(ColorScaleAttrib::make
|
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_node->set_transform(TransformState::make_pos_quat_scale
|
||||||
(cur_particle->get_position(),
|
(cur_particle->get_position(),
|
||||||
cur_particle->get_orientation(),
|
cur_particle->get_orientation(),
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "baseParticleRenderer.h"
|
#include "baseParticleRenderer.h"
|
||||||
#include "baseParticle.h"
|
#include "baseParticle.h"
|
||||||
|
#include "colorInterpolationManager.h"
|
||||||
|
|
||||||
#include "pandaNode.h"
|
#include "pandaNode.h"
|
||||||
#include "pointerTo.h"
|
#include "pointerTo.h"
|
||||||
@ -37,6 +38,7 @@ PUBLISHED:
|
|||||||
|
|
||||||
INLINE void set_geom_node(PandaNode *node);
|
INLINE void set_geom_node(PandaNode *node);
|
||||||
INLINE PandaNode *get_geom_node();
|
INLINE PandaNode *get_geom_node();
|
||||||
|
INLINE ColorInterpolationManager* get_color_interpolation_manager() const;
|
||||||
|
|
||||||
virtual BaseParticleRenderer *make_copy();
|
virtual BaseParticleRenderer *make_copy();
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ PUBLISHED:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PT(PandaNode) _geom_node;
|
PT(PandaNode) _geom_node;
|
||||||
|
PT(ColorInterpolationManager) _color_interpolation_manager;
|
||||||
|
|
||||||
pvector< PT(PandaNode) > _node_vector;
|
pvector< PT(PandaNode) > _node_vector;
|
||||||
|
|
||||||
|
@ -14,4 +14,4 @@
|
|||||||
#include "tangentRingEmitter.cxx"
|
#include "tangentRingEmitter.cxx"
|
||||||
#include "zSpinParticle.cxx"
|
#include "zSpinParticle.cxx"
|
||||||
#include "zSpinParticleFactory.cxx"
|
#include "zSpinParticleFactory.cxx"
|
||||||
|
#include "colorInterpolationManager.cxx"
|
||||||
|
@ -362,3 +362,12 @@ INLINE bool SpriteParticleRenderer::
|
|||||||
get_alpha_disable() const {
|
get_alpha_disable() const {
|
||||||
return _alpha_disable;
|
return _alpha_disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function : SpriteParticleRenderer::get_color_interpolation_manager
|
||||||
|
// Access : public
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE ColorInterpolationManager* SpriteParticleRenderer::
|
||||||
|
get_color_interpolation_manager() const {
|
||||||
|
return _color_interpolation_manager;
|
||||||
|
}
|
||||||
|
@ -56,9 +56,15 @@ SpriteParticleRenderer(Texture *tex) :
|
|||||||
_alpha_disable(false),
|
_alpha_disable(false),
|
||||||
_blend_method(PP_BLEND_LINEAR),
|
_blend_method(PP_BLEND_LINEAR),
|
||||||
_pool_size(0),
|
_pool_size(0),
|
||||||
_source_type(ST_texture)
|
_source_type(ST_texture),
|
||||||
|
_color_interpolation_manager(new ColorInterpolationManager(_color))
|
||||||
{
|
{
|
||||||
init_geoms();
|
init_geoms();
|
||||||
|
|
||||||
|
if(use_qpgeom)
|
||||||
|
cout<<"using qpgeoms"<<endl;
|
||||||
|
else
|
||||||
|
cout<<"not using qpgeoms"<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -515,23 +521,27 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
|
|||||||
else if (position[2] < _aabb_min[2])
|
else if (position[2] < _aabb_min[2])
|
||||||
_aabb_min[2] = position[2];
|
_aabb_min[2] = position[2];
|
||||||
|
|
||||||
|
|
||||||
|
float t = cur_particle->get_parameterized_age();
|
||||||
|
|
||||||
// Calculate the color
|
// 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();
|
int alphamode=get_alpha_mode();
|
||||||
if (alphamode != PR_ALPHA_NONE) {
|
if (alphamode != PR_ALPHA_NONE) {
|
||||||
float t = cur_particle->get_parameterized_age();
|
|
||||||
|
|
||||||
if (alphamode == PR_ALPHA_OUT)
|
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)
|
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) {
|
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 {
|
else {
|
||||||
assert(alphamode == PR_ALPHA_USER);
|
assert(alphamode == PR_ALPHA_USER);
|
||||||
c[3] = get_user_alpha();
|
c[3] *= get_user_alpha();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "geomSprite.h"
|
#include "geomSprite.h"
|
||||||
#include "qpgeomVertexData.h"
|
#include "qpgeomVertexData.h"
|
||||||
#include "qpgeomPoints.h"
|
#include "qpgeomPoints.h"
|
||||||
|
#include "colorInterpolationManager.h"
|
||||||
|
|
||||||
class NodePath;
|
class NodePath;
|
||||||
|
|
||||||
@ -75,6 +76,7 @@ PUBLISHED:
|
|||||||
INLINE void set_alpha_disable(bool ad);
|
INLINE void set_alpha_disable(bool ad);
|
||||||
|
|
||||||
INLINE Texture *get_texture() const;
|
INLINE Texture *get_texture() const;
|
||||||
|
INLINE ColorInterpolationManager* get_color_interpolation_manager() const;
|
||||||
INLINE const TexCoordf &get_ll_uv() const;
|
INLINE const TexCoordf &get_ll_uv() const;
|
||||||
INLINE const TexCoordf &get_ur_uv() const;
|
INLINE const TexCoordf &get_ur_uv() const;
|
||||||
INLINE float get_width() const;
|
INLINE float get_width() const;
|
||||||
@ -126,6 +128,7 @@ private:
|
|||||||
bool _alpha_disable;
|
bool _alpha_disable;
|
||||||
|
|
||||||
ParticleRendererBlendMethod _blend_method;
|
ParticleRendererBlendMethod _blend_method;
|
||||||
|
PT(ColorInterpolationManager) _color_interpolation_manager;
|
||||||
|
|
||||||
Vertexf _aabb_min;
|
Vertexf _aabb_min;
|
||||||
Vertexf _aabb_max;
|
Vertexf _aabb_max;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user