1 #ifndef MSP_GL_MATERIAL_H_
2 #define MSP_GL_MATERIAL_H_
4 #include <msp/datafile/objectloader.h>
7 #include "programdata.h"
13 Stores basic material properties. This includes color and reflection
14 parameters, but does not include texturing. Materials interact with light
15 soucres and ambient lighting to produce the base color of a surface. Textures
16 can be used to add detail.
18 Material provides a set of uniform variables for use with shaders. Standard
19 shaders generated by ProgramBuilder only use it when legacy mode is disabled.
21 In legacy mode, materials are applied with several calls to glMaterial.
23 class Material: public BindableWithDefault<Material>
26 class Loader: public DataFile::CollectionObjectLoader<Material>
33 Loader(Material &, Collection &);
37 Color make_color(float, float, float, float);
38 void ambient(float, float, float, float);
39 void diffuse(float, float, float, float);
40 void specular(float, float, float, float);
41 void emission(float, float, float, float);
42 void shininess(float);
43 void reflectivity(float);
68 void update_parameter(int) const;
71 /** Sets the ambient color of the material. Provided to shaders with the
72 name material.ambient. */
73 void set_ambient(const Color &);
75 /** Sets the diffuse (direction-independent) color of the material.
76 Provided to shaders with the name material.diffuse. */
77 void set_diffuse(const Color &);
79 /** Sets the specular (direction-dependent) color of the material. Provided
80 to shaders with the name material.specular. */
81 void set_specular(const Color &);
82 void set_emission(const Color &);
84 /** Sets the specular exponent of the material. Provided to shaders with
85 the name material.shininess. */
86 void set_shininess(float);
88 /** Sets the reflectivity of the material. Provided to shaders with the
89 name reflectivity. Has no effect when shaders are not used. */
90 void set_reflectivity(float);
92 const Color &get_ambient() const { return ambient; }
93 const Color &get_diffuse() const { return diffuse; }
94 const Color &get_specular() const { return specular; }
95 const Color &get_emission() const { return emission; }
96 float get_shininess() const { return shininess; }
97 float get_reflectivity() const { return reflectivity; }
99 /** Returns the uniforms for the material. Not needed for shaders that use
100 the legacy built-in uniform gl_FrontMaterial and have no reflections. */
101 const ProgramData &get_shader_data() const { return shdata; }