SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLMaterial Class Reference

Defines a standard CG material with textures and a shader program. More...

#include <SLMaterial.h>

Inheritance diagram for SLMaterial:
[legend]

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)
 
SLAssetManagerassetManager ()
 
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 ()
 
SLGLProgramprogram ()
 
SLGLProgramprogramTF ()
 
SLSkyboxskybox ()
 
SLParticleSystemps ()
 
SLVNodenodesVisible2D ()
 
SLVNodenodesVisible3D ()
 
SLVGLTexturetextures (SLTextureType type)
 
SLVGLTexturetextures3d ()
 
- 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 SLstringname () const
 
const SLstringurl () 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...
 

Detailed Description

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.

Remarks
It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within an SLScene::registerAssetsToLoad or SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread. For this material it means, that OpenGL shader programs in _programs and the textures in _textures do not get built until the first frame is rendered.

Definition at line 55 of file SLMaterial.h.

Constructor & Destructor Documentation

◆ SLMaterial() [1/7]

SLMaterial::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 
)
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.

Parameters
amPointer 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.
nameName of the material
amdiAmbient and diffuse color
specSpecular color
shininessShininess exponent (the higher the sharper the gloss)
krReflection coefficient used for ray tracing. (0.0-1.0)
ktTransparency coefficient used for ray tracing. (0.0-1.0)
knRefraction index used for ray tracing (1.0-2.5)
programPointer 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.

45  : SLObject(name)
46 {
47  _assetManager = am;
49  _ambient = _diffuse = amdi;
50  _specular = spec;
51  _emissive.set(0, 0, 0, 0);
53  _roughness = 0.5f;
54  _metalness = 0.0f;
55  _translucency = 0.0f;
56  _getsShadows = true;
57  _program = program;
58  _skybox = nullptr;
59  _numTextures = 0;
60 
61  _kr = kr;
62  _kt = kt;
63  _kn = kn;
64 
65  // sync the transparency coefficient with the alpha value or vice versa
66  if (_kt > 0) _diffuse.w = 1.0f - _kt;
67  if (_diffuse.w > 1) _kt = 1.0f - _diffuse.w;
68 
69  // Add pointer to the global resource vectors for deallocation
70  if (am)
71  am->materials().push_back(this);
72 }
@ RM_BlinnPhong
Definition: SLEnums.h:289
SLVMaterial & materials()
SLGLProgram * program()
Definition: SLMaterial.h:227
SLCol4f _emissive
emissive color coefficients
Definition: SLMaterial.h:246
SLCol4f _specular
specular color (RGB reflection coefficients)
Definition: SLMaterial.h:245
SLfloat shininess() const
Definition: SLMaterial.h:217
SLfloat _kt
transmission coefficient 0.0 - 1.0 used for ray and path tracing
Definition: SLMaterial.h:253
SLfloat _kr
reflection coefficient 0.0 - 1.0 used for ray and path tracing
Definition: SLMaterial.h:252
SLAssetManager * _assetManager
pointer to the asset manager (the owner) if available
Definition: SLMaterial.h:241
SLfloat kr() const
Definition: SLMaterial.h:222
SLfloat _metalness
metallic property (0-1) in Cook-Torrance model
Definition: SLMaterial.h:249
SLfloat _roughness
roughness property (0-1) in Cook-Torrance model
Definition: SLMaterial.h:248
SLCol4f _ambient
ambient color (RGB reflection coefficients)
Definition: SLMaterial.h:243
SLCol4f _diffuse
diffuse color (RGB reflection coefficients)
Definition: SLMaterial.h:244
SLbool _getsShadows
true if shadows are visible on this material
Definition: SLMaterial.h:255
SLfloat kn() const
Definition: SLMaterial.h:224
SLfloat kt() const
Definition: SLMaterial.h:223
SLGLProgram * _program
pointer to a GLSL shader program
Definition: SLMaterial.h:256
SLSkybox * _skybox
pointer to the skybox
Definition: SLMaterial.h:259
SLfloat _kn
refraction index
Definition: SLMaterial.h:254
SLReflectionModel _reflectionModel
reflection model (RM_BlinnPhong or RM_CookTorrance)
Definition: SLMaterial.h:242
SLint _numTextures
number of textures in all _textures vectors array
Definition: SLMaterial.h:258
SLfloat _shininess
shininess exponent in Blinn-Phong model
Definition: SLMaterial.h:247
SLfloat _translucency
translucency exponent for light refraction for path tracing
Definition: SLMaterial.h:251
SLObject(const SLstring &Name="", const SLstring &url="")
Definition: SLObject.h:25
const SLstring & name() const
Definition: SLObject.h:38
T w
Definition: SLVec4.h:32
void set(const T X, const T Y, const T Z, const T W=1)
Definition: SLVec4.h:49

◆ SLMaterial() [2/7]

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.

Parameters
amPointer 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.
nameName of the material
texture1Pointer to an SLGLTexture of a specific SLTextureType
texture2Pointer to an SLGLTexture of a specific SLTextureType
texture3Pointer to an SLGLTexture of a specific SLTextureType
texture4Pointer to an SLGLTexture of a specific SLTextureType
programPointer 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.

