Panda3D
Loading...
Searching...
No Matches
light.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 light.h
10 * @author mike
11 * @date 1997-01-09
12 */
13
14#ifndef LIGHT_H
15#define LIGHT_H
16
17#include "pandabase.h"
18
19#include "referenceCount.h"
20#include "luse.h"
21#include "cycleData.h"
22#include "cycleDataReader.h"
24#include "cycleDataWriter.h"
25#include "pipelineCycler.h"
26#include "updateSeq.h"
27#include "geomNode.h"
28
29class NodePath;
30class PandaNode;
32
33/**
34 * The abstract interface to all kinds of lights. The actual light objects
35 * also inherit from PandaNode, and can therefore be added to the scene graph
36 * at some arbitrary point to define the coordinate system of effect.
37 */
38class EXPCL_PANDA_PGRAPH Light {
39PUBLISHED:
40 INLINE Light();
41 INLINE Light(const Light &copy);
42 virtual ~Light();
43
44 virtual PandaNode *as_node()=0;
45 virtual bool is_ambient_light() const;
46
47 INLINE const LColor &get_color() const;
48 INLINE void set_color(const LColor &color);
49 MAKE_PROPERTY(color, get_color, set_color);
50
51 INLINE bool has_color_temperature() const;
52 INLINE PN_stdfloat get_color_temperature() const;
53 void set_color_temperature(PN_stdfloat temperature);
54 MAKE_PROPERTY(color_temperature, get_color_temperature,
56
57 virtual PN_stdfloat get_exponent() const;
58 virtual const LColor &get_specular_color() const;
59 virtual const LVecBase3 &get_attenuation() const;
60
61 INLINE void set_priority(int priority);
62 INLINE int get_priority() const;
63 virtual int get_class_priority() const=0;
64 MAKE_PROPERTY(priority, get_priority, set_priority);
65
66public:
67 virtual void attrib_ref();
68 virtual void attrib_unref();
69
70 virtual void output(std::ostream &out) const=0;
71 virtual void write(std::ostream &out, int indent_level) const=0;
72 virtual void bind(GraphicsStateGuardianBase *gsg, const NodePath &light,
73 int light_id)=0;
74
75 virtual bool get_vector_to_light(LVector3 &result,
76 const LPoint3 &from_object_point,
77 const LMatrix4 &to_object_space);
78
80
81 INLINE static UpdateSeq get_sort_seq();
82
83protected:
84 virtual void fill_viz_geom(GeomNode *viz_geom);
85 INLINE void mark_viz_stale();
86
87 // This enumerated class defines the relative class priority of different
88 // kinds of lights. This hierarchy is only used to resolve multiple lights
89 // of the same priority specified by set_priority(). In general, the first
90 // items in this list have a lesser priority than later items.
91 enum ClassPriority {
92 CP_ambient_priority,
93 CP_point_priority,
94 CP_directional_priority,
95 CP_spot_priority,
96 CP_area_priority,
97 };
98
99private:
100 // The priority is not cycled, because there's no real reason to do so, and
101 // cycling it makes it difficult to synchronize with the LightAttribs.
102 int _priority;
103 static UpdateSeq _sort_seq;
104
105 // The color temperature is not cycled either, because we only need to pass
106 // down the computed color anyway.
107 bool _has_color_temperature;
108 PN_stdfloat _color_temperature;
109
110 // This is the data that must be cycled between pipeline stages.
111 class EXPCL_PANDA_PGRAPH CData : public CycleData {
112 public:
113 INLINE CData();
114 INLINE CData(const CData &copy);
115 virtual CycleData *make_copy() const;
116 virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
117 virtual void fillin(DatagramIterator &scan, BamReader *manager);
118 virtual TypeHandle get_parent_type() const {
119 return Light::get_class_type();
120 }
121
122 LColor _color;
123
124 PT(GeomNode) _viz_geom;
125 bool _viz_geom_stale;
126 };
127
128 PipelineCycler<CData> _cycler;
129 typedef CycleDataReader<CData> CDReader;
130 typedef CycleDataLockedReader<CData> CDLockedReader;
131 typedef CycleDataWriter<CData> CDWriter;
132
133protected:
134 void write_datagram(BamWriter *manager, Datagram &dg);
135 void fillin(DatagramIterator &scan, BamReader *manager);
136
137public:
138 static TypeHandle get_class_type() {
139 return _type_handle;
140 }
141 static void init_type() {
142 ReferenceCount::init_type();
143 register_type(_type_handle, "Light",
144 ReferenceCount::get_class_type());
145 }
146 virtual TypeHandle get_type() const {
147 return get_class_type();
148 }
149
150private:
151 static TypeHandle _type_handle;
152};
153
154INLINE std::ostream &operator << (std::ostream &out, const Light &light) {
155 light.output(out);
156 return out;
157}
158
159#include "light.I"
160
161#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
A single page of data maintained by a PipelineCycler.
Definition cycleData.h:50
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
A node that holds Geom objects, renderable pieces of geometry.
Definition geomNode.h:34
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
The abstract interface to all kinds of lights.
Definition light.h:38
virtual bool get_vector_to_light(LVector3 &result, const LPoint3 &from_object_point, const LMatrix4 &to_object_space)
Computes the vector from a particular vertex to this light.
Definition light.cxx:189
get_color_temperature
Returns the basic color temperature of the light, assuming has_color_temperature() returns true.
Definition light.h:55
set_priority
Changes the relative importance of this light relative to the other lights that are applied simultane...
Definition light.h:64
virtual void attrib_ref()
This is called when the light is added to a LightAttrib.
Definition light.cxx:166
virtual PN_stdfloat get_exponent() const
For spotlights, returns the exponent that controls the amount of light falloff from the center of the...
Definition light.cxx:137
virtual const LVecBase3 & get_attenuation() const
Returns the terms of the attenuation equation for the light.
Definition light.cxx:157
get_color
Returns the basic color of the light.
Definition light.h:49
virtual bool is_ambient_light() const
Returns true if this is an AmbientLight, false if it is some other kind of light.
Definition light.cxx:63
set_color
Sets the basic color of the light.
Definition light.h:49
bool has_color_temperature() const
Returns true if the color was specified as a temperature in kelvins, and get_color_temperature is def...
Definition light.I:85
virtual const LColor & get_specular_color() const
Returns the color of specular highlights generated by the light.
Definition light.cxx:146
static UpdateSeq get_sort_seq()
Returns a global sequence number that is incremented any time any Light in the world changes sort or ...
Definition light.I:134
virtual void attrib_unref()
This is called when the light is removed from a LightAttrib.
Definition light.cxx:173
set_color_temperature
Sets the color temperature of the light in kelvins.
Definition light.h:55
GeomNode * get_viz()
Returns a GeomNode that may be rendered to visualize the Light.
Definition light.cxx:199
get_priority
Returns the priority associated with this light.
Definition light.h:64
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is a sequence number that increments monotonically.
Definition updateSeq.h:37
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.