CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cugl::scene3::Material Class Reference

#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::TexturegetAmbientMap () const
 
void setAmbientMap (const std::shared_ptr< graphics::Texture > &value)
 
std::shared_ptr< graphics::TexturegetDiffuseMap () const
 
void setDiffuseMap (const std::shared_ptr< graphics::Texture > &value)
 
std::shared_ptr< graphics::TexturegetSpecularMap () const
 
void setSpecularMap (const std::shared_ptr< graphics::Texture > &value)
 
std::shared_ptr< graphics::TexturegetBumpMap () 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< Materialalloc ()
 
static std::shared_ptr< MaterialallocWithInfo (const std::shared_ptr< MaterialInfo > &info, bool texture=false)
 
static std::shared_ptr< MaterialallocWithTexture (const std::shared_ptr< graphics::Texture > &texture)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Material()

cugl::scene3::Material::Material ( )
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.

◆ ~Material()

cugl::scene3::Material::~Material ( )
inline

Deletes this material, disposing all resources

Member Function Documentation

◆ alloc()

static std::shared_ptr< Material > cugl::scene3::Material::alloc ( )
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.

Returns
a newly allocated simple material.

◆ allocWithInfo()

static std::shared_ptr< Material > cugl::scene3::Material::allocWithInfo ( const std::shared_ptr< MaterialInfo > &  info,
bool  texture = false 
)
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.

Parameters
infoThe material information
textureWhether to load and allocate the textures
Returns
a newly allocated material with the given AST information

◆ allocWithTexture()

static std::shared_ptr< Material > cugl::scene3::Material::allocWithTexture ( const std::shared_ptr< graphics::Texture > &  texture)
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.

Parameters
textureThe diffuse texture for this material
Returns
a newly allocated material with a single texture.

◆ bind()

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.

◆ dispose()

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.

◆ getAmbientMap()

std::shared_ptr< graphics::Texture > cugl::scene3::Material::getAmbientMap ( ) const
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.

Returns
the texture map of the ambient light.

◆ getAmbientTint()

cugl::Color4f cugl::scene3::Material::getAmbientTint ( ) const
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.

Returns
the color coefficient of the ambient light.

◆ getBumpMap()

std::shared_ptr< graphics::Texture > cugl::scene3::Material::getBumpMap ( ) const
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.

Returns
the texture map of the fragment normals.

◆ getDiffuseMap()

std::shared_ptr< graphics::Texture > cugl::scene3::Material::getDiffuseMap ( ) const
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.

Returns
the texture map of the diffuse light.

◆ getDiffuseTint()

cugl::Color4f cugl::scene3::Material::getDiffuseTint ( ) const
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.

Returns
the color coefficient of the diffuse light.

◆ getIllum()

GLuint cugl::scene3::Material::getIllum ( ) const
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.

Returns
the illumination setting of this material.

◆ getName()

std::string cugl::scene3::Material::getName ( ) const
inline

Returns the name of this material.

Returns
the name of this material.

◆ getShininess()

float cugl::scene3::Material::getShininess ( ) const
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.

Returns
the shininess coefficient.

◆ getSpecularMap()

std::shared_ptr< graphics::Texture > cugl::scene3::Material::getSpecularMap ( ) const
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.

Returns
the texture map of the specular light.

◆ getSpecularTint()

cugl::Color4f cugl::scene3::Material::getSpecularTint ( ) const
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.

Returns
the color coefficient of the specular light.

◆ init()

bool cugl::scene3::Material::init ( )
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.

Returns
true if initialization was successful.

◆ initWithInfo()

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.

Parameters
infoThe material information
textureWhether to load and allocate the textures
Returns
true if initialization was successful.

◆ initWithTexture()

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.

Parameters
textureThe diffuse texture for this material
Returns
true if initialization was successful.

◆ setAmbientMap()

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.

Parameters
valueThe texture map of the ambient light.

◆ setAmbientTint()

void cugl::scene3::Material::setAmbientTint ( const cugl::Color4f  value)
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.

Parameters
valueThe color coefficient of the ambient light.

◆ setBumpMap()

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.

Parameters
valueThe texture map of the fragment normals.

◆ setDiffuseMap()

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.

Parameters
valueThe texture map of the diffuse light.

◆ setDiffuseTint()

void cugl::scene3::Material::setDiffuseTint ( const cugl::Color4f  value)
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.

Parameters
valueThe color coefficient of the diffuse light.

◆ setIllum()

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.

Parameters
valueThe illumination setting of this material

◆ setName()

void cugl::scene3::Material::setName ( std::string  name)
inline

Sets the name of this material.

Parameters
namethe name of this material.

◆ setShininess()

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.

Parameters
valueThe shininess coefficient.

◆ setSpecularMap()

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.

Parameters
valueThe texture map of the specular light.

◆ setSpecularTint()

void cugl::scene3::Material::setSpecularTint ( const cugl::Color4f  value)
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.

Parameters
valueThe color coefficient of the specular light.

◆ unbind()

void cugl::scene3::Material::unbind ( )

Unbinds the material, making it inactive.

This call is reentrant. If can be safely called multiple times.


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