SLProject 4.0.000
|
Defines a standard CG material with textures and a shader program. More...
#include <SLMaterial.h>
Public Member Functions | |
SLMaterial (SLAssetManager *am, const SLchar *name, const SLCol4f &amdi=SLCol4f::WHITE, const SLCol4f &spec=SLCol4f::WHITE, SLfloat shininess=100.0f, SLfloat kr=0.0, SLfloat kt=0.0f, SLfloat kn=1.0f, SLGLProgram *program=nullptr) | |
Default ctor for Blinn-Phong reflection model materials without textures. More... | |
SLMaterial (SLAssetManager *am, const SLchar *name, SLGLTexture *texture1, SLGLTexture *texture2=nullptr, SLGLTexture *texture3=nullptr, SLGLTexture *texture4=nullptr, SLGLProgram *program=nullptr) | |
Ctor for textured Blinn-Phong reflection model materials. More... | |
SLMaterial (SLAssetManager *am, const SLchar *name, SLSkybox *skybox, SLCol4f diffuse, SLfloat roughness, SLfloat metalness, SLGLProgram *program=nullptr) | |
Ctor for PBR material with Cook-Torrance material parameters. More... | |
SLMaterial (SLAssetManager *am, const SLchar *name, SLSkybox *skybox, SLGLTexture *texture1, SLGLTexture *texture2=nullptr, SLGLTexture *texture3=nullptr, SLGLTexture *texture4=nullptr, SLGLTexture *texture5=nullptr, SLGLProgram *program=nullptr) | |
Ctor for PBR material with Cook-Torrance material textures. More... | |
SLMaterial (SLAssetManager *am, const SLchar *name, SLParticleSystem *ps, SLGLTexture *texture, SLGLProgram *program=nullptr, SLGLProgram *programTF=nullptr) | |
Ctor for Particle System material with one texture (Draw and update) More... | |
SLMaterial (SLAssetManager *am, SLGLProgram *colorUniformProgram, const SLCol4f &uniformColor, const SLchar *name=(const char *)"Uniform color") | |
Ctor for uniform color material without lighting. More... | |
SLMaterial (SLAssetManager *am, const SLchar *name, SLGLProgram *program) | |
Ctor for only a program. More... | |
~SLMaterial () override | |
void | generateProgramPS () |
void | activate (SLCamera *cam, SLVLight *lights, SLSkybox *skybox=nullptr) |
SLint | passToUniforms (SLGLProgram *program, SLint nextTexUnit) |
Passes all material parameters as uniforms to the passed shader program. More... | |
SLbool | hasAlpha () |
Returns true if there is any transparency in diffuse alpha or textures. More... | |
SLbool | has3DTexture () |
Returns true if a material has a 3D texture. More... | |
SLbool | usesUVIndex (SLbyte uvIndex) |
Returns true if the specified uvIndex is used by one of the textures. More... | |
SLbool | needsTangents () |
SLbool | hasTextureType (SLTextureType tt) |
SLbool | hasTextureTypeWithUVIndex (SLTextureType tt, SLuint texIndex, SLbyte uvIndex) |
void | removeTextureType (SLTextureType tt) |
void | addTexture (SLGLTexture *texture) |
Adds the passed texture to the equivalent texture type vector. More... | |
SLstring | texturesString () |
Returns a unique string that represent all textures used. More... | |
void | assetManager (SLAssetManager *am) |
void | reflectionModel (SLReflectionModel rm) |
void | ambient (const SLCol4f &ambi) |
void | diffuse (const SLCol4f &diff) |
void | ambientDiffuse (const SLCol4f &am_di) |
void | specular (const SLCol4f &spec) |
void | emissive (const SLCol4f &emis) |
void | transmissive (const SLCol4f &transm) |
void | translucency (SLfloat transl) |
void | shininess (SLfloat shin) |
void | roughness (SLfloat r) |
void | metalness (SLfloat m) |
void | kr (SLfloat kr) |
void | kt (SLfloat kt) |
void | kn (SLfloat kn) |
void | getsShadows (SLbool receivesShadows) |
void | program (SLGLProgram *sp) |
void | programTF (SLGLProgram *sp) |
void | skybox (SLSkybox *sb) |
void | ps (SLParticleSystem *ps) |
SLAssetManager * | assetManager () |
SLReflectionModel | reflectionModel () |
SLCol4f | ambient () |
SLCol4f | diffuse () |
SLCol4f | specular () |
SLCol4f | emissive () |
SLfloat | shininess () const |
SLfloat | roughness () const |
SLfloat | metalness () const |
SLCol4f | transmissive () |
SLfloat | translucency () const |
SLfloat | kr () const |
SLfloat | kt () const |
SLfloat | kn () const |
SLbool | getsShadows () const |
SLuint | numTextures () |
SLGLProgram * | program () |
SLGLProgram * | programTF () |
SLSkybox * | skybox () |
SLParticleSystem * | ps () |
SLVNode & | nodesVisible2D () |
SLVNode & | nodesVisible3D () |
SLVGLTexture & | textures (SLTextureType type) |
SLVGLTexture & | textures3d () |
Public Member Functions inherited from SLObject | |
SLObject (const SLstring &Name="", const SLstring &url="") | |
virtual | ~SLObject () |
void | name (const SLstring &Name) |
void | url (const SLstring &url) |
const SLstring & | name () const |
const SLstring & | url () const |
Static Public Attributes | |
static SLfloat | K |
PM: Constant of gloss calibration (slope of point light at dist 1) More... | |
static SLfloat | PERFECT = 1000.0f |
PM: shininess/translucency limit. More... | |
Protected Attributes | |
SLAssetManager * | _assetManager |
pointer to the asset manager (the owner) if available More... | |
SLReflectionModel | _reflectionModel |
reflection model (RM_BlinnPhong or RM_CookTorrance) More... | |
SLCol4f | _ambient |
ambient color (RGB reflection coefficients) More... | |
SLCol4f | _diffuse |
diffuse color (RGB reflection coefficients) More... | |
SLCol4f | _specular |
specular color (RGB reflection coefficients) More... | |
SLCol4f | _emissive |
emissive color coefficients More... | |
SLfloat | _shininess |
shininess exponent in Blinn-Phong model More... | |
SLfloat | _roughness |
roughness property (0-1) in Cook-Torrance model More... | |
SLfloat | _metalness |
metallic property (0-1) in Cook-Torrance model More... | |
SLCol4f | _transmissive |
transmissive color (RGB reflection coefficients) for path tracing More... | |
SLfloat | _translucency |
translucency exponent for light refraction for path tracing More... | |
SLfloat | _kr {} |
reflection coefficient 0.0 - 1.0 used for ray and path tracing More... | |
SLfloat | _kt {} |
transmission coefficient 0.0 - 1.0 used for ray and path tracing More... | |
SLfloat | _kn {} |
refraction index More... | |
SLbool | _getsShadows |
true if shadows are visible on this material More... | |
SLGLProgram * | _program {} |
pointer to a GLSL shader program More... | |
SLGLProgram * | _programTF {} |
pointer to a GLSL shader program for transformFeedback More... | |
SLint | _numTextures |
number of textures in all _textures vectors array More... | |
SLSkybox * | _skybox |
pointer to the skybox More... | |
SLParticleSystem * | _ps |
pointer to a particle system More... | |
SLVGLTexture | _textures [TT_numTextureType] |
array of texture vectors one for each type More... | |
SLVGLTexture | _textures3d |
texture vector for diffuse 3D textures More... | |
SLGLTexture * | _errorTexture = nullptr |
pointer to error texture that is shown if another texture fails More... | |
SLstring | _compileErrorTexFilePath |
path to the error texture More... | |
SLVNode | _nodesVisible2D |
Vector of all visible 2D nodes of with this material. More... | |
SLVNode | _nodesVisible3D |
Vector of all visible 3D nodes of with this material. More... | |
Protected Attributes inherited from SLObject | |
SLstring | _name |
name of an object More... | |
SLstring | _url |
uniform resource locator More... | |
Defines a standard CG material with textures and a shader program.
The SLMaterial class defines a material with either the Blinn-Phong (default) or the Cook-Torrance reflection) model.
In the Blinn-Phong reflection model the following parameters get used:
The ambient, diffuse, specular and emissive color as well as the shininess parameter as shininess exponent. Instead of the diffuse color a texture of type TT_diffuse can be used.
In the Cook-Torrance reflection model only the diffuse color and the roughness and metallic parameter are used. All parameters can be provided also as a texture of the appropriate type. This reflection model corresponds to the Physically Based Rendering (PBR) material model.
In addition it has coefficients for reflectivity (kr), transparency (kt) and refraction index (kn) that can be used in special shaders and ray tracing.
A material has an array of empty vectors of SLGLTexture pointers. One for each SLTextureType.
The shading has to be implemented in the GLSL program (SLGLProgram) with a vertex and fragment shader. If no SLGLProgram is assigned, a pair of shaders (a vertex and fragment shader) gets automatically generated according to the reflection model and the material parameters. See SLGLProgramGenerated for more details.
|
explicit |
Default ctor for Blinn-Phong reflection model materials without textures.
Default constructor for Blinn-Phong reflection model materials without textures. Materials can be used by multiple meshes (SLMesh). Materials can belong therefore to the global assets such as meshes, materials, textures and shader programs.
am | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
name | Name of the material |
amdi | Ambient and diffuse color |
spec | Specular color |
shininess | Shininess exponent (the higher the sharper the gloss) |
kr | Reflection coefficient used for ray tracing. (0.0-1.0) |
kt | Transparency coefficient used for ray tracing. (0.0-1.0) |
kn | Refraction index used for ray tracing (1.0-2.5) |
program | Pointer to the shader program for the material. If none is passed a program will be generated from the passed parameters. |
SLMaterial::SLMaterial | ( | SLAssetManager * | am, |
const SLchar * | name, | ||
SLGLTexture * | texture1, | ||
SLGLTexture * | texture2 = nullptr , |
||
SLGLTexture * | texture3 = nullptr , |
||
SLGLTexture * | texture4 = nullptr , |
||
SLGLProgram * | program = nullptr |
||
) |
Ctor for textured Blinn-Phong reflection model materials.
Constructor for textured Blinn-Phong reflection model materials. Materials can be used by multiple meshes (SLMesh). Materials can belong therefore to the global assets such as meshes, materials, textures and shader programs.
am | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
name | Name of the material |
texture1 | Pointer to an SLGLTexture of a specific SLTextureType |
texture2 | Pointer to an SLGLTexture of a specific SLTextureType |
texture3 | Pointer to an SLGLTexture of a specific SLTextureType |
texture4 | Pointer to an SLGLTexture of a specific SLTextureType |
program | Pointer to the shader program for the material. If none is passed a program will be generated from the passed parameters. |
SLMaterial::SLMaterial | ( | SLAssetManager * | am, |
const SLchar * | name, | ||
SLSkybox * | skybox, | ||
SLCol4f | diffuse, | ||
SLfloat | roughness, | ||
SLfloat | metalness, | ||
SLGLProgram * | program = nullptr |
||
) |
Ctor for PBR material with Cook-Torrance material parameters.
Constructor for Cook-Torrance shaded materials with roughness and metalness. Materials can be used by multiple meshes (SLMesh). Materials can belong therefore to the global assets such as meshes, materials, textures and shader programs.
am | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
name | Name of the material |
skybox | Pointer to the skybox if available |
diffuse | Diffuse reflection color |
roughness | Roughness (0.0-1.0) |
metalness | Metalness (0.0-1.0) |
program | Pointer to the shader program for the material. If none is passed a program will be generated from the passed parameters. |
SLMaterial::SLMaterial | ( | SLAssetManager * | am, |
const SLchar * | name, | ||
SLSkybox * | skybox, | ||
SLGLTexture * | texture1, | ||
SLGLTexture * | texture2 = nullptr , |
||
SLGLTexture * | texture3 = nullptr , |
||
SLGLTexture * | texture4 = nullptr , |
||
SLGLTexture * | texture5 = nullptr , |
||
SLGLProgram * | program = nullptr |
||
) |
Ctor for PBR material with Cook-Torrance material textures.
Constructor for Cook-Torrance shaded materials with PBR textures. Materials can be used by multiple meshes (SLMesh). Materials can belong therefore to the global assets such as meshes, materials, textures and shader programs.
am | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
name | Name of the material |
skybox | Pointer to the skybox if available. If the skybox is an HDR skybox it will influence the ambient and specular reflection. |
texture1 | Pointer to a SLGLTexture of a specific SLTextureType. For PBR materials this can be TT_diffuse, TT_normal, TT_roughness, TT_metallic and TT_occlusion. |
texture2 | Pointer to a SLGLTexture of a specific SLTextureType. |
texture3 | Pointer to a SLGLTexture of a specific SLTextureType. |
texture4 | Pointer to a SLGLTexture of a specific SLTextureType. |
texture5 | Pointer to a SLGLTexture of a specific SLTextureType. |
program | Pointer to the shader program for the material. If none is passed a program will be generated from the passed parameters. |
SLMaterial::SLMaterial | ( | SLAssetManager * | am, |
const SLchar * | name, | ||
SLParticleSystem * | ps, | ||
SLGLTexture * | texture, | ||
SLGLProgram * | program = nullptr , |
||
SLGLProgram * | programTF = nullptr |
||
) |
Ctor for Particle System material with one texture (Draw and update)
Constructor for textured particle system materials (Draw=. Materials can be used by multiple meshes (SLMesh). Materials can belong therefore to the global assets such as meshes, materials, textures and shader programs.
am | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
name | Name of the material |
texture | Pointer to an SLGLTexture of a specific SLTextureType |
ps | Pointer to the particle system for the material. |
program | Pointer to the shader program for the material. If none is passed a program will be generated from the passed parameters. |
programTF | Pointer to the shader program for Transform Feedback |
|
explicit |
Ctor for uniform color material without lighting.
Constructor for uniform color material without lighting Materials can be used by multiple meshes (SLMesh). Materials can belong therefore to the global assets such as meshes, materials, textures and shader programs.
am | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
colorUniformProgram | Pointer to shader program for uniform coloring. |
uniformColor | Color to apply |
name | Name of the material |
SLMaterial::SLMaterial | ( | SLAssetManager * | am, |
const SLchar * | name, | ||
SLGLProgram * | shaderProg | ||
) |
Ctor for only a program.
Constructor for materials with only a shader program. Materials can be used by multiple meshes (SLMesh). Materials can belong therefore to the global assets such as meshes, materials, textures and shader programs.
am | Pointer to a global asset manager. If passed the asset manager is the owner of the instance and will do the deallocation. If a nullptr is passed the creator is responsible for the deallocation. |
name | Name of the material |
shaderProg | Pointer to the shader program for the material |
|
override |
The destructor should be called by the owner of the material. If an asset manager was passed in the constructor it will do it after scene destruction. The textures (SLGLTexture) and the shader program (SLGLProgram) that the material uses will not be deallocated.
SLMaterial::activate activates this material for rendering if it is not yet the active one and set as SLGLState::currentMaterial. If this material has not yet a shader program assigned (SLMaterial::_program) a suitable program will be generated with an instance of SLGLProgramGenerated. At the end the shader program will begin its usage with SLGLProgram::beginUse.
cam | Pointer to the active camera |
lights | Pointer to the scene vector of lights |
skybox | Pointer to the skybox |
void SLMaterial::addTexture | ( | SLGLTexture * | texture | ) |
Adds the passed texture to the equivalent texture type vector.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void SLMaterial::generateProgramPS | ( | ) |
If this material has not yet a shader program assigned (SLMaterial::_program) a suitable program will be generated with an instance of SLGLProgramGenerated.
|
inline |
|
inline |
|
inline |
Returns true if a material has a 3D texture.
|
inline |
Returns true if there is any transparency in diffuse alpha or textures.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
SLint SLMaterial::passToUniforms | ( | SLGLProgram * | program, |
SLint | nextTexUnit | ||
) |
Passes all material parameters as uniforms to the passed shader program.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
SLstring SLMaterial::texturesString | ( | ) |
Returns a unique string that represent all textures used.
|
inline |
|
inline |
|
inline |
|
inline |
Returns true if the specified uvIndex is used by one of the textures.
|
protected |
ambient color (RGB reflection coefficients)
|
protected |
pointer to the asset manager (the owner) if available
|
protected |
path to the error texture
|
protected |
diffuse color (RGB reflection coefficients)
|
protected |
emissive color coefficients
|
protected |
pointer to error texture that is shown if another texture fails
|
protected |
true if shadows are visible on this material
|
protected |
refraction index
|
protected |
reflection coefficient 0.0 - 1.0 used for ray and path tracing
|
protected |
transmission coefficient 0.0 - 1.0 used for ray and path tracing
|
protected |
metallic property (0-1) in Cook-Torrance model
|
protected |
Vector of all visible 2D nodes of with this material.
|
protected |
Vector of all visible 3D nodes of with this material.
|
protected |
number of textures in all _textures vectors array
|
protected |
pointer to a GLSL shader program
|
protected |
pointer to a GLSL shader program for transformFeedback
|
protected |
pointer to a particle system
|
protected |
reflection model (RM_BlinnPhong or RM_CookTorrance)
|
protected |
roughness property (0-1) in Cook-Torrance model
|
protected |
shininess exponent in Blinn-Phong model
|
protected |
pointer to the skybox
|
protected |
specular color (RGB reflection coefficients)
|
protected |
array of texture vectors one for each type
|
protected |
texture vector for diffuse 3D textures
|
protected |
translucency exponent for light refraction for path tracing
|
protected |
transmissive color (RGB reflection coefficients) for path tracing
|
static |
PM: Constant of gloss calibration (slope of point light at dist 1)
|
static |
PM: shininess/translucency limit.