95  : SLObject(name)
96 {
97  _assetManager = am;
99  _ambient.set(1, 1, 1);
100  _diffuse.set(1, 1, 1);
101  _specular.set(1, 1, 1);
102  _emissive.set(0, 0, 0, 0);
103  _shininess = 125;
104  _roughness = 0.5f;
105  _metalness = 0.0f;
106  _translucency = 0.0f;
107  _getsShadows = true;
108  _kr = 0.0f;
109  _kt = 0.0f;
110  _kn = 1.0f;
111  _diffuse.w = 1.0f - _kt;
112  _skybox = nullptr;
113  _program = program;
114 
115  _numTextures = 0;
116  addTexture(texture1);
117  addTexture(texture2);
118  addTexture(texture3);
119  addTexture(texture4);
120 
121  if (_textures[TT_roughness].size() > 0 || _textures[TT_metallic].size() > 0)
123 
124  // Add pointer to the global resource vectors for deallocation
125  if (am)
126  am->materials().push_back(this);
127 }
@ RM_CookTorrance
Definition: SLEnums.h:290
@ TT_metallic
Definition: SLGLTexture.h:85
@ TT_roughness
Definition: SLGLTexture.h:84
SLVGLTexture _textures[TT_numTextureType]
array of texture vectors one for each type
Definition: SLMaterial.h:264
void addTexture(SLGLTexture *texture)
Adds the passed texture to the equivalent texture type vector.
Definition: SLMaterial.cpp:348

◆ SLMaterial() [3/7]

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.

Parameters
amPointer 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.
nameName of the material
skyboxPointer to the skybox if available
diffuseDiffuse reflection color
roughnessRoughness (0.0-1.0)
metalnessMetalness (0.0-1.0)
programPointer 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.

150  : SLObject(name)
151 {
152  _assetManager = am;
153  _ambient.set(0, 0, 0); // not used in Cook-Torrance
154  _diffuse = diffuse;
155  _specular.set(1, 1, 1); // not used in Cook-Torrance
156  _emissive.set(0, 0, 0, 0); // not used in Cook-Torrance
157  _shininess = (1.0f - roughness) * 500.0f; // not used in Cook-Torrance
160  _numTextures = 0;
161  _getsShadows = true;
163  _skybox = skybox;
164  _program = program;
165 
166  _kr = 0.0f;
167  _kt = 0.0f;
168  _kn = 1.0f;
169 
170  // Add pointer to the global resource vectors for deallocation
171  if (am)
172  am->materials().push_back(this);
173 }
SLCol4f diffuse()
Definition: SLMaterial.h:214
SLSkybox * skybox()
Definition: SLMaterial.h:229
SLfloat roughness() const
Definition: SLMaterial.h:218
SLfloat metalness() const
Definition: SLMaterial.h:219

◆ SLMaterial() [4/7]

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.

Parameters
amPointer 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.
nameName of the material
skyboxPointer to the skybox if available. If the skybox is an HDR skybox it will influence the ambient and specular reflection.
texture1Pointer to a SLGLTexture of a specific SLTextureType. For PBR materials this can be TT_diffuse, TT_normal, TT_roughness, TT_metallic and TT_occlusion.
texture2Pointer to a SLGLTexture of a specific SLTextureType.
texture3Pointer to a SLGLTexture of a specific SLTextureType.
texture4Pointer to a SLGLTexture of a specific SLTextureType.
texture5Pointer to a SLGLTexture of a specific SLTextureType.
programPointer 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.

203  : SLObject(name)
204 {
205  _assetManager = am;
206  _ambient.set(1, 1, 1);
207  _diffuse.set(1, 1, 1);
208  _specular.set(1, 1, 1);
209  _emissive.set(0, 0, 0, 0);
210  _shininess = 125;
211  _roughness = 0.5f;
212  _metalness = 0.0f;
213  _numTextures = 0;
215  _getsShadows = true;
216  _skybox = skybox;
217  _program = program;
218 
219  addTexture(texture1);
220  addTexture(texture2);
221  addTexture(texture3);
222  addTexture(texture4);
223  addTexture(texture5);
224 
225  _kr = 0.0f;
226  _kt = 0.0f;
227  _kn = 1.0f;
228  _diffuse.w = 1.0f - _kt;
229  _program = nullptr;
230 
231  // Add pointer to the global resource vectors for deallocation
232  if (am)
233  am->materials().push_back(this);
234 }

◆ SLMaterial() [5/7]

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.

Parameters
amPointer 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.
nameName of the material
texturePointer to an SLGLTexture of a specific SLTextureType
psPointer to the particle system for the material.
programPointer to the shader program for the material. If none is passed a program will be generated from the passed parameters.
programTFPointer to the shader program for Transform Feedback

Definition at line 250 of file SLMaterial.cpp.

255  : SLObject(name)
256 {
257  _assetManager = am;
259  _getsShadows = true; // Later for Particle System maybe
260  _skybox = nullptr;
261  _ps = ps;
262  _program = program;
264 
265  _numTextures = 0;
266  addTexture(texture);
267 
268  // Add pointer to the global resource vectors for deallocation
269  if (am)
270  am->materials().push_back(this);
271 }
@ RM_Particle
Definition: SLEnums.h:291
SLParticleSystem * ps()
Definition: SLMaterial.h:230
SLGLProgram * _programTF
pointer to a GLSL shader program for transformFeedback
Definition: SLMaterial.h:257
SLParticleSystem * _ps
pointer to a particle system
Definition: SLMaterial.h:262
SLGLProgram * programTF()
Definition: SLMaterial.h:228

◆ SLMaterial() [6/7]

