18 Material(
const std::string &name) :
Namable(name) {
19 _base_color.set(1.0f, 1.0f, 1.0f, 1.0f);
20 _ambient.set(1.0f, 1.0f, 1.0f, 1.0f);
21 _diffuse.set(1.0f, 1.0f, 1.0f, 1.0f);
22 _specular.set(0.0f, 0.0f, 0.0f, 1.0f);
23 _emission.set(0.0f, 0.0f, 0.0f, 1.0f);
27 _refractive_index = 1;
37 _base_color(copy._base_color),
38 _ambient(copy._ambient),
39 _diffuse(copy._diffuse),
40 _specular(copy._specular),
41 _emission(copy._emission),
42 _shininess(copy._shininess),
43 _roughness(copy._roughness),
44 _metallic(copy._metallic),
45 _refractive_index(copy._refractive_index),
46 _flags(copy._flags & ~(F_attrib_lock | F_used_by_auto_shader)) {
71 INLINE
bool Material::
72 has_base_color()
const {
73 return (_flags & F_base_color) != 0;
80 INLINE
const LColor &Material::
81 get_base_color()
const {
93 INLINE
bool Material::
95 return (_flags & F_ambient) != 0;
102 INLINE
const LColor &Material::
103 get_ambient()
const {
110 INLINE
void Material::
113 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
115 _flags &= ~F_ambient;
116 _ambient = _base_color;
123 INLINE
bool Material::
124 has_diffuse()
const {
125 return (_flags & F_diffuse) != 0;
132 INLINE
const LColor &Material::
133 get_diffuse()
const {
140 INLINE
void Material::
143 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
145 _flags &= ~F_diffuse;
146 _diffuse = _base_color * (1 - _metallic);
153 INLINE
bool Material::
154 has_specular()
const {
155 return (_flags & F_specular) != 0;
162 INLINE
const LColor &Material::
163 get_specular()
const {
171 INLINE
bool Material::
172 has_emission()
const {
173 return (_flags & F_emission) != 0;
180 INLINE
const LColor &Material::
181 get_emission()
const {
188 INLINE
void Material::
191 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
193 _flags &= ~F_emission;
194 _emission.set(0.0f, 0.0f, 0.0f, 0.0f);
200 INLINE PN_stdfloat Material::
201 get_shininess()
const {
211 return (_flags & F_roughness) != 0;
220 return (_flags & F_metallic) != 0;
227 INLINE PN_stdfloat Material::
228 get_metallic()
const {
238 return (_flags & F_refractive_index) != 0;
245 INLINE PN_stdfloat Material::
246 get_refractive_index()
const {
247 return _refractive_index;
253 INLINE
bool Material::
255 return (_flags & F_local) != 0;
266 if (is_used_by_auto_shader() &&
get_local() != local) {
267 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
279 INLINE
bool Material::
280 get_twoside()
const {
281 return (_flags & F_twoside) != 0;
291 if (is_used_by_auto_shader() &&
get_twoside() != twoside) {
292 GraphicsStateGuardianBase::mark_rehash_generated_shaders();
297 _flags &= ~F_twoside;
304 INLINE
bool Material::
305 operator == (
const Material &other)
const {
312 INLINE
bool Material::
313 operator != (
const Material &other)
const {
320 INLINE
bool Material::
321 operator < (
const Material &other)
const {
330 return (_flags & F_attrib_lock) != 0;
338 _flags |= F_attrib_lock;
344 INLINE
bool Material::
345 is_used_by_auto_shader()
const {
346 return (_flags & F_attrib_lock) != 0;
355 _flags |= F_used_by_auto_shader;
361 INLINE
int Material::
364 return _flags & ~F_used_by_auto_shader;
has_ambient
Returns true if the ambient color has been explicitly set for this material, false otherwise.
bool has_metallic() const
Returns true if the metallic has been explicitly set for this material, false otherwise.
get_twoside
Returns the state of the two-sided lighting flag.
set_twoside
Set this true to enable two-sided lighting.
static Material * get_default()
Returns the default material.
get_local
Returns the local viewer flag.
has_base_color
Returns true if the base color has been explicitly set for this material, false otherwise.
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 ...
A base class for all things which can have a name.
bool has_roughness() const
Returns true if the roughness has been explicitly set for this material, false otherwise.
set_local
Sets the local viewer flag.
bool is_attrib_locked() const
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 mark_used_by_auto_shader()
Called by the shader generator to indicate that a shader has been generated that uses this material.
has_emission
Returns true if the emission color has been explicitly set for this material, false otherwise.