Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
jop::Material Class Referencefinal

#include <Material.hpp>

Inheritance diagram for jop::Material:
jop::Resource jop::SafeReferenceable< Resource > jop::SerializeInfo

Public Types

enum  LightingModel : uint64 {
  LightingModel::None = 0ull, LightingModel::Gouraud = 1ull << 63, LightingModel::Flat = Gouraud | Gouraud >> 1, LightingModel::Phong = Gouraud >> 2,
  LightingModel::BlinnPhong = Phong | Phong >> 1, LightingModel::Default
}
 
enum  Reflection { Reflection::Ambient, Reflection::Diffuse, Reflection::Specular, Reflection::Emission }
 
enum  Map : uint64 {
  Map::Diffuse0, Map::Specular, Map::Emission, Map::Environment,
  Map::Reflection, Map::Opacity, Map::Gloss, Map::__Last
}
 

Public Member Functions

 JOP_DISALLOW_COPY_MOVE (Material)
 
 Material (const Material &other, const std::string &newName)
 
 Material (const std::string &name)
 Constructor. More...
 
void sendToShader (ShaderProgram &shader) const
 Send this material to a shader. More...
 
MaterialsetLightingModel (const LightingModel model)
 Set the lighting model. More...
 
LightingModel getLightingModel () const
 Get the lighting model. More...
 
MaterialsetReflection (const Reflection reflection, const Color &color)
 Set a reflection value. More...
 
MaterialsetReflection (const Color &ambient, const Color &diffuse, const Color &specular, const Color &emission)
 Set the reflection values. More...
 
const ColorgetReflection (const Reflection reflection) const
 Get a reflection value. More...
 
MaterialsetShininess (const float value)
 Set the shininess value. More...
 
float getShininess () const
 Get the shininess value. More...
 
MaterialsetReflectivity (const float reflectivity)
 Set the reflectivity. More...
 
float getReflectivity () const
 Get the reflectivity value. More...
 
MaterialsetMap (const Map map, const Texture &tex)
 Set a map. More...
 
MaterialremoveMap (const Map map)
 Remove a map. More...
 
const TexturegetMap (const Map map) const
 Get a map. More...
 
bool hasAlpha () const
 Check if this material has potential transparency. More...
 
ShaderProgramgetShader () const
 Get the shader for this material. More...
 
uint64 getAttributes () const
 Get the internal attribute field. More...
 
- Public Member Functions inherited from jop::Resource
 Resource (const std::string &name)
 Constructor. More...
 
virtual ~Resource ()=0
 Virtual destructor. More...
 
const std::string & getName () const
 Get the name of this resource. More...
 
void setPersistence (const unsigned short level)
 Set the persistence level. More...
 
unsigned short getPersistence () const
 Get the persistence level. More...
 
- Public Member Functions inherited from jop::SafeReferenceable< Resource >
WeakReference< ResourcegetReference () const
 Get a weak reference to the bound object. More...
 
- Public Member Functions inherited from jop::SerializeInfo
 SerializeInfo ()
 
void setSerializePackage (const uint16 package)
 
uint16 getSerializePackage () const
 
void setShouldSerialize (const bool set)
 
bool shouldSerialize () const
 
void setLightSerializeable (const bool set)
 
bool isLightSerializeable () const
 

Static Public Member Functions

static MaterialgetDefault ()
 Get the default material. More...
 

Static Public Attributes

static const uint64 LightingAttribs
 

Friends

class ShaderAssembler
 

Additional Inherited Members

- Protected Member Functions inherited from jop::Resource
 Resource (const Resource &other, const std::string &newName)
 Copy constructor. More...
 
- Protected Member Functions inherited from jop::SafeReferenceable< Resource >
 SafeReferenceable (Resource *ref)
 Constructor. More...
 
 SafeReferenceable (SafeReferenceable< Resource > &&other)
 Move constructor. More...
 
SafeReferenceableoperator= (SafeReferenceable< Resource > &&other)
 Move assignment operator. More...
 
 ~SafeReferenceable ()
 Protected destructor. More...
 

Detailed Description

Definition at line 40 of file Material.hpp.

Member Enumeration Documentation

Enumerator
None 

No lighting.

Gouraud 

Vertex-base lighting. Lighting is calculated for each vertex before interpolating it for each pixel.

This model is much faster on GPU's where pixel fill rate is the bottleneck.

This model is the default for mobile.

Flat 

Flat lighting, disables normal interpolation between vertices, which results in a single polygon having a uniform color.

Warning
Not available on GLES 2.0, Gouraud model will be used instead
Phong 

Fragment-based phong lighting model. The lighting value is calculated for each pixel individually.

This is the most expensive lighting model, and thus is not recommended to be used in mobile environments.

See also
Gouraud
BlinnPhong 

