Panda3D

polylightEffect.h

00001 // Filename: polylightEffect.h
00002 // Created by:  sshodhan (01Jun04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef POLYLIGHTEFFECT_H
00016 #define POLYLIGHTEFFECT_H
00017 
00018 #include "pandabase.h"
00019 
00020 
00021 #include "renderEffect.h"
00022 #include "luse.h"
00023 #include "nodePath.h"
00024 #include "polylightNode.h"
00025 #include "pmap.h"
00026 #include "pnotify.h"
00027 #include "sceneSetup.h"
00028 
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : PolylightEffect
00032 // Description : A PolylightEffect can be used on a node to define a
00033 //               LightGroup  for that node. A LightGroup contains 
00034 //               PolylightNodes which are essentially nodes that add 
00035 //               color to the polygons of a model based on distance.
00036 //               PolylightNode is a cheap way to get lighting effects
00037 //               specially for night scenes
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDA_PGRAPH PolylightEffect : public RenderEffect {
00040 PUBLISHED:
00041   enum ContribType {
00042     CT_proximal,
00043     CT_all,
00044   };
00045 
00046   typedef pvector< NodePath > LightGroup;
00047 
00048 protected:
00049   INLINE PolylightEffect();
00050   INLINE PolylightEffect(const PolylightEffect &copy);
00051 
00052 PUBLISHED:
00053   static CPT(RenderEffect) make();
00054   static CPT(RenderEffect) make(PN_stdfloat weight, ContribType contrib, const LPoint3 &effect_center);
00055   static CPT(RenderEffect) make(PN_stdfloat weight, ContribType contrib, const LPoint3 &effect_center, const LightGroup &lights);
00056   CPT(RenderEffect) add_light(const NodePath &newlight) const;
00057   CPT(RenderEffect) remove_light(const NodePath &newlight) const;
00058   CPT(RenderEffect) set_weight(PN_stdfloat w) const;
00059   CPT(RenderEffect) set_contrib(ContribType c) const;
00060   CPT(RenderEffect) set_effect_center(const LPoint3 &ec) const;
00061   INLINE PN_stdfloat get_weight() const;
00062   INLINE ContribType get_contrib() const;
00063   INLINE LPoint3 get_effect_center()const;
00064 
00065   bool has_light(const NodePath &light) const;
00066 
00067 public:
00068   virtual bool has_cull_callback() const;
00069   virtual void cull_callback(CullTraverser *trav, CullTraverserData &data,
00070                              CPT(TransformState) &node_transform,
00071                              CPT(RenderState) &node_state) const;
00072 
00073   CPT(RenderAttrib) do_poly_light(const SceneSetup *scene, const CullTraverserData *data, const TransformState *node_transform) const;
00074   //CPT(RenderAttrib) do_poly_light(const NodePath &root, const CullTraverserData *data, const TransformState *node_transform) const;
00075 
00076   virtual void output(ostream &out) const;
00077 
00078 private:
00079   ContribType _contribution_type;
00080   PN_stdfloat _weight;
00081   LightGroup _lightgroup;
00082   LPoint3 _effect_center;
00083 
00084 protected:
00085   virtual int compare_to_impl(const RenderEffect *other) const;
00086 
00087 public:
00088   static TypeHandle get_class_type() {
00089     return _type_handle;
00090   }
00091   static void init_type() {
00092     RenderEffect::init_type();
00093     register_type(_type_handle, "PolylightEffect",
00094                   RenderEffect::get_class_type());
00095   }
00096   virtual TypeHandle get_type() const {
00097     return get_class_type();
00098   }
00099   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00100 
00101 private:
00102   static TypeHandle _type_handle;
00103 };
00104 
00105 #include "polylightEffect.I"
00106 
00107 ostream &operator << (ostream &out, PolylightEffect::ContribType ct);
00108 
00109 #endif
00110 
00111 
00112 
 All Classes Functions Variables Enumerations