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;
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());
385output(std::ostream &out)
const {
386 out <<
"Material " << get_name();
406 if (_flags & F_roughness) {
411 if (_flags & F_metallic) {
412 out <<
" m" << _metallic;
422write(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) {
547 if ((_flags & (F_base_color | F_metallic)) == (F_base_color | F_metallic)) {
553 _ambient.read_datagram(scan);
554 _diffuse.read_datagram(scan);
555 _specular.read_datagram(scan);
556 _emission.read_datagram(scan);
560 if (_flags & F_roughness) {
566 if (is_used_by_auto_shader()) {
567 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
A class to retrieve the individual data elements previously stored in a Datagram.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
std::string get_string()
Extracts a variable-length string.
int32_t get_int32()
Extracts a signed 32-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
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...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Defines the way an object appears in the presence of lighting.
get_ambient
Returns the ambient color setting, if it has been set.
has_specular
Returns true if the specular color has been explicitly set for this material, false otherwise.
set_emission
Specifies the emission color setting of the material.
bool has_metallic() const
Returns true if the metallic has been explicitly set for this material, false otherwise.
set_diffuse
Specifies the diffuse color setting of the material.
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.
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.
static void register_with_read_factory()
Factory method to generate a Material object.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
has_base_color
Returns true if the base color has been explicitly set for this material, false otherwise.
set_roughness
Sets the roughness exponent of the material, where 0 is completely shiny (infinite shininess),...
void clear_metallic()
Removes the explicit metallic setting from the material.
set_base_color
Specifies the base color of the material.
get_base_color
Returns the base_color color setting, if it has been set.
get_refractive_index
Returns the index of refraction, or 1 if none has been set for this material.
clear_specular
Removes the explicit specular color from the material.
set_specular
Specifies the specular color setting of the material.
get_twoside
Returns the state of the two-sided lighting flag.
set_ambient
Specifies the ambient color setting of the material.
get_specular
Returns the specular color setting, if it has been set.
has_emission
Returns true if the emission color has been explicitly set for this material, false otherwise.
has_ambient
Returns true if the ambient 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 ...
get_metallic
Returns the metallic setting, if it has been set.
get_roughness
Returns the roughness previously specified by set_roughness.
clear_base_color
Removes the explicit base_color color from the material.
set_refractive_index
Sets the index of refraction of the material, which is used to determine the specular color in absenc...
get_shininess
Returns the shininess exponent of the material.
bool has_refractive_index() const
Returns true if a refractive index has explicitly been specified for this material.
get_diffuse
Returns the diffuse color setting, if it has been set.
get_local
Returns the local viewer flag.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.