Slightly modified version of Phong. This uses a half-way normal reflection vector to calculate the specular highlight, which makes it slightly stronger.

This model is marginally faster than Phong.

This model is the default for desktop.

Default 

Default lighting mode

        Gouraud on GLES, BlinnPhong elsewhere.

Definition at line 52 of file Material.hpp.

enum jop::Material::Map : uint64
strong

The map attribute

Enumerator
Diffuse0 

Essentially the "base" texture for an object.

Specular 

The specular highlight value will be multiplied by this texture's value.

Emission 

The value of this texture will be added to the final fragment value, after multiplication with the emissive reflection value

Environment 

Cube map to be used as an environment reflection.

Reflection 

To be used with an environment map. The value of this texture will be multiplied with that of the environment map

Opacity 

8-bit alpha map. The opacity of each fragment will be multiplied by this texture's value

Gloss 

The value of this map will be multiplied with the shininess value

        Not available when using vertex-based lighting models.
__Last 

For internal use. Never use this.

Definition at line 127 of file Material.hpp.

The reflection attribute

Note
These will only affect rendering when lighting is enabled.
Enumerator
Ambient 

Ambient light reflection, unaffected by object orientation or shadows.

Diffuse 

Diffuse reflection.

Specular 

Specular reflection.

Emission 

Emissive reflection, which is simply added to the base light value.

Definition at line 117 of file Material.hpp.

Constructor & Destructor Documentation

jop::Material::Material ( const Material other,
const std::string &  newName 
)
jop::Material::Material ( const std::string &  name)

Constructor.

Parameters
nameName of the resource. This must be the file path if this resource is loaded from a file.

By default the material defines no functionality (only Drawable's color will be used in rendering).

Member Function Documentation

uint64 jop::Material::getAttributes ( ) const

Get the internal attribute field.

This is for internal use only.

Returns
The attribute field
static Material& jop::Material::getDefault ( )
static

Get the default material.

The default material has no attributes, meaning only the Drawable color will be used.

Returns
Reference to the default material
LightingModel jop::Material::getLightingModel ( ) const

Get the lighting model.

Returns
The lighting model
const Texture* jop::Material::getMap ( const Map  map) const

Get a map.

Parameters
mapThe map enum
Returns
Pointer to the texture. nullptr if none bound
const Color& jop::Material::getReflection ( const Reflection  reflection) const

Get a reflection value.

Parameters
reflectionThe reflection attribute
Returns
The reflection value
float jop::Material::getReflectivity ( ) const

Get the reflectivity value.

Returns
The reflectivity value
ShaderProgram& jop::Material::getShader ( ) const

Get the shader for this material.

Returns
Reference to the shader
float jop::Material::getShininess ( ) const

Get the shininess value.

Returns
The shininess value
bool jop::Material::hasAlpha ( ) const

Check if this material has potential transparency.

Returns
True if this material has potential transparency
jop::Material::JOP_DISALLOW_COPY_MOVE ( Material  )
Material& jop::Material::removeMap ( const Map  map)

Remove a map.

Parameters
mapThe map to remove
Returns
Reference to self
void jop::Material::sendToShader ( ShaderProgram shader) const

Send this material to a shader.

Parameters
shaderReference to the shader to send this material to
Material& jop::Material::setLightingModel ( const LightingModel  model)

Set the lighting model.

Parameters
modelThe lighting model to set
Returns
Reference to self
Material& jop::Material::setMap ( const Map  map,
const Texture tex 
)

Set a map.

Parameters
mapThe map enum
texReference to the texture
Returns
Reference to self
Material& jop::Material::setReflection ( const Reflection  reflection,
const Color color 
)

Set a reflection value.

Parameters
reflectionThe reflection attribute
colorThe reflection color
Returns
Reference to self
Material& jop::Material::setReflection ( const Color ambient,
const Color diffuse,
const Color specular,
const Color emission 
)

Set the reflection values.

Parameters
ambientThe ambient reflection
diffuseThe diffuse reflection
specularThe specular reflection
emissionThe emission value
Returns
Reference to self
Material& jop::Material::setReflectivity ( const float  reflectivity)

Set the reflectivity.

Do not confuse this with reflection. What this defines is how strongly an environment map is reflected. 0 means there's no reflection and 1 makes the surface mirror-like. This attribute has no effect if there's no environment map

Parameters
reflectivityThe reflectivity value
Returns
Reference to self
Material& jop::Material::setShininess ( const float  value)

Set the shininess value.

Parameters
valueThe shininess value
Returns
Reference to self

Friends And Related Function Documentation

friend class ShaderAssembler
friend

Definition at line 48 of file Material.hpp.

Member Data Documentation

const uint64 jop::Material::LightingAttribs
static

All the lighting model attributes combined

For internal use only.

Definition at line 164 of file Material.hpp.


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