Panda3D
Loading...
Searching...
No Matches
material.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 material.h
10 * @author mike
11 * @date 1997-01-09
12 */
13
14#ifndef MATERIAL_H
15#define MATERIAL_H
16
17#include "pandabase.h"
18
20#include "namable.h"
21#include "luse.h"
22#include "numeric_types.h"
23#include "config_gobj.h"
25
26class FactoryParams;
27
28/**
29 * Defines the way an object appears in the presence of lighting. A material
30 * is only necessary if lighting is to be enabled; otherwise, the material
31 * isn't used.
32 *
33 * There are two workflows that are supported: the "classic" workflow of
34 * providing separate ambient, diffuse and specular colors, and the
35 * "metalness" workflow, in which a base color is specified along with a
36 * "metallic" value that indicates whether the material is a metal or a
37 * dielectric.
38 *
39 * The size of the specular highlight can be specified by either specifying
40 * the specular exponent (shininess) or by specifying a roughness value that
41 * in perceptually linear in the range of 0-1.
42 */
43class EXPCL_PANDA_GOBJ Material : public TypedWritableReferenceCount, public Namable {
44PUBLISHED:
45 INLINE explicit Material(const std::string &name = "");
46 INLINE Material(const Material &copy);
47 void operator = (const Material &copy);
48 INLINE ~Material();
49
50 INLINE static Material *get_default();
51
52 INLINE bool has_base_color() const;
53 INLINE const LColor &get_base_color() const;
54 void set_base_color(const LColor &color);
55 void clear_base_color();
56
57 INLINE bool has_ambient() const;
58 INLINE const LColor &get_ambient() const;
59 void set_ambient(const LColor &color);
60 INLINE void clear_ambient();
61
62 INLINE bool has_diffuse() const;
63 INLINE const LColor &get_diffuse() const;
64 void set_diffuse(const LColor &color);
65 INLINE void clear_diffuse();
66
67 INLINE bool has_specular() const;
68 INLINE const LColor &get_specular() const;
69 void set_specular(const LColor &color);
70 void clear_specular();
71
72 INLINE bool has_emission() const;
73 INLINE const LColor &get_emission() const;
74 void set_emission(const LColor &color);
75 INLINE void clear_emission();
76
77 INLINE PN_stdfloat get_shininess() const;
78 void set_shininess(PN_stdfloat shininess);
79
80 INLINE bool has_roughness() const;
81 PN_stdfloat get_roughness() const;
82 void set_roughness(PN_stdfloat roughness);
83
84 INLINE bool has_metallic() const;
85 INLINE PN_stdfloat get_metallic() const;
86 void set_metallic(PN_stdfloat metallic);
87 void clear_metallic();
88
89 INLINE bool has_refractive_index() const;
90 INLINE PN_stdfloat get_refractive_index() const;
91 void set_refractive_index(PN_stdfloat refractive_index);
92
93 INLINE bool get_local() const;
94 INLINE void set_local(bool local);
95 INLINE bool get_twoside() const;
96 INLINE void set_twoside(bool twoside);
97
98 INLINE bool operator == (const Material &other) const;
99 INLINE bool operator != (const Material &other) const;
100 INLINE bool operator < (const Material &other) const;
101
102 int compare_to(const Material &other) const;
103
104 void output(std::ostream &out) const;
105 void write(std::ostream &out, int indent) const;
106
107 INLINE bool is_attrib_locked() const;
108 INLINE void set_attrib_lock();
109
110PUBLISHED:
111 MAKE_PROPERTY2(base_color, has_base_color, get_base_color,
113 MAKE_PROPERTY2(ambient, has_ambient, get_ambient,
115 MAKE_PROPERTY2(diffuse, has_diffuse, get_diffuse,
117 MAKE_PROPERTY2(specular, has_specular, get_specular,
119 MAKE_PROPERTY2(emission, has_emission, get_emission,
121
122 MAKE_PROPERTY(shininess, get_shininess, set_shininess);
123 MAKE_PROPERTY(roughness, get_roughness, set_roughness);
124 MAKE_PROPERTY(metallic, get_metallic, set_metallic);
125 MAKE_PROPERTY(refractive_index, get_refractive_index,
127
128 MAKE_PROPERTY(local, get_local, set_local);
129 MAKE_PROPERTY(twoside, get_twoside, set_twoside);
130
131protected:
132 INLINE bool is_used_by_auto_shader() const;
133
134public:
135 INLINE void mark_used_by_auto_shader();
136 INLINE int get_flags() const;
137
138 enum Flags {
139 F_ambient = 0x001,
140 F_diffuse = 0x002,
141 F_specular = 0x004,
142 F_emission = 0x008,
143 F_local = 0x010,
144 F_twoside = 0x020,
145 F_attrib_lock = 0x040,
146 F_roughness = 0x080,
147 F_metallic = 0x100,
148 F_base_color = 0x200,
149 F_refractive_index = 0x400,
150 F_used_by_auto_shader = 0x800,
151 };
152
153private:
154 LColor _base_color;
155 LColor _ambient;
156 LColor _diffuse;
157 LColor _specular;
158 LColor _emission;
159 PN_stdfloat _shininess;
160 PN_stdfloat _roughness;
161 PN_stdfloat _metallic;
162 PN_stdfloat _refractive_index;
163
164 static PT(Material) _default;
165
166 int _flags;
167
168public:
169 static void register_with_read_factory();
170 virtual void write_datagram(BamWriter *manager, Datagram &me);
171
172protected:
173 static TypedWritable *make_Material(const FactoryParams &params);
174 void fillin(DatagramIterator &scan, BamReader *manager);
175
176public:
177 static TypeHandle get_class_type() {
178 return _type_handle;
179 }
180 static void init_type() {
181 TypedWritableReferenceCount::init_type();
182 register_type(_type_handle, "Material",
183 TypedWritableReferenceCount::get_class_type());
184 }
185 virtual TypeHandle get_type() const {
186 return get_class_type();
187 }
188 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
189
190private:
191
192 static TypeHandle _type_handle;
193};
194
195INLINE std::ostream &operator << (std::ostream &out, const Material &m) {
196 m.output(out);
197 return out;
198}
199
200#include "material.I"
201
202#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 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...
Defines the way an object appears in the presence of lighting.
Definition material.h:43
get_ambient
Returns the ambient color setting, if it has been set.
Definition material.h:114
has_specular
Returns true if the specular color has been explicitly set for this material, false otherwise.
Definition material.h:118
set_emission
Specifies the emission color setting of the material.
Definition material.h:120
bool has_metallic() const
Returns true if the metallic has been explicitly set for this material, false otherwise.
Definition material.I:219
set_diffuse
Specifies the diffuse color setting of the material.
Definition material.h:116
get_emission
Returns the emission color setting, if it has been set.
Definition material.h:120
has_diffuse
Returns true if the diffuse color has been explicitly set for this material, false otherwise.
Definition material.h:116
set_metallic
Sets the metallic setting of the material, which is is used for physically- based rendering models.
Definition material.h:124
set_shininess
Sets the shininess exponent of the material.
Definition material.h:122
has_base_color
Returns true if the base color has been explicitly set for this material, false otherwise.
Definition material.h:112
set_roughness
Sets the roughness exponent of the material, where 0 is completely shiny (infinite shininess),...
Definition material.h:123
void clear_metallic()
Removes the explicit metallic setting from the material.
Definition material.cxx:297
set_base_color
Specifies the base color of the material.
Definition material.h:112
get_base_color
Returns the base_color color setting, if it has been set.
Definition material.h:112
get_refractive_index
Returns the index of refraction, or 1 if none has been set for this material.
Definition material.h:126
clear_specular
Removes the explicit specular color from the material.
Definition material.h:118
void mark_used_by_auto_shader()
Called by the shader generator to indicate that a shader has been generated that uses this material.
Definition material.I:354
set_specular
Specifies the specular color setting of the material.
Definition material.h:118
get_twoside
Returns the state of the two-sided lighting flag.
Definition material.h:129
set_ambient
Specifies the ambient color setting of the material.
Definition material.h:114
set_twoside
Set this true to enable two-sided lighting.
Definition material.h:129
clear_diffuse
Removes the explicit diffuse color from the material.
Definition material.h:116
clear_emission
Removes the explicit emission color from the material.
Definition material.h:120
get_specular
Returns the specular color setting, if it has been set.
Definition material.h:118
has_emission
Returns true if the emission color has been explicitly set for this material, false otherwise.
Definition material.h:120
has_ambient
Returns true if the ambient color has been explicitly set for this material, false otherwise.
Definition material.h:114
int compare_to(const Material &other) const
Returns a number less than zero if this material sorts before the other one, greater than zero if it ...
Definition material.cxx:349
get_metallic
Returns the metallic setting, if it has been set.
Definition material.h:124
bool is_attrib_locked() const
Definition material.I:329
get_roughness
Returns the roughness previously specified by set_roughness.
Definition material.h:123
clear_base_color
Removes the explicit base_color color from the material.
Definition material.h:112
set_refractive_index
Sets the index of refraction of the material, which is used to determine the specular color in absenc...
Definition material.h:126
get_shininess
Returns the shininess exponent of the material.
Definition material.h:122
static Material * get_default()
Returns the default material.
Definition material.I:60
clear_ambient
Removes the explicit ambient color from the material.
Definition material.h:114
bool has_refractive_index() const
Returns true if a refractive index has explicitly been specified for this material.
Definition material.I:237
set_local
Sets the local viewer flag.
Definition material.h:128
get_diffuse
Returns the diffuse color setting, if it has been set.
Definition material.h:116
bool has_roughness() const
Returns true if the roughness has been explicitly set for this material, false otherwise.
Definition material.I:210
get_local
Returns the local viewer flag.
Definition material.h:128
void set_attrib_lock()
Definition material.I:337
void output(std::ostream &out) const
Outputs the Namable.
Definition namable.I:61
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
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.