SLMaterial::SLMaterial ( SLAssetManager am,
SLGLProgram colorUniformProgram,
const SLCol4f uniformColor,
const SLchar name = (const char*)"Uniform color" 
)
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.

Parameters
amPointer 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.
colorUniformProgramPointer to shader program for uniform coloring.
uniformColorColor to apply
nameName of the material

Definition at line 319 of file SLMaterial.cpp.

322  : SLObject(name)
323 {
324  _assetManager = am;
326  _ambient.set(0, 0, 0);
327  _diffuse = uniformColor;
328  _specular.set(0, 0, 0);
329  _emissive.set(0, 0, 0, 0);
330  _shininess = 125;
331  _roughness = 0.5f;
332  _metalness = 0.0f;
333  _translucency = 0.0f;
334  _program = colorUniformProgram;
335  _skybox = nullptr;
336  _kr = 0.0f;
337  _kt = 0.0f;
338  _kn = 1.0f;
339  _getsShadows = true;
340  _numTextures = 0;
341 
342  // Add pointer to the global resource vectors for deallocation
343  if (am)
344  am->materials().push_back(this);
345 }
@ RM_Custom
Definition: SLEnums.h:292

◆ SLMaterial() [7/7]

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.

Parameters
amPointer 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.
nameName of the material
shaderProgPointer to the shader program for the material

Definition at line 283 of file SLMaterial.cpp.

285  : SLObject(name)
286 {
287  _assetManager = am;
288  _program = shaderProg;
289  _skybox = nullptr;
291  _ambient.set(1, 1, 1);
292  _diffuse.set(1, 1, 1);
293  _specular.set(1, 1, 1);
294  _emissive.set(0, 0, 0, 0);
295  _shininess = 125.0f;
296  _roughness = 0.0f;
297  _metalness = 0.0f;
298  _translucency = 0.0f;
299  _getsShadows = true;
300  _numTextures = 0;
301 
302  // Add pointer to the global resource vectors for deallocation
303  if (am)
304  am->materials().push_back(this);
305 }

◆ ~SLMaterial()

SLMaterial::~SLMaterial ( )
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.

368 {
369  if (_errorTexture)
370  {
371  delete _errorTexture;
372  _errorTexture = nullptr;
373  }
374 }
SLGLTexture * _errorTexture
pointer to error texture that is shown if another texture fails
Definition: SLMaterial.h:266

Member Function Documentation

◆ activate()

void SLMaterial::activate ( SLCamera cam,
SLVLight lights,
SLbool  supportGPUSkinning 
)

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.

Parameters
camPointer to the active camera
lightsPointer to the scene vector of lights
supportsSkinningflag if skinning in shader should be supported

Definition at line 507 of file SLMaterial.cpp.

510 {
511  SLGLState* stateGL = SLGLState::instance();
512 
513  if (stateGL->currentMaterial() == this &&
514  stateGL->currentMaterial()->program())
515  return;
516 
517  // Deactivate shader program of the current active material
518  if (stateGL->currentMaterial() && stateGL->currentMaterial()->program())
519  stateGL->currentMaterial()->program()->endShader();
520 
521  // Set this material as the current material
522  stateGL->currentMaterial(this);
523 
524  // If no shader program is attached add a generated shader program
525  // A 3D object can be stored without material or shader program information.
526  if (!_program)
527  {
528  // Check first the asset manager if the requested program type already exists
529  string programName;
531  lights,
532  supportGPUSkinning,
533  programName);
534  _program = _assetManager->getProgramByName(programName);
535 
536  // If the program was not found by name generate a new one
537  if (!_program)
539  programName,
540  this,
541  lights,
542  supportGPUSkinning);
543  }
544 
545  // Check if shader had a compile error and the error texture should be shown
546  if (_program && _program->name().find("ErrorTex") != string::npos)
547  {
548  for (int i = 0; i < TT_numTextureType; i++)
549  _textures[i].clear();
550  if (!_errorTexture && !_compileErrorTexFilePath.empty())
552  _textures[TT_diffuse].push_back(_errorTexture);
553  }
554 
555  // Activate the shader program now
556  _program->beginUse(cam, this, lights);
557 }
@ TT_numTextureType
Definition: SLGLTexture.h:95
@ TT_diffuse
Definition: SLGLTexture.h:78
SLGLProgram * getProgramByName(const string &programName)
Returns the pointer to shader program if found by name.
Generated Shader Program class inherited from SLGLProgram.
static void buildProgramName(SLMaterial *mat, SLVLight *lights, SLbool supportGPUSkinning, string &programName)
Builds unique program name that identifies shader program.
void beginUse(SLCamera *cam, SLMaterial *mat, SLVLight *lights)
Singleton class holding all OpenGL states.
Definition: SLGLState.h:71
static SLGLState * instance()
Public static instance getter for singleton pattern.
Definition: SLGLState.h:74
void currentMaterial(SLMaterial *mat)
Definition: SLGLState.h:120
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110
SLstring _compileErrorTexFilePath
path to the error texture
Definition: SLMaterial.h:267
void name(const SLstring &Name)
Definition: SLObject.h:34
void clear(std::string path)
Definition: SLIOMemory.cpp:34

◆ addTexture()

void SLMaterial::addTexture ( SLGLTexture texture)

Adds the passed texture to the equivalent texture type vector.

Definition at line 348 of file SLMaterial.cpp.

