SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLMaterial.cpp
Go to the documentation of this file.
1 /**
2  * \file SLMaterial.cpp
3  * \date July 2014
4  * \authors Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #include <SLMaterial.h>
11 #include <SLSceneView.h>
12 #include <SLAssetManager.h>
13 #include <SLGLProgramGenerated.h>
14 #include <SLSkybox.h>
15 
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
19 /*!
20  Default constructor for Blinn-Phong reflection model materials without textures.
21  Materials can be used by multiple meshes (SLMesh). Materials can belong
22  therefore to the global assets such as meshes, materials, textures and
23  shader programs.
24  @param am Pointer to a global asset manager. If passed the asset
25  manager is the owner of the instance and will do the deallocation. If a
26  nullptr is passed the creator is responsible for the deallocation.
27  @param name Name of the material
28  @param amdi Ambient and diffuse color
29  @param spec Specular color
30  @param shininess Shininess exponent (the higher the sharper the gloss)
31  @param kr Reflection coefficient used for ray tracing. (0.0-1.0)
32  @param kt Transparency coefficient used for ray tracing. (0.0-1.0)
33  @param kn Refraction index used for ray tracing (1.0-2.5)
34  @param program Pointer to the shader program for the material.
35  If none is passed a program will be generated from the passed parameters.
36 */
38  const SLchar* name,
39  const SLCol4f& amdi,
40  const SLCol4f& spec,
41  SLfloat shininess,
42  SLfloat kr,
43  SLfloat kt,
44  SLfloat kn,
45  SLGLProgram* program) : 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 }
73 //-----------------------------------------------------------------------------
74 /*! Constructor for textured Blinn-Phong reflection model materials.
75  Materials can be used by multiple meshes (SLMesh). Materials can belong
76  therefore to the global assets such as meshes, materials, textures and
77  shader programs.
78  @param am Pointer to a global asset manager. If passed the asset
79  manager is the owner of the instance and will do the deallocation. If a
80  nullptr is passed the creator is responsible for the deallocation.
81  @param name Name of the material
82  @param texture1 Pointer to an SLGLTexture of a specific SLTextureType
83  @param texture2 Pointer to an SLGLTexture of a specific SLTextureType
84  @param texture3 Pointer to an SLGLTexture of a specific SLTextureType
85  @param texture4 Pointer to an SLGLTexture of a specific SLTextureType
86  @param program Pointer to the shader program for the material.
87  If none is passed a program will be generated from the passed parameters.
88  */
90  const SLchar* name,
91  SLGLTexture* texture1,
92  SLGLTexture* texture2,
93  SLGLTexture* texture3,
94  SLGLTexture* texture4,
95  SLGLProgram* program) : 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 }
128 //-----------------------------------------------------------------------------
129 /*! Constructor for Cook-Torrance shaded materials with roughness and metalness.
130  Materials can be used by multiple meshes (SLMesh). Materials can belong
131  therefore to the global assets such as meshes, materials, textures and
132  shader programs.
133  @param am Pointer to a global asset manager. If passed the asset manager
134  is the owner of the instance and will do the deallocation. If a nullptr
135  is passed the creator is responsible for the deallocation.
136  @param name Name of the material
137  @param skybox Pointer to the skybox if available
138  @param diffuse Diffuse reflection color
139  @param roughness Roughness (0.0-1.0)
140  @param metalness Metalness (0.0-1.0)
141  @param program Pointer to the shader program for the material.
142  If none is passed a program will be generated from the passed parameters.
143  */
145  const SLchar* name,
146  SLSkybox* skybox,
147  SLCol4f diffuse,
148  SLfloat roughness,
149  SLfloat metalness,
150  SLGLProgram* program) : 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 }
174 //-----------------------------------------------------------------------------
175 /*! Constructor for Cook-Torrance shaded materials with PBR textures.
176  Materials can be used by multiple meshes (SLMesh). Materials can belong
177  therefore to the global assets such as meshes, materials, textures and
178  shader programs.
179  @param am Pointer to a global asset manager. If passed the asset manager
180  is the owner of the instance and will do the deallocation. If a nullptr
181  is passed the creator is responsible for the deallocation.
182  @param name Name of the material
183  @param skybox Pointer to the skybox if available. If the skybox is an HDR
184  skybox it will influence the ambient and specular reflection.
185  @param texture1 Pointer to a SLGLTexture of a specific SLTextureType. For
186  PBR materials this can be TT_diffuse, TT_normal, TT_roughness, TT_metallic
187  and TT_occlusion.
188  @param texture2 Pointer to a SLGLTexture of a specific SLTextureType.
189  @param texture3 Pointer to a SLGLTexture of a specific SLTextureType.
190  @param texture4 Pointer to a SLGLTexture of a specific SLTextureType.
191  @param texture5 Pointer to a SLGLTexture of a specific SLTextureType.
192  @param program Pointer to the shader program for the material.
193  If none is passed a program will be generated from the passed parameters.
194  */
196  const SLchar* name,
197  SLSkybox* skybox,
198  SLGLTexture* texture1,
199  SLGLTexture* texture2,
200  SLGLTexture* texture3,
201  SLGLTexture* texture4,
202  SLGLTexture* texture5,
203  SLGLProgram* program) : 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 }
235 //-----------------------------------------------------------------------------
236 /*! Constructor for textured particle system materials (Draw=.
237  Materials can be used by multiple meshes (SLMesh). Materials can belong
238  therefore to the global assets such as meshes, materials, textures and
239  shader programs.
240  @param am Pointer to a global asset manager. If passed the asset
241  manager is the owner of the instance and will do the deallocation. If a
242  nullptr is passed the creator is responsible for the deallocation.
243  @param name Name of the material
244  @param texture Pointer to an SLGLTexture of a specific SLTextureType
245  @param ps Pointer to the particle system for the material.
246  @param program Pointer to the shader program for the material.
247  If none is passed a program will be generated from the passed parameters.
248  @param programTF Pointer to the shader program for Transform Feedback
249  */
251  const SLchar* name,
252  SLParticleSystem* ps,
253  SLGLTexture* texture,
254  SLGLProgram* program,
255  SLGLProgram* programTF) : 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 }
272 //-----------------------------------------------------------------------------
273 /*! Constructor for materials with only a shader program.
274  Materials can be used by multiple meshes (SLMesh). Materials can belong
275  therefore to the global assets such as meshes, materials, textures and
276  shader programs.
277  @param am Pointer to a global asset manager. If passed the asset
278  manager is the owner of the instance and will do the deallocation. If a
279  nullptr is passed the creator is responsible for the deallocation.
280  @param name Name of the material
281  @param shaderProg Pointer to the shader program for the material
282  */
284  const SLchar* name,
285  SLGLProgram* shaderProg) : 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 }
306 //-----------------------------------------------------------------------------
307 /*!
308  Constructor for uniform color material without lighting
309  Materials can be used by multiple meshes (SLMesh). Materials can belong
310  therefore to the global assets such as meshes, materials, textures and
311  shader programs.
312  @param am Pointer to a global asset manager. If passed the asset
313  manager is the owner of the instance and will do the deallocation. If a
314  nullptr is passed the creator is responsible for the deallocation.
315  @param colorUniformProgram Pointer to shader program for uniform coloring.
316  @param uniformColor Color to apply
317  @param name Name of the material
318  */
320  SLGLProgram* colorUniformProgram,
321  const SLCol4f& uniformColor,
322  const SLchar* name) : 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 }
346 //-----------------------------------------------------------------------------
347 //! Adds the passed texture to the equivalent texture type vector
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 }
360 //-----------------------------------------------------------------------------
361 /*!
362  The destructor should be called by the owner of the material. If an asset
363  manager was passed in the constructor it will do it after scene destruction.
364  The textures (SLGLTexture) and the shader program (SLGLProgram) that the
365  material uses will not be deallocated.
366 */
368 {
369  if (_errorTexture)
370  {
371  delete _errorTexture;
372  _errorTexture = nullptr;
373  }
374 }
375 //------------------------------------------------------------------------------
377 {
378  if (_program)
379  {
382  delete _program;
383  _program = nullptr;
384  }
385 }
386 //-----------------------------------------------------------------------------
387 /*!
388  If this material has not yet a shader program assigned (SLMaterial::_program)
389  a suitable program will be generated with an instance of SLGLProgramGenerated.
390  */
391 void SLMaterial::generateProgramPS(bool drawInstanced)
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 }
496 //-----------------------------------------------------------------------------
497 /*!
498  SLMaterial::activate activates this material for rendering if it is not yet
499  the active one and set as SLGLState::currentMaterial. If this material has
500  not yet a shader program assigned (SLMaterial::_program) a suitable program
501  will be generated with an instance of SLGLProgramGenerated.
502  At the end the shader program will begin its usage with SLGLProgram::beginUse.
503  @param cam Pointer to the active camera
504  @param lights Pointer to the scene vector of lights
505  @param supportsSkinning flag if skinning in shader should be supported
506  */
508  SLVLight* lights,
509  SLbool supportGPUSkinning)
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 }
558 //-----------------------------------------------------------------------------
559 //! Passes all material parameters as uniforms to the passed shader program
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 }
685 //-----------------------------------------------------------------------------
686 //! Returns a unique string that represent all textures used
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 }
705 //-----------------------------------------------------------------------------
706 //! Returns true if the specified uvIndex is used by one of the textures
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 }
719 //-----------------------------------------------------------------------------
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
char SLchar
Definition: SL.h:162
bool SLbool
Definition: SL.h:175
signed char SLbyte
Definition: SL.h:166
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
@ RM_BlinnPhong
Definition: SLEnums.h:289
@ RM_Custom
Definition: SLEnums.h:292
@ RM_Particle
Definition: SLEnums.h:291
@ RM_CookTorrance
Definition: SLEnums.h:290
@ TT_occluRoughMetal
Definition: SLGLTexture.h:87
@ TT_height
Definition: SLGLTexture.h:80
@ TT_metallic
Definition: SLGLTexture.h:85
@ TT_environmentCubemap
Definition: SLGLTexture.h:90
@ TT_roughMetal
Definition: SLGLTexture.h:86
@ TT_roughness
Definition: SLGLTexture.h:84
@ TT_specular
Definition: SLGLTexture.h:81
@ TT_numTextureType
Definition: SLGLTexture.h:95
@ TT_normal
Definition: SLGLTexture.h:79
@ TT_diffuse
Definition: SLGLTexture.h:78
@ TT_occlusion
Definition: SLGLTexture.h:83
@ TT_emissive
Definition: SLGLTexture.h:82
@ TT_font
Definition: SLGLTexture.h:88
vector< SLLight * > SLVLight
STL vector of light pointers.
Definition: SLLight.h:232
Toplevel holder of the assets meshes, materials, textures and shaders.
SLGLProgram * getProgramByName(const string &programName)
Returns the pointer to shader program if found by name.
bool removeProgram(SLGLProgram *program)
Removes the specified mesh from the meshes resource vector.
SLVMaterial & materials()
Active or visible camera node class.
Definition: SLCamera.h:54
Generated Shader Program class inherited from SLGLProgram.
static void buildProgramNamePS(SLMaterial *mat, string &programName, bool isDrawProg, bool drawInstanced)
static void buildProgramName(SLMaterial *mat, SLVLight *lights, SLbool supportGPUSkinning, string &programName)
Builds unique program name that identifies shader program.
Encapsulation of an OpenGL shader program object.
Definition: SLGLProgram.h:56
SLint uniform4fv(const SLchar *name, SLsizei count, const SLfloat *value) const
Passes 4 float values py pointer to the uniform variable "name".
void deleteDataGpu()
Delete all Gpu data.
Definition: SLGLProgram.cpp:96
SLint uniform1f(const SLchar *name, SLfloat v0) const
Passes the float value v0 to the uniform variable "name".
void initTF(const char *writeBackAttrib[], int size)
void beginUse(SLCamera *cam, SLMaterial *mat, SLVLight *lights)
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
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
SLenum target() const
Definition: SLGLTexture.h:226
void texType(SLTextureType bt)
Definition: SLGLTexture.h:200
void bindActive(SLuint texUnit=0)
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
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.
Definition: SLMaterial.cpp:37
void deleteDataGpu()
Definition: SLMaterial.cpp:376
SLstring texturesString()
Returns a unique string that represent all textures used.
Definition: SLMaterial.cpp:687
SLfloat _kr
reflection coefficient 0.0 - 1.0 used for ray and path tracing
Definition: SLMaterial.h:252
static SLfloat PERFECT
PM: shininess/translucency limit.
Definition: SLMaterial.h:238
SLVGLTexture _textures[TT_numTextureType]
array of texture vectors one for each type
Definition: SLMaterial.h:264
SLParticleSystem * ps()
Definition: SLMaterial.h:230
SLCol4f diffuse()
Definition: SLMaterial.h:214
SLAssetManager * _assetManager
pointer to the asset manager (the owner) if available
Definition: SLMaterial.h:241
SLint passToUniforms(SLGLProgram *program, SLint nextTexUnit)
Passes all material parameters as uniforms to the passed shader program.
Definition: SLMaterial.cpp:560
SLVGLTexture _textures3d
texture vector for diffuse 3D textures
Definition: SLMaterial.h:265
SLfloat kr() const
Definition: SLMaterial.h:222
SLSkybox * skybox()
Definition: SLMaterial.h:229
SLfloat _metalness
metallic property (0-1) in Cook-Torrance model
Definition: SLMaterial.h:249
SLGLProgram * _programTF
pointer to a GLSL shader program for transformFeedback
Definition: SLMaterial.h:257
SLfloat _roughness
roughness property (0-1) in Cook-Torrance model
Definition: SLMaterial.h:248
void generateProgramPS(bool drawInstanced=false)
Definition: SLMaterial.cpp:391
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 roughness() const
Definition: SLMaterial.h:218
SLfloat metalness() const
Definition: SLMaterial.h:219
void addTexture(SLGLTexture *texture)
Adds the passed texture to the equivalent texture type vector.
Definition: SLMaterial.cpp:348
void activate(SLCamera *cam, SLVLight *lights, SLbool supportGPUSkinning)
Definition: SLMaterial.cpp:507
~SLMaterial() override
Definition: SLMaterial.cpp:367
SLfloat kn() const
Definition: SLMaterial.h:224
SLfloat kt() const
Definition: SLMaterial.h:223
SLParticleSystem * _ps
pointer to a particle system
Definition: SLMaterial.h:262
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
SLbool usesUVIndex(SLbyte uvIndex)
Returns true if the specified uvIndex is used by one of the textures.
Definition: SLMaterial.cpp:707
SLReflectionModel _reflectionModel
reflection model (RM_BlinnPhong or RM_CookTorrance)
Definition: SLMaterial.h:242
SLGLTexture * _errorTexture
pointer to error texture that is shown if another texture fails
Definition: SLMaterial.h:266
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
SLGLProgram * programTF()
Definition: SLMaterial.h:228
SLstring _compileErrorTexFilePath
path to the error texture
Definition: SLMaterial.h:267
SLfloat _translucency
translucency exponent for light refraction for path tracing
Definition: SLMaterial.h:251
Base class for all other classes.
Definition: SLObject.h:23
void name(const SLstring &Name)
Definition: SLObject.h:34
const SLstring & name() const
Definition: SLObject.h:38
SLParticleSystem creates a particle meshes from a point primitive buffer.
SLbool doFlipBookTexture()
Skybox node class with a SLBox mesh.
Definition: SLSkybox.h:29
SLfloat exposure()
Definition: SLSkybox.h:54
SLGLTexture * irradianceCubemap()
Definition: SLSkybox.h:51
SLGLTexture * brdfLutTexture()
Definition: SLSkybox.h:53
SLGLTexture * roughnessCubemap()
Definition: SLSkybox.h:52
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
void clear(std::string path)
Definition: SLIOMemory.cpp:34
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Definition: Utils.cpp:1103