30 Namable::operator = (copy);
32 if (is_used_by_auto_shader()) {
33 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
36 _base_color = copy._base_color;
37 _ambient = copy._ambient;
38 _diffuse = copy._diffuse;
39 _specular = copy._specular;
40 _emission = copy._emission;
41 _shininess = copy._shininess;
42 _roughness = copy._roughness;
43 _metallic = copy._metallic;
44 _refractive_index = copy._refractive_index;
45 _flags = (copy._flags & ~(F_attrib_lock | F_used_by_auto_shader)) | (_flags & (F_attrib_lock | F_used_by_auto_shader));
62 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
65 _flags |= F_base_color | F_metallic;
66 _flags &= ~(F_ambient | F_diffuse | F_specular);
69 _ambient = _base_color;
70 _diffuse = _base_color * (1 - _metallic);
73 if (_refractive_index >= 1) {
74 f0 = (_refractive_index - 1) / (_refractive_index + 1);
76 f0 *= (1 - _metallic);
78 _specular.set(f0, f0, f0, 0);
79 _specular += _base_color * _metallic;
88 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
90 _flags &= ~F_base_color;
91 _base_color.set(0.0f, 0.0f, 0.0f, 0.0f);
93 if ((_flags & F_ambient) == 0) {
94 _ambient.set(0, 0, 0, 0);
96 if ((_flags & F_diffuse) == 0) {
97 _diffuse.set(0, 0, 0, 0);
99 if ((_flags & F_specular) == 0) {
102 if (_refractive_index >= 1) {
103 f0 = (_refractive_index - 1) / (_refractive_index + 1);
106 _specular.set(f0, f0, f0, 0);
123 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
142 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
163 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
166 _flags |= F_specular;
175 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
177 _flags &= ~F_specular;
181 if (_refractive_index >= 1) {
182 f0 = (_refractive_index - 1) / (_refractive_index + 1);
184 f0 *= (1 - _metallic);
186 _specular.set(f0, f0, f0, 0);
187 _specular += _base_color * _metallic;
202 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
205 _flags |= F_emission;
220 _shininess = shininess;
221 _flags &= ~F_roughness;
228 PN_stdfloat Material::
229 get_roughness()
const {
230 if ((_flags & F_roughness) == 0) {
232 return csqrt(csqrt(2 / (_shininess + 2)));
249 _roughness = roughness;
250 _flags |= F_roughness;
256 if (roughness <= 0 || IS_NEARLY_ZERO(roughness)) {
257 _shininess = make_inf((PN_stdfloat)0);
259 PN_stdfloat alpha = roughness * roughness;
260 _shininess = 2 / (alpha * alpha) - 2;
273 _metallic = metallic;
274 _flags |= F_metallic;
277 if ((_flags & F_diffuse) == 0) {
278 _diffuse = _base_color * (1 - _metallic);
280 if ((_flags & F_specular) == 0) {
283 if (_refractive_index >= 1) {
284 f0 = (_refractive_index - 1) / (_refractive_index + 1);
286 f0 *= (1 - _metallic);
288 _specular.set(f0, f0, f0, 0);
289 _specular += _base_color * _metallic;
298 _flags &= ~F_metallic;
302 if (_flags & F_base_color) {
303 if ((_flags & F_diffuse) == 0) {
304 _diffuse = _base_color;
306 if ((_flags & F_specular) == 0) {
309 if (_refractive_index >= 1) {
310 f0 = (_refractive_index - 1) / (_refractive_index + 1);
313 _specular.set(f0, f0, f0, 0);
328 _refractive_index = refractive_index;
329 _flags |= F_refractive_index;
331 if ((_flags & F_specular) == 0) {
334 if (_refractive_index >= 1) {
335 f0 = (_refractive_index - 1) / (_refractive_index + 1);
338 _specular.set(f0, f0, f0, 0);
350 if (_flags != other._flags) {
351 return _flags - other._flags;
378 return strcmp(get_name().c_str(), other.get_name().c_str());
385 output(std::ostream &out)
const {
386 out <<
"Material " << get_name();
387 if (has_base_color()) {
388 out <<
" c(" << get_base_color() <<
")";
406 if (_flags & F_roughness) {
411 if (_flags & F_metallic) {
412 out <<
" m" << _metallic;
422 write(std::ostream &out,
int indent_level)
const {
423 indent(out, indent_level) <<
"Material " << get_name() <<
"\n";
441 if (_flags & F_roughness) {
472 me.
add_int32(_flags & ~F_used_by_auto_shader);
474 if (_flags & F_metallic) {
476 _base_color.write_datagram(me);
479 _ambient.write_datagram(me);
480 _diffuse.write_datagram(me);
481 _specular.write_datagram(me);
483 _emission.write_datagram(me);
485 if (_flags & F_roughness) {
493 _ambient.write_datagram(me);
494 _diffuse.write_datagram(me);
495 _specular.write_datagram(me);
496 _emission.write_datagram(me);
512 me->fillin(scan, manager);
528 if (_flags & F_metallic) {
530 _base_color.read_datagram(scan);
534 _ambient.read_datagram(scan);
535 _diffuse.read_datagram(scan);
536 _specular.read_datagram(scan);
538 _emission.read_datagram(scan);
540 if (_flags & F_roughness) {
548 _ambient.read_datagram(scan);
549 _diffuse.read_datagram(scan);
550 _specular.read_datagram(scan);
551 _emission.read_datagram(scan);
555 if (_flags & F_roughness) {
561 if (is_used_by_auto_shader()) {
562 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
set_specular
Specifies the specular color setting of the material.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
has_ambient
Returns true if the ambient color has been explicitly set for this material, false otherwise.
set_ambient
Specifies the ambient color setting of the material.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool has_metallic() const
Returns true if the metallic has been explicitly set for this material, false otherwise.
set_metallic
Sets the metallic setting of the material, which is is used for physically- based rendering models.
set_shininess
Sets the shininess exponent of the material.
Base class for objects that can be written to and read from Bam files.
get_twoside
Returns the state of the two-sided lighting flag.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear_metallic()
Removes the explicit metallic setting from the material.
get_roughness
Returns the roughness previously specified by set_roughness.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
int32_t get_int32()
Extracts a signed 32-bit integer.
std::string get_string()
Extracts a variable-length string.
get_local
Returns the local viewer flag.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
set_base_color
Specifies the base color of the material.
set_diffuse
Specifies the diffuse color setting of the material.
get_diffuse
Returns the diffuse color setting, if it has been set.
has_base_color
Returns true if the base color has been explicitly set for this material, false otherwise.
get_emission
Returns the emission color setting, if it has been set.
has_diffuse
Returns true if the diffuse color has been explicitly set for this material, false otherwise.
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 ...
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
set_emission
Specifies the emission color setting of the material.
get_metallic
Returns the metallic setting, if it has been set.
get_base_color
Returns the base_color color setting, if it has been set.
get_shininess
Returns the shininess exponent of the material.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
get_refractive_index
Returns the index of refraction, or 1 if none has been set for this material.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
get_ambient
Returns the ambient color setting, if it has been set.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool has_refractive_index() const
Returns true if a refractive index has explicitly been specified for this material.
Defines the way an object appears in the presence of lighting.
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
set_roughness
Sets the roughness exponent of the material, where 0 is completely shiny (infinite shininess),...
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
get_specular
Returns the specular color setting, if it has been set.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
static void register_with_read_factory()
Factory method to generate a Material object.
set_refractive_index
Sets the index of refraction of the material, which is used to determine the specular color in absenc...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
has_specular
Returns true if the specular color has been explicitly set for this material, false otherwise.
has_emission
Returns true if the emission color has been explicitly set for this material, false otherwise.