SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
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 (bool drawInstanced=false) |
void | activate (SLCamera *cam, SLVLight *lights, SLbool supportGPUSkinning) |
SLint | passToUniforms (SLGLProgram *program, SLint nextTexUnit) |
Passes all material parameters as uniforms to the passed shader program. More... | |
void | deleteDataGpu () |
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.
Definition at line 55 of file SLMaterial.h.
|
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. |
Definition at line 37 of file SLMaterial.cpp.
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. |
Definition at line 89 of file SLMaterial.cpp.
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. |
Definition at line 144 of file SLMaterial.cpp.
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. |
Definition at line 195 of file SLMaterial.cpp.
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 |
Definition at line 250 of file SLMaterial.cpp.
|
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 |
Definition at line 319 of file SLMaterial.cpp.
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 |
Definition at line 283 of file SLMaterial.cpp.
|
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.
Definition at line 367 of file SLMaterial.cpp.
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 |
supportsSkinning | flag if skinning in shader should be supported |
Definition at line 507 of file SLMaterial.cpp.
void SLMaterial::addTexture | ( | SLGLTexture * | texture | ) |
Adds the passed texture to the equivalent texture type vector.
Definition at line 348 of file SLMaterial.cpp.
|
inline |
Definition at line 213 of file SLMaterial.h.
Definition at line 170 of file SLMaterial.h.
Definition at line 172 of file SLMaterial.h.
|
inline |
Definition at line 211 of file SLMaterial.h.
|
inline |
Definition at line 168 of file SLMaterial.h.
void SLMaterial::deleteDataGpu | ( | ) |
Definition at line 376 of file SLMaterial.cpp.
|
inline |
Definition at line 214 of file SLMaterial.h.
Definition at line 171 of file SLMaterial.h.
|
inline |
Definition at line 216 of file SLMaterial.h.
Definition at line 174 of file SLMaterial.h.
void SLMaterial::generateProgramPS | ( | bool | drawInstanced = false | ) |
If this material has not yet a shader program assigned (SLMaterial::_program) a suitable program will be generated with an instance of SLGLProgramGenerated.
Definition at line 391 of file SLMaterial.cpp.
|
inline |
Definition at line 225 of file SLMaterial.h.
Definition at line 204 of file SLMaterial.h.
|
inline |
Returns true if a material has a 3D texture.
Definition at line 139 of file SLMaterial.h.
|
inline |
Returns true if there is any transparency in diffuse alpha or textures.
Definition at line 125 of file SLMaterial.h.
|
inline |
Definition at line 149 of file SLMaterial.h.
|
inline |
Definition at line 153 of file SLMaterial.h.
|
inline |
Definition at line 224 of file SLMaterial.h.
Definition at line 199 of file SLMaterial.h.
|
inline |
Definition at line 222 of file SLMaterial.h.
|
inline |
Definition at line 223 of file SLMaterial.h.
|
inline |
Definition at line 219 of file SLMaterial.h.
Definition at line 183 of file SLMaterial.h.
|
inline |
Definition at line 144 of file SLMaterial.h.
|
inline |
Definition at line 231 of file SLMaterial.h.
|
inline |
Definition at line 232 of file SLMaterial.h.
|
inline |
Definition at line 226 of file SLMaterial.h.
SLint SLMaterial::passToUniforms | ( | SLGLProgram * | program, |
SLint | nextTexUnit | ||
) |
Passes all material parameters as uniforms to the passed shader program.
Definition at line 560 of file SLMaterial.cpp.
|
inline |
Definition at line 227 of file SLMaterial.h.
|
inline |
Definition at line 205 of file SLMaterial.h.
|
inline |
Definition at line 228 of file SLMaterial.h.
|
inline |
Definition at line 206 of file SLMaterial.h.
|
inline |
Definition at line 230 of file SLMaterial.h.
|
inline |
Definition at line 208 of file SLMaterial.h.
|
inline |
Definition at line 212 of file SLMaterial.h.
|
inline |
Definition at line 169 of file SLMaterial.h.
|
inline |
Definition at line 159 of file SLMaterial.h.
|
inline |
Definition at line 218 of file SLMaterial.h.
Definition at line 182 of file SLMaterial.h.
|
inline |
Definition at line 217 of file SLMaterial.h.
Definition at line 177 of file SLMaterial.h.
|
inline |
Definition at line 229 of file SLMaterial.h.
Definition at line 207 of file SLMaterial.h.
|
inline |
Definition at line 215 of file SLMaterial.h.
Definition at line 173 of file SLMaterial.h.
|
inline |
Definition at line 233 of file SLMaterial.h.
|
inline |
Definition at line 234 of file SLMaterial.h.
SLstring SLMaterial::texturesString | ( | ) |
Returns a unique string that represent all textures used.
Definition at line 687 of file SLMaterial.cpp.
|
inline |
Definition at line 221 of file SLMaterial.h.
Definition at line 176 of file SLMaterial.h.
|
inline |
Definition at line 220 of file SLMaterial.h.
Definition at line 175 of file SLMaterial.h.
Returns true if the specified uvIndex is used by one of the textures.
Definition at line 707 of file SLMaterial.cpp.
|
protected |
ambient color (RGB reflection coefficients)
Definition at line 243 of file SLMaterial.h.
|
protected |
pointer to the asset manager (the owner) if available
Definition at line 241 of file SLMaterial.h.
|
protected |
path to the error texture
Definition at line 267 of file SLMaterial.h.
|
protected |
diffuse color (RGB reflection coefficients)
Definition at line 244 of file SLMaterial.h.
|
protected |
emissive color coefficients
Definition at line 246 of file SLMaterial.h.
|
protected |
pointer to error texture that is shown if another texture fails
Definition at line 266 of file SLMaterial.h.
|
protected |
true if shadows are visible on this material
Definition at line 255 of file SLMaterial.h.
|
protected |
refraction index
Definition at line 254 of file SLMaterial.h.
|
protected |
reflection coefficient 0.0 - 1.0 used for ray and path tracing
Definition at line 252 of file SLMaterial.h.
|
protected |
transmission coefficient 0.0 - 1.0 used for ray and path tracing
Definition at line 253 of file SLMaterial.h.
|
protected |
metallic property (0-1) in Cook-Torrance model
Definition at line 249 of file SLMaterial.h.
|
protected |
Vector of all visible 2D nodes of with this material.
Definition at line 269 of file SLMaterial.h.
|
protected |
Vector of all visible 3D nodes of with this material.
Definition at line 270 of file SLMaterial.h.
|
protected |
number of textures in all _textures vectors array
Definition at line 258 of file SLMaterial.h.
|
protected |
pointer to a GLSL shader program
Definition at line 256 of file SLMaterial.h.
|
protected |
pointer to a GLSL shader program for transformFeedback
Definition at line 257 of file SLMaterial.h.
|
protected |
pointer to a particle system
Definition at line 262 of file SLMaterial.h.
|
protected |
reflection model (RM_BlinnPhong or RM_CookTorrance)
Definition at line 242 of file SLMaterial.h.
|
protected |
roughness property (0-1) in Cook-Torrance model
Definition at line 248 of file SLMaterial.h.
|
protected |
shininess exponent in Blinn-Phong model
Definition at line 247 of file SLMaterial.h.
|
protected |
pointer to the skybox
Definition at line 259 of file SLMaterial.h.
|
protected |
specular color (RGB reflection coefficients)
Definition at line 245 of file SLMaterial.h.
|
protected |
array of texture vectors one for each type
Definition at line 264 of file SLMaterial.h.
|
protected |
texture vector for diffuse 3D textures
Definition at line 265 of file SLMaterial.h.
|
protected |
translucency exponent for light refraction for path tracing
Definition at line 251 of file SLMaterial.h.
|
protected |
transmissive color (RGB reflection coefficients) for path tracing
Definition at line 250 of file SLMaterial.h.
|
static |
PM: Constant of gloss calibration (slope of point light at dist 1)
Definition at line 237 of file SLMaterial.h.
|
static |
PM: shininess/translucency limit.
Definition at line 238 of file SLMaterial.h.