Browse Source

added choice of additive or modulated mode

Josh Wilson 19 years ago
parent
commit
eea0bf839e

+ 24 - 0
panda/src/particlesystem/colorInterpolationManager.I

@@ -169,6 +169,17 @@ get_time_end() const {
   return _t_end;
   return _t_end;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//    Function : ColorInterpolationSegment::is_modulated
+//      Access : public
+// Description : Returns whether the function is additive or modulated.
+////////////////////////////////////////////////////////////////////
+
+INLINE bool ColorInterpolationSegment::
+is_modulated() const {
+  return _is_modulated;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //    Function : ColorInterpolationSegment::is_enabled()
 //    Function : ColorInterpolationSegment::is_enabled()
 //      Access : public
 //      Access : public
@@ -232,6 +243,19 @@ set_time_end(const float time) {
   _t_total = _t_end-_t_begin;
   _t_total = _t_end-_t_begin;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//    Function : ColorInterpolationSegment::set_is_modulated
+//      Access : public
+// Description : Sets how the function is applied to the final color.
+//               If true, the value is multiplied. If false, the value
+//               is simply added. Default is true.
+////////////////////////////////////////////////////////////////////
+
+INLINE void ColorInterpolationSegment::
+set_is_modulated(const bool flag) {
+  _is_modulated = flag;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //    Function : ColorInterpolationSegment::set_enabled()
 //    Function : ColorInterpolationSegment::set_enabled()
 //      Access : public
 //      Access : public

+ 20 - 6
panda/src/particlesystem/colorInterpolationManager.cxx

@@ -208,6 +208,7 @@ ColorInterpolationSegment(ColorInterpolationFunction* function,
   _t_begin(time_begin),
   _t_begin(time_begin),
   _t_end(time_end),
   _t_end(time_end),
   _t_total(time_end-time_begin),
   _t_total(time_end-time_begin),
+  _is_modulated(true),
   _enabled(true),
   _enabled(true),
   _id(id) {
   _id(id) {
 }
 }
@@ -224,6 +225,7 @@ ColorInterpolationSegment(const ColorInterpolationSegment &copy) :
   _t_begin(copy._t_begin),
   _t_begin(copy._t_begin),
   _t_end(copy._t_end),
   _t_end(copy._t_end),
   _t_total(copy._t_total),
   _t_total(copy._t_total),
+  _is_modulated(copy._is_modulated),
   _enabled(copy._enabled),
   _enabled(copy._enabled),
   _id(copy._id) {
   _id(copy._id) {
 }
 }
@@ -411,7 +413,7 @@ clear_to_initial() {
 Colorf ColorInterpolationManager::
 Colorf ColorInterpolationManager::
 generateColor(const float interpolated_time) {
 generateColor(const float interpolated_time) {
   bool segment_found = false;
   bool segment_found = false;
-  Colorf out(0.0f,0.0f,0.0f,0.0f);
+  Colorf out(_default_color);
   ColorInterpolationSegment *cur_seg;
   ColorInterpolationSegment *cur_seg;
   pvector<PT(ColorInterpolationSegment)>::iterator iter;
   pvector<PT(ColorInterpolationSegment)>::iterator iter;
 
 
@@ -421,15 +423,27 @@ generateColor(const float interpolated_time) {
         interpolated_time >= cur_seg->get_time_begin() 
         interpolated_time >= cur_seg->get_time_begin() 
         && interpolated_time <= cur_seg->get_time_end() ) {
         && interpolated_time <= cur_seg->get_time_end() ) {
       segment_found = true;
       segment_found = true;
-      out += cur_seg->interpolateColor(interpolated_time);
-      out[0] = max(0.0f, min(out[0], 1.0f));
-      out[1] = max(0.0f, min(out[1], 1.0f));
-      out[2] = max(0.0f, min(out[2], 1.0f));
-      out[3] = max(0.0f, min(out[3], 1.0f));
+      Colorf cur_color = cur_seg->interpolateColor(interpolated_time);
+      if( cur_seg->is_modulated() ) {
+        out[0] *= cur_color[0];
+        out[1] *= cur_color[1];
+        out[2] *= cur_color[2];
+        out[3] *= cur_color[3];
+      }
+      else {
+        out[0] += cur_color[0];
+        out[1] += cur_color[1];
+        out[2] += cur_color[2];
+        out[3] += cur_color[3];
+      }
     }
     }
   }
   }
   
   
   if(segment_found) {
   if(segment_found) {
+      out[0] = max(0.0f, min(out[0], 1.0f));
+      out[1] = max(0.0f, min(out[1], 1.0f));
+      out[2] = max(0.0f, min(out[2], 1.0f));
+      out[3] = max(0.0f, min(out[3], 1.0f));
     return out;
     return out;
   }
   }
   
   

+ 3 - 0
panda/src/particlesystem/colorInterpolationManager.h

@@ -252,12 +252,14 @@ PUBLISHED:
   INLINE TypedReferenceCount* get_function() const;
   INLINE TypedReferenceCount* get_function() const;
   INLINE float get_time_begin() const;
   INLINE float get_time_begin() const;
   INLINE float get_time_end() const;
   INLINE float get_time_end() const;
+  INLINE bool is_modulated() const;
   INLINE int get_id() const;
   INLINE int get_id() const;
   INLINE bool is_enabled() const;
   INLINE bool is_enabled() const;
 
 
   INLINE void set_function(ColorInterpolationFunction* function);
   INLINE void set_function(ColorInterpolationFunction* function);
   INLINE void set_time_begin(const float time);
   INLINE void set_time_begin(const float time);
   INLINE void set_time_end(const float time);
   INLINE void set_time_end(const float time);
+  INLINE void set_is_modulated(const bool flag);
   INLINE void set_enabled(const bool enabled);
   INLINE void set_enabled(const bool enabled);
 
 
 public:
 public:
@@ -268,6 +270,7 @@ protected:
   float _t_begin;
   float _t_begin;
   float _t_end;
   float _t_end;
   float _t_total;
   float _t_total;
+  bool _is_modulated;
   bool _enabled;
   bool _enabled;
   const int _id;
   const int _id;
 };
 };