349 {
350  if (!texture)
351  return;
352 
353  if (texture->target() == GL_TEXTURE_3D)
354  _textures3d.push_back(texture);
355 
356  _textures[texture->texType()].push_back(texture);
357 
358  _numTextures++;
359 }
SLenum target() const
Definition: SLGLTexture.h:226
void texType(SLTextureType bt)
Definition: SLGLTexture.h:200
SLVGLTexture _textures3d
texture vector for diffuse 3D textures
Definition: SLMaterial.h:265

◆ ambient() [1/2]

SLCol4f SLMaterial::ambient ( )
inline

Definition at line 213 of file SLMaterial.h.

213 { return _ambient; }

◆ ambient() [2/2]

void SLMaterial::ambient ( const SLCol4f ambi)
inline

Definition at line 170 of file SLMaterial.h.

170 { _ambient = ambi; }

◆ ambientDiffuse()

void SLMaterial::ambientDiffuse ( const SLCol4f am_di)
inline

Definition at line 172 of file SLMaterial.h.

172 { _ambient = _diffuse = am_di; }

◆ assetManager() [1/2]

SLAssetManager* SLMaterial::assetManager ( )
inline

Definition at line 211 of file SLMaterial.h.

211 { return _assetManager; }

◆ assetManager() [2/2]

void SLMaterial::assetManager ( SLAssetManager am)
inline

Definition at line 168 of file SLMaterial.h.

168 { _assetManager = am; }

◆ deleteDataGpu()

void SLMaterial::deleteDataGpu ( )

Definition at line 376 of file SLMaterial.cpp.

377 {
378  if (_program)
379  {
382  delete _program;
383  _program = nullptr;
384  }
385 }
bool removeProgram(SLGLProgram *program)
Removes the specified mesh from the meshes resource vector.
void deleteDataGpu()
Delete all Gpu data.
Definition: SLGLProgram.cpp:96

◆ diffuse() [1/2]

SLCol4f SLMaterial::diffuse ( )
inline

Definition at line 214 of file SLMaterial.h.

214 { return _diffuse; }

◆ diffuse() [2/2]

void SLMaterial::diffuse ( const SLCol4f diff)
inline

Definition at line 171 of file SLMaterial.h.

171 { _diffuse = diff; }

◆ emissive() [1/2]

SLCol4f SLMaterial::emissive ( )
inline

Definition at line 216 of file SLMaterial.h.

216 { return _emissive; }

◆ emissive() [2/2]

void SLMaterial::emissive ( const SLCol4f emis)
inline

Definition at line 174 of file SLMaterial.h.

174 { _emissive = emis; }

◆ generateProgramPS()

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.

