![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUMaterial.h>
Public Member Functions | |
Material () | |
~Material () | |
void | dispose () |
bool | init () |
bool | initWithInfo (const std::shared_ptr< MaterialInfo > &info, bool texture=false) |
bool | initWithTexture (const std::shared_ptr< graphics::Texture > &texture) |
std::string | getName () const |
void | setName (std::string name) |
GLuint | getIllum () const |
void | setIllum (GLuint value) |
float | getShininess () const |
void | setShininess (float value) |
cugl::Color4f | getAmbientTint () const |
void | setAmbientTint (const cugl::Color4f value) |
cugl::Color4f | getDiffuseTint () const |
void | setDiffuseTint (const cugl::Color4f value) |
cugl::Color4f | getSpecularTint () const |
void | setSpecularTint (const cugl::Color4f value) |
std::shared_ptr< graphics::Texture > | getAmbientMap () const |
void | setAmbientMap (const std::shared_ptr< graphics::Texture > &value) |
std::shared_ptr< graphics::Texture > | getDiffuseMap () const |
void | setDiffuseMap (const std::shared_ptr< graphics::Texture > &value) |
std::shared_ptr< graphics::Texture > | getSpecularMap () const |
void | setSpecularMap (const std::shared_ptr< graphics::Texture > &value) |
std::shared_ptr< graphics::Texture > | getBumpMap () const |
void | setBumpMap (const std::shared_ptr< graphics::Texture > &value) |
void | bind (const std::shared_ptr< ObjShader > &shader) |
void | unbind () |
Static Public Member Functions | |
static std::shared_ptr< Material > | alloc () |
static std::shared_ptr< Material > | allocWithInfo (const std::shared_ptr< MaterialInfo > &info, bool texture=false) |
static std::shared_ptr< Material > | allocWithTexture (const std::shared_ptr< graphics::Texture > &texture) |
This class represents a WaveFront material
The MTL file itself is read into an MaterialLib
object using an ObjParser
. From that object, you can access the MaterialInfo
objects and use them to construct actual materials.
Our Material objects currently include support for illums 0-2 (using standard phong shading). We allow texture maps for ambient, diffuse, and specular color. However, the shininess value is only a scalar; we do not support texture maps for the specular exponent.
Colors are determined by multiplying the color coefficient with the appropriate texture. If a texture is missing, a solid color is used instead. The exception to this rule is ambient color. If there is no ambient texture, but there is a diffuse texture, then the ambient color is the ambient coefficient times the diffuse texture.
We do not support reflection, transparency, or emission. We also do not support dissolve effects or decals. If you need more complicated MTL support, you should use a third party rendering library.
With that said, this class does provide support for simple bump mapping. The bump texture should be an RGB image encoding the normals in tangent space.
|
inline |
Creates a degenerate material
Binding this material is guaranteed to create a white, featureless surface. For a more interesting material, you must initialize it using a MaterialInfo
object.
|
inline |
Deletes this material, disposing all resources
|
inlinestatic |
Returns a newly allocated simple material.
Binding this material is guaranteed to create a white, featureless surface. This initializer does not do much more than the constructor.
|
inlinestatic |
Returns a newly allocated material with the given AST information
This method will fill in the attributes using the information provided. If load is true, it will also load and allocate any of the specified textures. This value is false by default, as it is assumed the textures will be loaded separately and manually attached to the material. Textures must be in the same direct as the MTL file to be loaded automatically.
info | The material information |
texture | Whether to load and allocate the textures |
|
inlinestatic |
Returns a newly allocated material with a single texture.
This creates a trivial material that uses the given texture as the diffuse map (with a white light color). There will be no textures for the other maps, and all other lights will be clear.
texture | The diffuse texture for this material |
void cugl::scene3::Material::bind | ( | const std::shared_ptr< ObjShader > & | shader | ) |
Binds this material to the given shader, activating it.
This call is reentrant. If can be safely called multiple times.
void cugl::scene3::Material::dispose | ( | ) |
Disposes all of the resources used by this material.
A disposed Material can be safely reinitialized. Any textures owned by this material will be released. They will be deleted if no other object owns them.
|
inline |
Returns the texture map of the ambient light.
The ambient light is determined by multiplying this texture (if it exists) times the ambient color. No ambient texture produces a solid color. However, if the diffuse texture exists while the ambient texture does not, the ambient light will multiply this coefficient times that texture instead.
|
inline |
Returns the color coefficient of the ambient light.
The ambient light is determined by multiplying this color times the ambient texture (if it exists). No ambient texture produces a solid color. However, if the diffuse texture exists while the ambient texture does not, the ambient light will multiply this coefficient times that texture instead.
|
inline |
Returns the texture map of the fragment normals.
This texture specifies the per fragment normals for bump mapping. These normals are encoded as RGB values in tangent space (meaning the images typically appear blue). If this texture is not specified, the lighting normal will be interpolated from the vertex normals instead.
|
inline |
Returns the texture map of the diffuse light.
The diffuse light is determined by multiplying this texture (if it exists) times the diffuse color. No diffuse texture produces a solid color. This texture will also determine the ambient light if there is no separate texture for the ambient light.
|
inline |
Returns the color coefficient of the diffuse light.
The diffuse light is determined by multiplying this color times the diffuse texture (if it exists). No diffuse texture produces a solid color. The diffuse light is also affected by the direction of the light source.
|
inline |
Returns the illumination setting of this material.
We support illum values 0-2. In the MTL specification, these are defined as follows:
0: Color with no reflection (ambient only) 1: Diffuse reflection 2: Specular reflection
Colors are determined by multiplying the color coefficient with the appropriate texture. If a texture is missing, a solid color is used instead. The exception to this rule is ambient color. If there is no ambient texture, but there is a diffuse texture, then the ambient color is the ambient coefficient times the diffuse texture.
|
inline |
Returns the name of this material.
|
inline |
Returns the shininess coefficient.
This value defines the focus of the specular highlight as an exponent. A high exponent results in a tight, concentrated highlight. These values normally range from 0 to 1000.
|
inline |
Returns the texture map of the specular light.
The specular light is determined by multiplying this texture (if it exists) times the specular color. No specular texture produces a solid color. The specular light is also affected by the direction of the light source, as well as the shininess exponent.
|
inline |
Returns the color coefficient of the specular light.
The specular light is determined by multiplying this color times the specular texture (if it exists). No specular texture produces a solid color. The specular light is also affected by the direction of the light source, as well as the shininess exponent.
|
inline |
Initializes a simple material.
Binding this material is guaranteed to create a white, featureless surface. This initializer does not do much more than the constructor.
bool cugl::scene3::Material::initWithInfo | ( | const std::shared_ptr< MaterialInfo > & | info, |
bool | texture = false |
||
) |
Initializes a material with the given AST information
This method will fill in the attributes using the information provided. If load is true, it will also load and allocate any of the specified textures. This value is false by default, as it is assumed the textures will be loaded separately and manually attached to the material. Textures must be in the same direct as the MTL file to be loaded automatically.
info | The material information |
texture | Whether to load and allocate the textures |
bool cugl::scene3::Material::initWithTexture | ( | const std::shared_ptr< graphics::Texture > & | texture | ) |
Initializes a material with a single texture.
This creates a trivial material that uses the given texture as the diffuse map (with a white light color). There will be no textures for the other maps, and all other lights will be clear.
texture | The diffuse texture for this material |
void cugl::scene3::Material::setAmbientMap | ( | const std::shared_ptr< graphics::Texture > & | value | ) |
Sets the texture map of the ambient light.
The ambient light is determined by multiplying this texture (if it exists) times the ambient color. No ambient texture produces a solid color. However, if the diffuse texture exists while the ambient texture does not, the ambient light will multiply this coefficient times that texture instead.
value | The texture map of the ambient light. |
|
inline |
Sets the color coefficient of the ambient light.
The ambient light is determined by multiplying this color times the ambient texture (if it exists). No ambient texture produces a solid color. However, if the diffuse texture exists while the ambient texture does not, the ambient light will multiply this coefficient times that texture instead.
value | The color coefficient of the ambient light. |
void cugl::scene3::Material::setBumpMap | ( | const std::shared_ptr< graphics::Texture > & | value | ) |
Sets the texture map of the fragment normals.
This texture specifies the per fragment normals for bump mapping. These normals are encoded as RGB values in tangent space (meaning the images typically appear blue). If this texture is not specified, the lighting normal will be interpolated from the vertex normals instead.
value | The texture map of the fragment normals. |
void cugl::scene3::Material::setDiffuseMap | ( | const std::shared_ptr< graphics::Texture > & | value | ) |
Sets the texture map of the diffuse light.
The diffuse light is determined by multiplying this texture (if it exists) times the diffuse color. No diffuse texture produces a solid color. This texture will also determine the ambient light if there is no separate texture for the ambient light.
value | The texture map of the diffuse light. |
|
inline |
Sets the color coefficient of the diffuse light.
The diffuse light is determined by multiplying this color times the diffuse texture (if it exists). No diffuse texture produces a solid color. The diffuse light is also affected by the direction of the light source.
value | The color coefficient of the diffuse light. |
void cugl::scene3::Material::setIllum | ( | GLuint | value | ) |
Sets the illumination setting of this material.
We support illum values 0-2. In the MTL specification, these are defined as follows:
0: Color with no reflection (ambient only) 1: Diffuse reflection 2: Specular reflection
Colors are determined by multiplying the color coefficient with the appropriate texture. If a texture is missing, a solid color is used instead. The exception to this rule is ambient color. If there is no ambient texture, but there is a diffuse texture, then the ambient color is the ambient coefficient times the diffuse texture.
value | The illumination setting of this material |
|
inline |
Sets the name of this material.
name | the name of this material. |
void cugl::scene3::Material::setShininess | ( | float | value | ) |
Sets the shininess coefficient.
This value defines the focus of the specular highlight as an exponent. A high exponent results in a tight, concentrated highlight. These values normally range from 0 to 1000.
value | The shininess coefficient. |
void cugl::scene3::Material::setSpecularMap | ( | const std::shared_ptr< graphics::Texture > & | value | ) |
Sets the texture map of the specular light.
The specular light is determined by multiplying this texture (if it exists) times the specular color. No specular texture produces a solid color. The specular light is also affected by the direction of the light source, as well as the shininess exponent.
value | The texture map of the specular light. |
|
inline |
Sets the color coefficient of the specular light.
The specular light is determined by multiplying this color times the specular texture (if it exists). No specular texture produces a solid color. The specular light is also affected by the direction of the light source, as well as the shininess exponent.
value | The color coefficient of the specular light. |
void cugl::scene3::Material::unbind | ( | ) |
Unbinds the material, making it inactive.
This call is reentrant. If can be safely called multiple times.