Defines the way an object appears in the presence of lighting. More...
#include "material.h"
Public Member Functions | |
Material (const std::string &name="") | |
Material (const Material ©) | |
void | clear_ambient () |
void | clear_base_color () |
void | clear_diffuse () |
void | clear_emission () |
void | clear_metallic () |
Removes the explicit metallic setting from the material. More... | |
void | clear_specular () |
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 sorts after, or zero if they are equivalent. More... | |
virtual TypeHandle | force_init_type () |
const LColor & | get_ambient () const |
const LColor & | get_base_color () const |
const LColor & | get_diffuse () const |
const LColor & | get_emission () const |
int | get_flags () const |
bool | get_local () const |
PN_stdfloat | get_metallic () const |
PN_stdfloat | get_refractive_index () const |
PN_stdfloat | get_roughness () const |
PN_stdfloat | get_shininess () const |
const LColor & | get_specular () const |
bool | get_twoside () const |
virtual TypeHandle | get_type () const |
bool | has_ambient () const |
bool | has_base_color () const |
bool | has_diffuse () const |
bool | has_emission () const |
bool | has_metallic () const |
Returns true if the metallic has been explicitly set for this material, false otherwise. More... | |
bool | has_refractive_index () const |
Returns true if a refractive index has explicitly been specified for this material. More... | |
bool | has_roughness () const |
Returns true if the roughness has been explicitly set for this material, false otherwise. More... | |
bool | has_specular () const |
bool | is_attrib_locked () const |
void | mark_used_by_auto_shader () |
Called by the shader generator to indicate that a shader has been generated that uses this material. More... | |
bool | operator != (const Material &other) const |
bool | operator< (const Material &other) const |
void | operator= (const Material ©) |
bool | operator== (const Material &other) const |
void | output (std::ostream &out) const |
void | set_ambient (const LColor &color) |
void | set_attrib_lock () |
void | set_base_color (const LColor &color) |
void | set_diffuse (const LColor &color) |
void | set_emission (const LColor &color) |
void | set_local (bool local) |
void | set_metallic (PN_stdfloat metallic) |
void | set_refractive_index (PN_stdfloat refractive_index) |
void | set_roughness (PN_stdfloat roughness) |
void | set_shininess (PN_stdfloat shininess) |
void | set_specular (const LColor &color) |
void | set_twoside (bool twoside) |
void | write (std::ostream &out, int indent) const |
virtual void | write_datagram (BamWriter *manager, Datagram &me) |
Function to write the important information in the particular object to a Datagram. More... | |
Public Member Functions inherited from TypedWritableReferenceCount | |
TypedWritableReferenceCount (const TypedWritableReferenceCount ©) | |
virtual ReferenceCount * | as_reference_count () |
Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type. More... | |
void | operator= (const TypedWritableReferenceCount ©) |
Public Member Functions inherited from TypedWritable | |
TypedWritable (const TypedWritable ©) | |
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(). More... | |
vector_uchar | encode_to_bam_stream () const |
Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a bytes object. More... | |
bool | encode_to_bam_stream (vector_uchar &data, BamWriter *writer=nullptr) const |
Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. More... | |
virtual void | finalize (BamReader *manager) |
Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed. More... | |
UpdateSeq | get_bam_modified () const |
Returns the current bam_modified counter. More... | |
void | mark_bam_modified () |
Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. More... | |
void | operator= (const TypedWritable ©) |
virtual bool | require_fully_complete () const |
Some objects require all of their nested pointers to have been completed before the objects themselves can be completed. More... | |
virtual void | update_bam_nested (BamWriter *manager) |
Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates. More... | |
Public Member Functions inherited from TypedObject | |
TypedObject (const TypedObject ©)=default | |
TypedObject * | as_typed_object () |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
const TypedObject * | as_typed_object () const |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
int | get_best_parent_from_Set (const std::set< int > &) const |
int | get_type_index () const |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More... | |
bool | is_exact_type (TypeHandle handle) const |
Returns true if the current object is the indicated type exactly. More... | |
bool | is_of_type (TypeHandle handle) const |
Returns true if the current object is or derives from the indicated type. More... | |
TypedObject & | operator= (const TypedObject ©)=default |
Public Member Functions inherited from ReferenceCount | |
int | get_ref_count () const |
WeakReferenceList * | get_weak_list () const |
Returns the WeakReferenceList associated with this ReferenceCount object. More... | |
bool | has_weak_list () const |
Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More... | |
void | local_object () |
This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More... | |
void | ref () const |
Explicitly increments the reference count. More... | |
bool | ref_if_nonzero () const |
Atomically increases the reference count of this object if it is not zero. More... | |
bool | test_ref_count_integrity () const |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
bool | test_ref_count_nonzero () const |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More... | |
virtual bool | unref () const |
Explicitly decrements the reference count. More... | |
WeakReferenceList * | weak_ref () |
Adds the indicated PointerToVoid as a weak reference to this object. More... | |
void | weak_unref () |
Removes the indicated PointerToVoid as a weak reference to this object. More... | |
Public Member Functions inherited from Namable | |
Namable (const std::string &initial_name="") | |
void | clear_name () |
Resets the Namable's name to empty. More... | |
const std::string & | get_name () const |
bool | has_name () const |
Returns true if the Namable has a nonempty name set, false if the name is empty. More... | |
void | output (std::ostream &out) const |
Outputs the Namable. More... | |
void | set_name (const std::string &name) |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static Material * | get_default () |
Returns the default material. More... | |
static void | init_type () |
static void | register_with_read_factory () |
Factory method to generate a Material object. More... | |
Static Public Member Functions inherited from TypedWritableReferenceCount | |
static TypeHandle | get_class_type () |
static void | init_type () |
static | PT (TypedWritableReferenceCount) decode_from_bam_stream(vector_uchar data |
Static Public Member Functions inherited from TypedWritable | |
static bool | decode_raw_from_bam_stream (TypedWritable *&ptr, ReferenceCount *&ref_ptr, vector_uchar data, BamReader *reader=nullptr) |
Reads the bytes created by a previous call to encode_to_bam_stream(), and extracts the single object on those bytes. More... | |
static TypeHandle | get_class_type () |
static void | init_type () |
Static Public Member Functions inherited from TypedObject | |
static TypeHandle | get_class_type () |
static void | init_type () |
This function is declared non-inline to work around a compiler bug in g++ 2.96. More... | |
Static Public Member Functions inherited from ReferenceCount | |
static TypeHandle | get_class_type () |
static void | init_type () |
Static Public Member Functions inherited from Namable | |
static TypeHandle | get_class_type () |
static void | init_type () |
Public Attributes | |
clear_ambient | |
Removes the explicit ambient color from the material. More... | |
clear_base_color | |
Removes the explicit base_color color from the material. More... | |
clear_diffuse | |
Removes the explicit diffuse color from the material. More... | |
clear_emission | |
Removes the explicit emission color from the material. More... | |
clear_specular | |
Removes the explicit specular color from the material. More... | |
get_ambient | |
Returns the ambient color setting, if it has been set. More... | |
get_base_color | |
Returns the base_color color setting, if it has been set. More... | |
get_diffuse | |
Returns the diffuse color setting, if it has been set. More... | |
get_emission | |
Returns the emission color setting, if it has been set. More... | |
get_local | |
Returns the local viewer flag. More... | |
get_metallic | |
Returns the metallic setting, if it has been set. More... | |
get_refractive_index | |
Returns the index of refraction, or 1 if none has been set for this material. More... | |
get_roughness | |
Returns the roughness previously specified by set_roughness. More... | |
get_shininess | |
Returns the shininess exponent of the material. More... | |
get_specular | |
Returns the specular color setting, if it has been set. More... | |
get_twoside | |
Returns the state of the two-sided lighting flag. More... | |
has_ambient | |
Returns true if the ambient color has been explicitly set for this material, false otherwise. More... | |
has_base_color | |
Returns true if the base color has been explicitly set for this material, false otherwise. More... | |
has_diffuse | |
Returns true if the diffuse color has been explicitly set for this material, false otherwise. More... | |
has_emission | |
Returns true if the emission color has been explicitly set for this material, false otherwise. More... | |
has_specular | |
Returns true if the specular color has been explicitly set for this material, false otherwise. More... | |
set_ambient | |
Specifies the ambient color setting of the material. More... | |
set_base_color | |
Specifies the base color of the material. More... | |
set_diffuse | |
Specifies the diffuse color setting of the material. More... | |
set_emission | |
Specifies the emission color setting of the material. More... | |
set_local | |
Sets the local viewer flag. More... | |
set_metallic | |
Sets the metallic setting of the material, which is is used for physically- based rendering models. More... | |
set_refractive_index | |
Sets the index of refraction of the material, which is used to determine the specular color in absence of an explicit specular color assignment. More... | |
set_roughness | |
Sets the roughness exponent of the material, where 0 is completely shiny (infinite shininess), and 1 is a completely dull object (0 shininess). More... | |
set_shininess | |
Sets the shininess exponent of the material. More... | |
set_specular | |
Specifies the specular color setting of the material. More... | |
set_twoside | |
Set this true to enable two-sided lighting. More... | |
Public Attributes inherited from TypedWritableReferenceCount | |
static BamReader * | reader = nullptr) |
Public Attributes inherited from TypedObject | |
get_type | |
Public Attributes inherited from ReferenceCount | |
get_ref_count | |
Returns the current reference count. More... | |
Public Attributes inherited from Namable | |
get_name | |
set_name | |
Additional Inherited Members | |
Static Public Attributes inherited from TypedWritable | |
static TypedWritable *const | Null = nullptr |
Defines the way an object appears in the presence of lighting.
A material is only necessary if lighting is to be enabled; otherwise, the material isn't used.
There are two workflows that are supported: the "classic" workflow of providing separate ambient, diffuse and specular colors, and the "metalness" workflow, in which a base color is specified along with a "metallic" value that indicates whether the material is a metal or a dielectric.
The size of the specular highlight can be specified by either specifying the specular exponent (shininess) or by specifying a roughness value that in perceptually linear in the range of 0-1.
Definition at line 43 of file material.h.
void Material::clear_metallic | ( | ) |
Removes the explicit metallic setting from the material.
Definition at line 297 of file material.cxx.
int Material::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 sorts after, or zero if they are equivalent.
The sorting order is arbitrary and largely meaningless, except to differentiate different materials.
Definition at line 349 of file material.cxx.
References get_ambient, get_base_color, get_diffuse, get_emission, get_metallic, get_refractive_index, get_shininess, get_specular, has_ambient, has_base_color, has_diffuse, has_emission, and has_specular.
|
inlinestatic |
Returns the default material.
Definition at line 60 of file material.I.
|
inline |
Returns true if the metallic has been explicitly set for this material, false otherwise.
Definition at line 219 of file material.I.
|
inline |
Returns true if a refractive index has explicitly been specified for this material.
Definition at line 237 of file material.I.
|
inline |
Returns true if the roughness has been explicitly set for this material, false otherwise.
Definition at line 210 of file material.I.
|
inline |
Definition at line 329 of file material.I.
|
inline |
Called by the shader generator to indicate that a shader has been generated that uses this material.
Definition at line 354 of file material.I.
|
static |
Factory method to generate a Material object.
Definition at line 459 of file material.cxx.
References BamReader::get_factory(), and Factory< Type >::register_factory().
|
inline |
Definition at line 337 of file material.I.
Referenced by CPT().
Function to write the important information in the particular object to a Datagram.
Reimplemented from TypedWritable.
Definition at line 468 of file material.cxx.
References Datagram::add_int32(), Datagram::add_stdfloat(), Datagram::add_string(), and BamWriter::get_file_minor_ver().
|
inline |
Removes the explicit ambient color from the material.
Definition at line 114 of file material.h.
void Material::clear_base_color |
Removes the explicit base_color color from the material.
Definition at line 112 of file material.h.
|
inline |
Removes the explicit diffuse color from the material.
Definition at line 116 of file material.h.
|
inline |
Removes the explicit emission color from the material.
Definition at line 120 of file material.h.
void Material::clear_specular |
Removes the explicit specular color from the material.
Definition at line 118 of file material.h.
|
inline |
Returns the ambient color setting, if it has been set.
Returns (0,0,0,0) if the ambient color has not been set.
Definition at line 114 of file material.h.
Referenced by compare_to().
|
inline |
Returns the base_color color setting, if it has been set.
If neither the base color nor the metallic have been set, this returns the diffuse color.
Definition at line 112 of file material.h.
Referenced by compare_to().
|
inline |
Returns the diffuse color setting, if it has been set.
Returns (1,1,1,1) if the diffuse color has not been set.
Definition at line 116 of file material.h.
Referenced by compare_to().
|
inline |
Returns the emission color setting, if it has been set.
Returns (0,0,0,0) if the emission color has not been set.
Definition at line 120 of file material.h.
Referenced by compare_to().
|
inline |
|
inline |
Returns the metallic setting, if it has been set.
Returns 0 if it has not been set.
Definition at line 124 of file material.h.
Referenced by compare_to().
|
inline |
Returns the index of refraction, or 1 if none has been set for this material.
Definition at line 126 of file material.h.
Referenced by compare_to().
PN_stdfloat Material::get_roughness |
Returns the roughness previously specified by set_roughness.
If none was previously set, this value is computed from the shininess value.
Definition at line 123 of file material.h.
|
inline |
Returns the shininess exponent of the material.
Definition at line 122 of file material.h.
Referenced by compare_to().
|
inline |
Returns the specular color setting, if it has been set.
Returns (0,0,0,0) if the specular color has not been set.
Definition at line 118 of file material.h.
Referenced by compare_to().
|
inline |
Returns the state of the two-sided lighting flag.
See set_twoside().
Definition at line 129 of file material.h.
|
inline |
Returns true if the ambient color has been explicitly set for this material, false otherwise.
Definition at line 114 of file material.h.
Referenced by compare_to().
|
inline |
Returns true if the base color has been explicitly set for this material, false otherwise.
Definition at line 112 of file material.h.
Referenced by compare_to().
|
inline |
Returns true if the diffuse color has been explicitly set for this material, false otherwise.
Definition at line 116 of file material.h.
Referenced by compare_to().
|
inline |
Returns true if the emission color has been explicitly set for this material, false otherwise.
Definition at line 120 of file material.h.
Referenced by compare_to().
|
inline |
Returns true if the specular color has been explicitly set for this material, false otherwise.
Definition at line 118 of file material.h.
Referenced by compare_to().
void Material::set_ambient |
Specifies the ambient color setting of the material.
This will be the multiplied by any ambient lights in effect on the material to set its base color.
This is the color of the object as it appears in the absence of direct light.
If this is not set, the object color will be used.
Definition at line 114 of file material.h.
void Material::set_base_color |
Specifies the base color of the material.
In conjunction with set_metallic, this is an alternate way to specify the color of a material. For dielectrics, this will determine the value of the diffuse color, and for metals, this will determine the value of the specular color.
Setting this will clear an explicit specular, diffuse or ambient color assignment.
If this is not set, the object color will be used.
Definition at line 112 of file material.h.
void Material::set_diffuse |
Specifies the diffuse color setting of the material.
This will be multiplied by any lights in effect on the material to get the color in the parts of the object illuminated by the lights.
This is the primary color of an object; the color of the object as it appears in direct light, in the absence of highlights.
If this is not set, the object color will be used.
Definition at line 116 of file material.h.
void Material::set_emission |
Specifies the emission color setting of the material.
This is the color of the object as it appears in the absence of any light whatsover, including ambient light. It is as if the object is glowing by this color (although of course it will not illuminate neighboring objects).
If this is not set, the object will not glow by its own light and will only appear visible in the presence of one or more lights.
Definition at line 120 of file material.h.
|
inline |
Sets the local viewer flag.
Set this true to enable camera-relative specular highlights, or false to use orthogonal specular highlights. The default value is true. Applications that use orthogonal projection should specify false.
Definition at line 128 of file material.h.
void Material::set_metallic |
Sets the metallic setting of the material, which is is used for physically- based rendering models.
This is usually 0 for dielectric materials and 1 for metals. It really does not make sense to set this to a value other than 0 or 1, but it is nonetheless a float for compatibility with tools that allow setting this to values other than 0 or 1.
Definition at line 124 of file material.h.
void Material::set_refractive_index |
Sets the index of refraction of the material, which is used to determine the specular color in absence of an explicit specular color assignment.
This is usually 1.5 for dielectric materials. It is not very useful for metals, since they cannot be described as easily with a single number.
Should be 1 or higher. The default is 1.
Definition at line 126 of file material.h.
void Material::set_roughness |
Sets the roughness exponent of the material, where 0 is completely shiny (infinite shininess), and 1 is a completely dull object (0 shininess).
This is a different, more perceptually intuitive way of controlling the size of the specular spot, and more commonly used in physically-based rendering.
Setting a roughness recalculates the shininess value.
Definition at line 123 of file material.h.
void Material::set_shininess |
Sets the shininess exponent of the material.
This controls the size of the specular highlight spot. In general, larger number produce a smaller specular highlight, which makes the object appear shinier. Smaller numbers produce a larger highlight, which makes the object appear less shiny.
This is usually in the range 0..128.
Setting a shininess value removes any previous roughness assignment.
Definition at line 122 of file material.h.
void Material::set_specular |
Specifies the specular color setting of the material.
This will be multiplied by any lights in effect on the material to compute the color of specular highlights on the object.
This is the highlight color of an object: the color of small highlight reflections.
If this is not set, the specular color is taken from the index of refraction, which is 1 by default (meaning no specular reflections are generated).
Definition at line 118 of file material.h.
|
inline |
Set this true to enable two-sided lighting.
When two-sided lighting is on, both sides of a polygon will be lit by this material. The default is for two-sided lighting to be off, in which case only the front surface is lit.
Definition at line 129 of file material.h.