392 {
393  // If no shader program is attached add a generated shader program
394  // A 3D object can be stored without material or shader program information.
395  if (!_program)
396  {
397  /////////////////////////////
398  // Generate draw program
399  /////////////////////////////
400 
401  // Check first the asset manager if the requested program type already exists
402  string programNameDraw;
404  programNameDraw,
405  true,
406  drawInstanced);
407  _program = _assetManager->getProgramByName(programNameDraw);
408 
409  // If the program was not found by name generate a new one
410  if (!_program)
411  {
412  std::string geom = "";
413  if (!drawInstanced)
414  geom = "Geom";
415 
417  programNameDraw,
418  this,
419  true,
420  geom);
421  }
422  }
423 
424  if (!_programTF)
425  {
426  /////////////////////////////
427  // Generate update program
428  /////////////////////////////
429 
430  // Check first the asset manager if the requested programTF type already exists
431  string programNameUpdate;
432  SLGLProgramGenerated::buildProgramNamePS(this, programNameUpdate, false, drawInstanced);
433  _programTF = _assetManager->getProgramByName(programNameUpdate);
434  if (!_programTF)
435  {
437  programNameUpdate,
438  this,
439  false);
440 
441  int countString = 3;
442  vector<const char*> outputNames; // For transform feedback
443  outputNames.push_back("tf_position");
444  outputNames.push_back("tf_velocity");
445  outputNames.push_back("tf_startTime");
446  if (_ps->doAcc() || _ps->doGravity())
447  {
448  outputNames.push_back("tf_initialVelocity");
449  countString++;
450  }
451  if (_ps->doRotation())
452  {
453  outputNames.push_back("tf_rotation");
454  countString++;
455  }
456  if (_ps->doRotation() && _ps->doRotRange())
457  {
458  outputNames.push_back("tf_angularVelo");
459  countString++;
460  }
461  if (_ps->doFlipBookTexture())
462  {
463  outputNames.push_back("tf_texNum");
464  countString++;
465  }
466  if (_ps->doShape())
467  {
468  outputNames.push_back("tf_initialPosition");
469  countString++;
470  }
471  _programTF->initTF(&outputNames[0], countString);
472  }
473  }
474 
475  // Check if shader had a compile error and the error texture should be shown
476  if (_program && _program->name().find("ErrorTex") != string::npos)
477  {
478  for (int i = 0; i < TT_numTextureType; i++)
479  _textures[i].clear();
480  if (!_errorTexture && !_compileErrorTexFilePath.empty())
481  _errorTexture = new SLGLTexture(nullptr,
483  _textures[TT_diffuse].push_back(_errorTexture);
484  }
485 
486  if (_programTF && _programTF->name().find("ErrorTex") != string::npos)
487  {
488  for (int i = 0; i < TT_numTextureType; i++)
489  _textures[i].clear();
490  if (!_errorTexture && !_compileErrorTexFilePath.empty())
491  _errorTexture = new SLGLTexture(nullptr,
493  _textures[TT_diffuse].push_back(_errorTexture);
494  }
495 }
static void buildProgramNamePS(SLMaterial *mat, string &programName, bool isDrawProg, bool drawInstanced)
void initTF(const char *writeBackAttrib[], int size)
SLbool doFlipBookTexture()

◆ getsShadows() [1/2]

SLbool SLMaterial::getsShadows ( ) const
inline

Definition at line 225 of file SLMaterial.h.

225 { return _getsShadows; }

◆ getsShadows() [2/2]

void SLMaterial::getsShadows ( SLbool  receivesShadows)
inline

Definition at line 204 of file SLMaterial.h.

204 { _getsShadows = receivesShadows; }

◆ has3DTexture()

SLbool SLMaterial::has3DTexture ( )
inline

Returns true if a material has a 3D texture.

Definition at line 139 of file SLMaterial.h.

140  {
141  return !_textures3d.empty();
142  }

◆ hasAlpha()

SLbool SLMaterial::hasAlpha ( )
inline

Returns true if there is any transparency in diffuse alpha or textures.

Definition at line 125 of file SLMaterial.h.

126  {
127  if (_diffuse.a < 1.0)
128  return true;
129 
130  for (int i = 0; i < _textures[TT_diffuse].size(); i++)
131  {
132  if (_textures[TT_diffuse][i]->hasAlpha())
133  return true;
134  }
135  return false;
136  }
SLbool hasAlpha()
Returns true if there is any transparency in diffuse alpha or textures.
Definition: SLMaterial.h:125
T a
Definition: SLVec4.h:33

◆ hasTextureType()

SLbool SLMaterial::hasTextureType ( SLTextureType  tt)
inline

Definition at line 149 of file SLMaterial.h.

150  {
151  return !_textures[tt].empty();
152  }

◆ hasTextureTypeWithUVIndex()

SLbool SLMaterial::hasTextureTypeWithUVIndex ( SLTextureType  tt,
SLuint  texIndex,
SLbyte  uvIndex 
)
inline

Definition at line 153 of file SLMaterial.h.

154  {
155  return (_textures[tt].size() > texIndex &&
156  _textures[tt][texIndex]->uvIndex() == uvIndex);
157  }

◆ kn() [1/2]

SLfloat SLMaterial::kn ( ) const
inline

Definition at line 224 of file SLMaterial.h.

224 { return _kn; }

◆ kn() [2/2]

void SLMaterial::kn ( SLfloat  kn)
inline

Definition at line 199 of file SLMaterial.h.

200  {
201  assert(kn >= 0.0f);
202  _kn = kn;
203  }

◆ kr() [1/2]

SLfloat SLMaterial::kr ( ) const
inline

Definition at line 222 of file SLMaterial.h.

222 { return _kr; }

◆ kr() [2/2]

void SLMaterial::kr ( SLfloat  kr)
inline

Definition at line 184 of file SLMaterial.h.

185  {
186  if (kr < 0.0f) kr = 0.0f;
187  if (kr > 1.0f) kr = 1.0f;
188  _kr = kr;
189  }

◆ kt() [1/2]

SLfloat SLMaterial::kt ( ) const
inline

Definition at line 223 of file SLMaterial.h.

223 { return _kt; }

◆ kt() [2/2]

void SLMaterial::kt ( SLfloat  kt)
inline

Definition at line 190 of file SLMaterial.h.

191  {
192  if (kt < 0.0f) kt = 0.0f;
193  if (kt > 1.0f) kt = 1.0f;
194  _kt = kt;
195  _ambient.w = 1.0f - kt;
196  _diffuse.w = 1.0f - kt;
197  _specular.w = 1.0f - kt;
198  }

◆ metalness() [1/2]

SLfloat SLMaterial::metalness ( ) const
inline

Definition at line 219 of file SLMaterial.h.

219 { return _metalness; }

◆ metalness() [2/2]

void SLMaterial::metalness ( SLfloat  m)
inline

Definition at line 183 of file SLMaterial.h.

183 { _metalness = Utils::clamp(m, 0.0f, 1.0f); }
T clamp(T a, T min, T max)
Definition: Utils.h:253

◆ needsTangents()

SLbool SLMaterial::needsTangents ( )
inline

Definition at line 144 of file SLMaterial.h.

145  {
146  return !_textures[TT_normal].empty() &&
147  _textures[TT_normal][0]->target() == GL_TEXTURE_2D;
148  }
@ TT_normal
Definition: SLGLTexture.h:79

◆ nodesVisible2D()

SLVNode& SLMaterial::nodesVisible2D ( )
inline

Definition at line 231 of file SLMaterial.h.

231 { return _nodesVisible2D; }
SLVNode _nodesVisible2D
Vector of all visible 2D nodes of with this material.
Definition: SLMaterial.h:269

◆ nodesVisible3D()

SLVNode& SLMaterial::nodesVisible3D ( )
inline

Definition at line 232 of file SLMaterial.h.

232 { return _nodesVisible3D; }
SLVNode _nodesVisible3D
Vector of all visible 3D nodes of with this material.
Definition: SLMaterial.h:270

◆ numTextures()

SLuint SLMaterial::numTextures ( )
inline

Definition at line 226 of file SLMaterial.h.

226 { return _numTextures; }

◆ passToUniforms()

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.

561 {
562  assert(program && "SLMaterial::passToUniforms: No shader program set!");
563 
564  program->uniform4fv("u_matAmbi", 1, (SLfloat*)&_ambient);
565  program->uniform4fv("u_matDiff", 1, (SLfloat*)&_diffuse);
566  program->uniform4fv("u_matSpec", 1, (SLfloat*)&_specular);
567  program->uniform4fv("u_matEmis", 1, (SLfloat*)&_emissive);
568  program->uniform1f("u_matShin", _shininess);
569  program->uniform1f("u_matRough", _roughness);
570  program->uniform1f("u_matMetal", _metalness);
571  program->uniform1f("u_matKr", _kr);
572  program->uniform1f("u_matKt", _kt);
573  program->uniform1f("u_matKn", _kn);
574  program->uniform1i("u_matGetsShadows", _getsShadows);
575  program->uniform1i("u_matHasTexture", _numTextures > 0 ? 1 : 0);
576 
577  // pass textures unit id to the sampler uniform
578  for (SLuint i = 0; i < TT_numTextureType; i++)
579  {
580  int texNb = 0;
581  for (SLGLTexture* texture : _textures[i])
582  {
583  SLchar name[100];
584  texture->bindActive(nextTexUnit);
585  switch (i)
586  {
587  case TT_diffuse:
588  {
589  snprintf(name, sizeof(name), "u_matTextureDiffuse%d", texNb);
590  break;
591  }
592  case TT_specular:
593  {
594  snprintf(name, sizeof(name), "u_matTextureSpecular%d", texNb);
595  break;
596  }
597  case TT_normal:
598  {
599  snprintf(name, sizeof(name), "u_matTextureNormal%d", texNb);
600  break;
601  }
602  case TT_height:
603  {
604  snprintf(name, sizeof(name), "u_matTextureHeight%d", texNb);
605  break;
606  }
607  case TT_occlusion:
608  {
609  snprintf(name, sizeof(name), "u_matTextureOcclusion%d", texNb);
610  break;
611  }
612  case TT_roughness:
613  {
614  snprintf(name, sizeof(name), "u_matTextureRoughness%d", texNb);
615  break;
616  }
617  case TT_metallic:
618  {
619  snprintf(name, sizeof(name), "u_matTextureMetallic%d", texNb);
620  break;
621  }
622  case TT_roughMetal:
623  {
624  snprintf(name, sizeof(name), "u_matTextureRoughMetal%d", texNb);
625  break;
626  }
627  case TT_occluRoughMetal:
628  {
629  snprintf(name, sizeof(name), "u_matTextureOccluRoughMetal%d", texNb);
630  break;
631  }
632  case TT_emissive:
633  {
634  snprintf(name, sizeof(name), "u_matTextureEmissive%d", texNb);
635  break;
636  }
638  {
639  snprintf(name, sizeof(name), "u_matTextureEnvCubemap%d", texNb);
640  break;
641  }
642  case TT_font:
643  {
644  snprintf(name, sizeof(name), "u_matTextureFont%d", texNb);
645  break;
646  }
647  default:
648  {
649  snprintf(name, sizeof(name), "u_matTextureDiffuse%d", texNb);
650  break;
651  }
652  }
653 
654  if (program->uniform1i(name, nextTexUnit) < 0)
655  Utils::log("Material",
656  "texture name %s not found for program: %s",
657  name,
658  program->name().c_str());
659 
660  texNb++;
661  nextTexUnit++;
662  }
663  }
664 
665  // Pass environment mapping uniforms from the skybox
666  if (_skybox &&
670  {
671  if (program->uniform1i("u_skyIrradianceCubemap", nextTexUnit) >= 0)
672  _skybox->irradianceCubemap()->bindActive(nextTexUnit++);
673 
674  if (program->uniform1i("u_skyRoughnessCubemap", nextTexUnit) >= 0)
675  _skybox->roughnessCubemap()->bindActive(nextTexUnit++);
676 
677  if (program->uniform1i("u_skyBrdfLutTexture", nextTexUnit) >= 0)
678  _skybox->brdfLutTexture()->bindActive(nextTexUnit++);
679 
680  program->uniform1f("u_skyExposure", _skybox->exposure());
681  }
682 
683  return nextTexUnit;
684 }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
char SLchar
Definition: SL.h:162
@ TT_occluRoughMetal
Definition: SLGLTexture.h:87
@ TT_height
Definition: SLGLTexture.h:80
@ TT_environmentCubemap
Definition: SLGLTexture.h:90
@ TT_roughMetal
Definition: SLGLTexture.h:86
@ TT_specular
Definition: SLGLTexture.h:81
@ TT_occlusion
Definition: SLGLTexture.h:83
@ TT_emissive
Definition: SLGLTexture.h:82
@ TT_font
Definition: SLGLTexture.h:88
SLint uniform4fv(const SLchar *name, SLsizei count, const SLfloat *value) const
Passes 4 float values py pointer to the uniform variable "name".
SLint uniform1f(const SLchar *name, SLfloat v0) const
Passes the float value v0 to the uniform variable "name".
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
void bindActive(SLuint texUnit=0)
SLfloat exposure()
Definition: SLSkybox.h:54
SLGLTexture * irradianceCubemap()
Definition: SLSkybox.h:51
SLGLTexture * brdfLutTexture()
Definition: SLSkybox.h:53
SLGLTexture * roughnessCubemap()
Definition: SLSkybox.h:52
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Definition: Utils.cpp:1103

◆ program() [1/2]

SLGLProgram* SLMaterial::program ( )
inline

Definition at line 227 of file SLMaterial.h.

227 { return _program; }

◆ program() [2/2]

void SLMaterial::program ( SLGLProgram sp)
inline

Definition at line 205 of file SLMaterial.h.

205 { _program = sp; }

◆ programTF() [1/2]

SLGLProgram* SLMaterial::programTF ( )
inline

Definition at line 228 of file SLMaterial.h.

228 { return _programTF; }

◆ programTF() [2/2]

void SLMaterial::programTF ( SLGLProgram sp)
inline

Definition at line 206 of file SLMaterial.h.

206 { _programTF = sp; }

◆ ps() [1/2]

SLParticleSystem* SLMaterial::ps ( )
inline

Definition at line 230 of file SLMaterial.h.

230 { return _ps; }

◆ ps() [2/2]

void SLMaterial::ps ( SLParticleSystem ps)
inline

Definition at line 208 of file SLMaterial.h.

208 { _ps = ps; }

◆ reflectionModel() [1/2]

SLReflectionModel SLMaterial::reflectionModel ( )
inline

Definition at line 212 of file SLMaterial.h.

212 { return _reflectionModel; }

◆ reflectionModel() [2/2]

void SLMaterial::reflectionModel ( SLReflectionModel  rm)
inline

Definition at line 169 of file SLMaterial.h.

169 { _reflectionModel = rm; }

◆ removeTextureType()

void SLMaterial::removeTextureType ( SLTextureType  tt)
inline

Definition at line 159 of file SLMaterial.h.

160  {
161  _numTextures -= (SLint)_textures[tt].size();
162  _textures[tt].clear();
163  }
int SLint
Definition: SL.h:170

◆ roughness() [1/2]

SLfloat SLMaterial::roughness ( ) const
inline

Definition at line 218 of file SLMaterial.h.

218 { return _roughness; }

◆ roughness() [2/2]

void SLMaterial::roughness ( SLfloat  r)
inline

Definition at line 182 of file SLMaterial.h.

182 { _roughness = Utils::clamp(r, 0.0f, 1.0f); }

◆ shininess() [1/2]

SLfloat SLMaterial::shininess ( ) const
inline

Definition at line 217 of file SLMaterial.h.

217 { return _shininess; }

◆ shininess() [2/2]

void SLMaterial::shininess ( SLfloat  shin)
inline

Definition at line 177 of file SLMaterial.h.

178  {
179  if (shin < 0.0f) shin = 0.0;
180  _shininess = shin;
181  }

◆ skybox() [1/2]

SLSkybox* SLMaterial::skybox ( )
inline

Definition at line 229 of file SLMaterial.h.

229 { return _skybox; }

◆ skybox() [2/2]

void SLMaterial::skybox ( SLSkybox sb)
inline

Definition at line 207 of file SLMaterial.h.

207 { _skybox = sb; }

◆ specular() [1/2]

SLCol4f SLMaterial::specular ( )
inline

Definition at line 215 of file SLMaterial.h.

215 { return _specular; }

◆ specular() [2/2]

void SLMaterial::specular ( const SLCol4f spec)
inline

Definition at line 173 of file SLMaterial.h.

173 { _specular = spec; }

◆ textures()

SLVGLTexture& SLMaterial::textures ( SLTextureType  type)
inline

Definition at line 233 of file SLMaterial.h.

233 { return _textures[type]; }

◆ textures3d()

SLVGLTexture& SLMaterial::textures3d ( )
inline

Definition at line 234 of file SLMaterial.h.

234 { return _textures3d; }

◆ texturesString()

SLstring SLMaterial::texturesString ( )

Returns a unique string that represent all textures used.

Definition at line 687 of file SLMaterial.cpp.

688 {
689  SLstring texStr;
690  for (SLuint iTT = 0; iTT < TT_numTextureType; ++iTT)
691  {
692  for (SLuint iT = 0; iT < _textures[iTT].size(); ++iT)
693  {
694  texStr += "-" +
695  _textures[iTT][iT]->typeShortName() +
696  std::to_string(iT) +
697  std::to_string(_textures[iTT][iT]->uvIndex());
698  }
699  }
700  if (_skybox)
701  texStr += "-Sky";
702 
703  return texStr;
704 }
string SLstring
Definition: SL.h:158

◆ translucency() [1/2]

SLfloat SLMaterial::translucency ( ) const
inline

Definition at line 221 of file SLMaterial.h.

221 { return _translucency; }

◆ translucency() [2/2]

void SLMaterial::translucency ( SLfloat  transl)
inline

Definition at line 176 of file SLMaterial.h.

176 { _translucency = transl; }

◆ transmissive() [1/2]

SLCol4f SLMaterial::transmissive ( )
inline

Definition at line 220 of file SLMaterial.h.

220 { return _transmissive; }
SLCol4f _transmissive
transmissive color (RGB reflection coefficients) for path tracing
Definition: SLMaterial.h:250

◆ transmissive() [2/2]

void SLMaterial::transmissive ( const SLCol4f transm)
inline

Definition at line 175 of file SLMaterial.h.

175 { _transmissive = transm; }

◆ usesUVIndex()

SLbool SLMaterial::usesUVIndex ( SLbyte  uvIndex)

Returns true if the specified uvIndex is used by one of the textures.

Definition at line 707 of file SLMaterial.cpp.

708 {
709  for (SLuint iTT = 0; iTT < TT_numTextureType; ++iTT)
710  {
711  for (SLuint iT = 0; iT < _textures[iTT].size(); ++iT)
712  {
713  if (_textures[iTT][iT]->uvIndex() == uvIndex)
714  return true;
715  }
716  }
717  return false;
718 }

Member Data Documentation

◆ _ambient

SLCol4f SLMaterial::_ambient
protected

ambient color (RGB reflection coefficients)

Definition at line 243 of file SLMaterial.h.

◆ _assetManager

SLAssetManager* SLMaterial::_assetManager
protected

pointer to the asset manager (the owner) if available

Definition at line 241 of file SLMaterial.h.

◆ _compileErrorTexFilePath

SLstring SLMaterial::_compileErrorTexFilePath
protected

path to the error texture

Definition at line 267 of file SLMaterial.h.

◆ _diffuse

SLCol4f SLMaterial::_diffuse
protected

diffuse color (RGB reflection coefficients)

Definition at line 244 of file SLMaterial.h.

◆ _emissive

SLCol4f SLMaterial::_emissive
protected

emissive color coefficients

Definition at line 246 of file SLMaterial.h.

◆ _errorTexture

SLGLTexture* SLMaterial::_errorTexture = nullptr
protected

pointer to error texture that is shown if another texture fails

Definition at line 266 of file SLMaterial.h.

◆ _getsShadows

SLbool SLMaterial::_getsShadows
protected

true if shadows are visible on this material

Definition at line 255 of file SLMaterial.h.

◆ _kn

SLfloat SLMaterial::_kn {}
protected

refraction index

Definition at line 254 of file SLMaterial.h.

◆ _kr

SLfloat SLMaterial::_kr {}
protected

reflection coefficient 0.0 - 1.0 used for ray and path tracing

Definition at line 252 of file SLMaterial.h.

◆ _kt

SLfloat SLMaterial::_kt {}
protected

transmission coefficient 0.0 - 1.0 used for ray and path tracing

Definition at line 253 of file SLMaterial.h.

◆ _metalness

SLfloat SLMaterial::_metalness
protected

metallic property (0-1) in Cook-Torrance model

Definition at line 249 of file SLMaterial.h.

◆ _nodesVisible2D

SLVNode SLMaterial::_nodesVisible2D
protected

Vector of all visible 2D nodes of with this material.

Definition at line 269 of file SLMaterial.h.

◆ _nodesVisible3D

SLVNode SLMaterial::_nodesVisible3D
protected

Vector of all visible 3D nodes of with this material.

Definition at line 270 of file SLMaterial.h.

◆ _numTextures

SLint SLMaterial::_numTextures
protected

number of textures in all _textures vectors array

Definition at line 258 of file SLMaterial.h.

◆ _program

SLGLProgram* SLMaterial::_program {}
protected

pointer to a GLSL shader program

Definition at line 256 of file SLMaterial.h.

◆ _programTF

SLGLProgram* SLMaterial::_programTF {}
protected

pointer to a GLSL shader program for transformFeedback

Definition at line 257 of file SLMaterial.h.

◆ _ps

SLParticleSystem* SLMaterial::_ps
protected

pointer to a particle system

Definition at line 262 of file SLMaterial.h.

◆ _reflectionModel

SLReflectionModel SLMaterial::_reflectionModel
protected

reflection model (RM_BlinnPhong or RM_CookTorrance)

Definition at line 242 of file SLMaterial.h.

◆ _roughness

SLfloat SLMaterial::_roughness
protected

roughness property (0-1) in Cook-Torrance model

Definition at line 248 of file SLMaterial.h.

◆ _shininess

SLfloat SLMaterial::_shininess
protected

shininess exponent in Blinn-Phong model

Definition at line 247 of file SLMaterial.h.

◆ _skybox

SLSkybox* SLMaterial::_skybox
protected

pointer to the skybox

Definition at line 259 of file SLMaterial.h.

◆ _specular

SLCol4f SLMaterial::_specular
protected

specular color (RGB reflection coefficients)

Definition at line 245 of file SLMaterial.h.

◆ _textures

SLVGLTexture SLMaterial::_textures[TT_numTextureType]
protected

array of texture vectors one for each type

Definition at line 264 of file SLMaterial.h.

◆ _textures3d

SLVGLTexture SLMaterial::_textures3d
protected

texture vector for diffuse 3D textures

Definition at line 265 of file SLMaterial.h.

◆ _translucency

SLfloat SLMaterial::_translucency
protected

translucency exponent for light refraction for path tracing

Definition at line 251 of file SLMaterial.h.

◆ _transmissive

SLCol4f SLMaterial::_transmissive
protected

transmissive color (RGB reflection coefficients) for path tracing

Definition at line 250 of file SLMaterial.h.

◆ K

SLfloat SLMaterial::K
static

PM: Constant of gloss calibration (slope of point light at dist 1)

Definition at line 237 of file SLMaterial.h.

◆ PERFECT

SLfloat SLMaterial::PERFECT = 1000.0f
static

PM: shininess/translucency limit.

Definition at line 238 of file SLMaterial.h.


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