Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Material Class Reference

Defines the way an object appears in the presence of lighting. More...

#include "material.h"

Inheritance diagram for Material:
TypedWritableReferenceCount Namable TypedWritable ReferenceCount MemoryBase TypedObject MemoryBase MemoryBase

Public Types

enum  Flags {
  F_ambient = 0x001, F_diffuse = 0x002, F_specular = 0x004, F_emission = 0x008,
  F_local = 0x010, F_twoside = 0x020, F_attrib_lock = 0x040, F_roughness = 0x080,
  F_metallic = 0x100, F_base_color = 0x200, F_refractive_index = 0x400, F_used_by_auto_shader = 0x800
}
 

Public Member Functions

 Material (const std::string &name="")
 
 Material (const Material &copy)
 
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 &copy)
 
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 &copy)
 
virtual ReferenceCountas_reference_count ()
 Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type. More...
 
void operator= (const TypedWritableReferenceCount &copy)
 
- Public Member Functions inherited from TypedWritable
 TypedWritable (const TypedWritable &copy)
 
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 &copy)
 
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 &copy)=default
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_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...
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
WeakReferenceListget_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...
 
WeakReferenceListweak_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 Materialget_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 BamReaderreader = 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
 

Detailed Description

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.

Member Function Documentation

◆ clear_metallic()

void Material::clear_metallic ( )

Removes the explicit metallic setting from the material.

Definition at line 297 of file material.cxx.

◆ compare_to()

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.

◆ get_default()

Material * Material::get_default ( )
inlinestatic

Returns the default material.

Definition at line 60 of file material.I.

◆ has_metallic()

bool Material::has_metallic ( ) const
inline

Returns true if the metallic has been explicitly set for this material, false otherwise.

Definition at line 219 of file material.I.

◆ has_refractive_index()

bool Material::has_refractive_index ( ) const
inline

Returns true if a refractive index has explicitly been specified for this material.

Definition at line 237 of file material.I.

◆ has_roughness()

bool Material::has_roughness ( ) const
inline

Returns true if the roughness has been explicitly set for this material, false otherwise.

Definition at line 210 of file material.I.

◆ is_attrib_locked()

bool Material::is_attrib_locked ( ) const
inline

Definition at line 329 of file material.I.

◆ mark_used_by_auto_shader()

void Material::mark_used_by_auto_shader ( )
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.

◆ register_with_read_factory()

void Material::register_with_read_factory ( )
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().

◆ set_attrib_lock()

void Material::set_attrib_lock ( )
inline

Definition at line 337 of file material.I.

Referenced by CPT().

◆ write_datagram()

void Material::write_datagram ( BamWriter manager,
Datagram me 
)
virtual

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().

Member Data Documentation

◆ clear_ambient

void Material::clear_ambient
inline

Removes the explicit ambient color from the material.

Definition at line 114 of file material.h.

◆ clear_base_color

void Material::clear_base_color

Removes the explicit base_color color from the material.

Definition at line 112 of file material.h.

◆ clear_diffuse

void Material::clear_diffuse
inline

Removes the explicit diffuse color from the material.

Definition at line 116 of file material.h.

◆ clear_emission

void Material::clear_emission
inline

Removes the explicit emission color from the material.

Definition at line 120 of file material.h.

◆ clear_specular

void Material::clear_specular

Removes the explicit specular color from the material.

Definition at line 118 of file material.h.

◆ get_ambient

const LColor & Material::get_ambient
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().

◆ get_base_color

const LColor & Material::get_base_color
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().

◆ get_diffuse

const LColor & Material::get_diffuse
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().

◆ get_emission

const LColor & Material::get_emission
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().

◆ get_local

bool Material::get_local
inline

Returns the local viewer flag.

Set set_local().

Definition at line 128 of file material.h.

◆ get_metallic

PN_stdfloat Material::get_metallic
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().

◆ get_refractive_index

PN_stdfloat Material::get_refractive_index
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().

◆ get_roughness

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.

◆ get_shininess

PN_stdfloat Material::get_shininess
inline

Returns the shininess exponent of the material.

Definition at line 122 of file material.h.

Referenced by compare_to().

◆ get_specular

const LColor & Material::get_specular
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().

◆ get_twoside

bool Material::get_twoside
inline

Returns the state of the two-sided lighting flag.

See set_twoside().

Definition at line 129 of file material.h.

◆ has_ambient

bool Material::has_ambient
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().

◆ has_base_color

bool Material::has_base_color
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().

◆ has_diffuse

bool Material::has_diffuse
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().

◆ has_emission

bool Material::has_emission
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().

◆ has_specular

bool Material::has_specular
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().

◆ set_ambient

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.

◆ set_base_color

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.

◆ set_diffuse

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.

◆ set_emission

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.

◆ set_local

void Material::set_local
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.

◆ set_metallic

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.

◆ set_refractive_index

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.

◆ set_roughness

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.

◆ set_shininess

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.

◆ set_specular

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.

◆ set_twoside

void Material::set_twoside
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.


The documentation for this class was generated from the following files: