Panda3D
Loading...
Searching...
No Matches
texProjectorEffect.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file texProjectorEffect.h
10 * @author drose
11 * @date 2004-07-25
12 */
13
14#ifndef TEXPROJECTOREFFECT_H
15#define TEXPROJECTOREFFECT_H
16
17#include "pandabase.h"
18
19#include "renderEffect.h"
20#include "luse.h"
21#include "nodePath.h"
22
23class LensNode;
24
25/**
26 * This effect automatically applies a computed texture matrix to the
27 * specified texture stage, according to the relative position of two
28 * specified nodes.
29 *
30 * The relative transform from the "from" node to the "to" node is applied
31 * directly to the texture matrix each frame. If the "to" node happens to be
32 * a LensNode, its lens projection matrix is applied as well.
33 *
34 * This can be used to apply a number of special effects. Fundamentally, it
35 * may simply be used to provide a separate PandaNode that may be adjusted
36 * (e.g. via a LerpInterval) in order to easily apply a linear transformation
37 * to an object's texture coordinates (rather than having to explicitly call
38 * NodePath.set_tex_transform() each frame).
39 *
40 * In a more sophisticated case, the TexProjectorEffect is particularly useful
41 * in conjunction with a TexGenAttrib that specifies a mode of
42 * M_world_position (which copies the world position of each vertex to the
43 * texture coordinates). Then the TexProjector can be used to convert these
44 * world coordinates to the relative coordinates of a particular node, causing
45 * (for instance) a texture to appear to follow a node around as it moves
46 * through the world. With a LensNode, you can project a texture onto the
47 * walls, for instance to apply a flashlight effect or an image-based shadow.
48 */
49class EXPCL_PANDA_PGRAPH TexProjectorEffect : public RenderEffect {
50protected:
51 INLINE TexProjectorEffect();
52 INLINE TexProjectorEffect(const TexProjectorEffect &copy);
53
54public:
55 virtual ~TexProjectorEffect();
56
57PUBLISHED:
58 static CPT(RenderEffect) make();
59
60 CPT(RenderEffect) add_stage(TextureStage *stage, const NodePath &from, const NodePath &to, int lens_index = 0) const;
61 CPT(RenderEffect) remove_stage(TextureStage *stage) const;
62
63 bool is_empty() const;
64 bool has_stage(TextureStage *stage) const;
65
66 NodePath get_from(TextureStage *stage) const;
67 NodePath get_to(TextureStage *stage) const;
68 int get_lens_index(TextureStage *stage) const;
69
70public:
71 virtual void output(std::ostream &out) const;
72
73 virtual bool has_cull_callback() const;
74 virtual void cull_callback(CullTraverser *trav, CullTraverserData &data,
75 CPT(TransformState) &node_transform,
76 CPT(RenderState) &node_state) const;
77
78protected:
79 virtual int compare_to_impl(const RenderEffect *other) const;
80
81private:
82 class StageDef {
83 public:
84 INLINE StageDef();
85 INLINE void set_from(const NodePath &from);
86 void set_to(const NodePath &to);
87 INLINE void set_lens_index(int lens_index);
88
89 INLINE int compare_to(const StageDef &other) const;
90
91 NodePath _from;
92 NodePath _to;
93 LensNode *_to_lens_node;
94 int _lens_index;
95 };
96
97 typedef pmap<PT(TextureStage), StageDef> Stages;
98 Stages _stages;
99
100 static CPT(RenderEffect) _empty_effect;
101
102public:
103 static void register_with_read_factory();
104 virtual void write_datagram(BamWriter *manager, Datagram &dg);
105 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
106
107protected:
108 static TypedWritable *make_from_bam(const FactoryParams &params);
109 void fillin(DatagramIterator &scan, BamReader *manager);
110
111public:
112 static TypeHandle get_class_type() {
113 return _type_handle;
114 }
115 static void init_type() {
116 RenderEffect::init_type();
117 register_type(_type_handle, "TexProjectorEffect",
118 RenderEffect::get_class_type());
119 }
120 virtual TypeHandle get_type() const {
121 return get_class_type();
122 }
123 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
124
125private:
126 static TypeHandle _type_handle;
127};
128
129#include "texProjectorEffect.I"
130
131#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
A node that contains a Lens.
Definition lensNode.h:29
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual void cull_callback(CullTraverser *trav, CullTraverserData &data, ConstPointerTo< TransformState > &node_transform, ConstPointerTo< RenderState > &node_state) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
int compare_to(const RenderEffect &other) const
Provides an arbitrary ordering among all unique RenderEffects, so we can store the essentially differ...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
int get_lens_index(TextureStage *stage) const
Returns the lens_index associated with the TexProjectorEffect on the indicated stage.
static ConstPointerTo< RenderEffect > make()
Constructs a TexProjectorEffect that modifies no stages at all.
bool is_empty() const
Returns true if no stages are defined in the TexProjectorEffect, false if at least one is.
ConstPointerTo< RenderEffect > remove_stage(TextureStage *stage) const
Returns a new TexProjectorEffect just like this one, with the indicated stage removed.
ConstPointerTo< RenderEffect > add_stage(TextureStage *stage, const NodePath &from, const NodePath &to, int lens_index=0) const
Returns a new TexProjectorEffect just like this one, with the indicated projection for the given stag...
NodePath get_to(TextureStage *stage) const
Returns the "to" node associated with the TexProjectorEffect on the indicated stage.
static void register_with_read_factory()
Tells the BamReader how to create objects of type TexProjectorEffect.
bool has_stage(TextureStage *stage) const
Returns true if there is a transform associated with the indicated stage, or false otherwise (in whic...
NodePath get_from(TextureStage *stage) const
Returns the "from" node associated with the TexProjectorEffect on the indicated stage.
Defines the properties of a named stage of the multitexture pipeline.
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
This is our own Panda specialization on the default STL list.
Definition plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.