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

Class for Cook-Torrance lighting demo scene. More...

#include <AppDemoSceneShaderCook.h>

Inheritance diagram for AppDemoSceneShaderCook:
[legend]

Public Member Functions

 AppDemoSceneShaderCook ()
 
void registerAssetsToLoad (SLAssetLoader &al) override
 All scene specific assets have to be registered for async loading in here. More...
 
void assemble (SLAssetManager *am, SLSceneView *sv) override
 After parallel loading of the assets the scene gets assembled in here. More...
 
- Public Member Functions inherited from SLScene
 SLScene (const SLstring &name)
 
 ~SLScene () override
 
void initOculus (SLstring shaderDir)
 
void root3D (SLNode *root3D)
 
void root2D (SLNode *root2D)
 
void skybox (SLSkybox *skybox)
 
void stopAnimations (SLbool stop)
 
void info (SLstring i)
 
void loadTimeMS (SLfloat loadTimeMS)
 
SLAnimManageranimManager ()
 
SLAssetManagerassetManager ()
 
SLNoderoot3D ()
 
SLNoderoot2D ()
 
SLSkyboxskybox ()
 
SLstringinfo ()
 
SLfloat elapsedTimeMS () const
 
SLfloat elapsedTimeSec () const
 
SLVEventHandlereventHandlers ()
 
SLfloat loadTimeMS () const
 
SLVLightlights ()
 
SLfloat fps () const
 
AvgFloatframeTimesMS ()
 
AvgFloatupdateTimesMS ()
 
AvgFloatupdateAnimTimesMS ()
 
AvgFloatupdateAABBTimesMS ()
 
AvgFloatupdateDODTimesMS ()
 
SLNodesingleNodeSelected ()
 Returns the node if only one is selected. See also SLMesh::selectNodeMesh. More...
 
SLMeshsingleMeshFullSelected ()
 Returns the node if only one is selected. See also SLMesh::selectNodeMesh. More...
 
SLVNodeselectedNodes ()
 
SLVMeshselectedMeshes ()
 
SLbool stopAnimations () const
 
SLint numSceneCameras ()
 Returns the number of camera nodes in the scene. More...
 
SLCameranextCameraInScene (SLCamera *activeSVCam)
 Returns the next camera in the scene if there is one. More...
 
bool onUpdate (bool renderTypeIsRT, bool voxelsAreShown, bool forceCPUSkinning)
 Updates animations and AABBs. More...
 
void init (SLAssetManager *am)
 
virtual void unInit ()
 
void selectNodeMesh (SLNode *nodeToSelect, SLMesh *meshToSelect)
 Handles the full mesh selection from double-clicks. More...
 
void deselectAllNodesAndMeshes ()
 Deselects all nodes and its meshes. More...
 
SLGLOculusoculus ()
 
- 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
 

Private Attributes

SLGLProgram_sp
 
SLGLProgram_spTex
 
SLGLTexture_texC
 
SLGLTexture_texN
 
SLGLTexture_texM
 
SLGLTexture_texR
 

Additional Inherited Members

- Protected Attributes inherited from SLScene
SLVLight _lights
 Vector of all lights. More...
 
SLVEventHandler _eventHandlers
 Vector of all event handler. More...
 
SLAnimManager _animManager
 Animation manager instance. More...
 
SLAssetManager_assetManager
 Pointer to the external assetManager. More...
 
SLNode_root3D
 Root node for 3D scene. More...
 
SLNode_root2D
 Root node for 2D scene displayed in ortho projection. More...
 
SLSkybox_skybox
 pointer to skybox More...
 
SLstring _info
 scene info string More...
 
SLVNode _selectedNodes
 Vector of selected nodes. See SLMesh::selectNodeMesh. More...
 
SLVMesh _selectedMeshes
 Vector of selected meshes. See SLMesh::selectNodeMesh. More...
 
SLfloat _loadTimeMS
 time to load scene in ms More...
 
SLfloat _frameTimeMS
 Last frame time in ms. More...
 
SLfloat _lastUpdateTimeMS
 Last time after update in ms. More...
 
SLfloat _fps
 Averaged no. of frames per second. More...
 
AvgFloat _frameTimesMS
 Averaged total time per frame in ms. More...
 
AvgFloat _updateTimesMS
 Averaged time for update in ms. More...
 
AvgFloat _updateAABBTimesMS
 Averaged time for update the nodes AABB in ms. More...
 
AvgFloat _updateAnimTimesMS
 Averaged time for update the animations in ms. More...
 
AvgFloat _updateDODTimesMS
 Averaged time for update the SLEntities graph. More...
 
SLbool _stopAnimations
 Global flag for stopping all animations. More...
 
std::unique_ptr< SLGLOculus_oculus
 Oculus Rift interface. More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 

Detailed Description

Class for Cook-Torrance lighting demo scene.

Definition at line 20 of file AppDemoSceneShaderCook.h.

Constructor & Destructor Documentation

◆ AppDemoSceneShaderCook()

AppDemoSceneShaderCook::AppDemoSceneShaderCook ( )

Definition at line 21 of file AppDemoSceneShaderCook.cpp.

22  : SLScene("Cook-Torrance Shading")
23 {
24  info("Cook-Torrance reflection model. Left-Right: roughness 0.05-1, Top-Down: metallic: 1-0. "
25  "The center sphere has roughness and metallic encoded in textures. "
26  "The reflection model produces a more physically based light reflection "
27  "than the standard Blinn-Phong reflection model.");
28 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneShaderCook::assemble ( SLAssetManager am,
SLSceneView sv 
)
overridevirtual

After parallel loading of the assets the scene gets assembled in here.

Remarks
All scene-specific assets have to be loaded async by overriding SLScene::registerAssetsToLoad and SLScene::assemble. Async loading and assembling means that it happens in a parallel thread and that in there are no OpenGL calls allowed. OpenGL calls are only allowed in the main thread. It is important that all object instantiations within SLScene::assemble do NOT call any OpenGL functions (gl*) because they happen in a parallel thread. All objects that get rendered have to do their initialization when they are used the first time during rendering in the main thread.

Reimplemented from SLScene.

Definition at line 54 of file AppDemoSceneShaderCook.cpp.

55 {
56  // Base root group node for the scene
57  SLNode* scene = new SLNode;
58  this->root3D(scene);
59 
60  SLCamera* cam1 = new SLCamera("Camera 1");
61  cam1->translation(0, 0, 30);
62  cam1->lookAt(0, 0, 0);
64  cam1->focalDist(30);
65  cam1->setInitialState();
67  scene->addChild(cam1);
68 
69  // Create spheres and materials with roughness & metallic values between 0 and 1
70  const SLint nrRows = 7;
71  const SLint nrCols = 7;
72  SLfloat spacing = 2.5f;
73  SLfloat maxX = (float)(nrCols - 1) * spacing * 0.5f;
74  SLfloat maxY = (float)(nrRows - 1) * spacing * 0.5f;
75  SLfloat deltaR = 1.0f / (float)(nrRows - 1);
76  SLfloat deltaM = 1.0f / (float)(nrCols - 1);
77 
78  SLMaterial* mat[nrRows * nrCols];
79  SLint i = 0;
80  SLfloat y = -maxY;
81  for (SLint m = 0; m < nrRows; ++m)
82  {
83  SLfloat x = -maxX;
84  for (SLint r = 0; r < nrCols; ++r)
85  {
86  if (m == nrRows / 2 && r == nrCols / 2)
87  {
88  // The center sphere has roughness and metallic encoded in textures
89  mat[i] = new SLMaterial(am,
90  "CookTorranceMatTex",
91  nullptr,
92  _texC,
93  _texN,
94  _texM,
95  _texR,
96  nullptr,
97  _spTex);
98  }
99  else
100  {
101  // Cook-Torrance material without textures
102  mat[i] = new SLMaterial(am,
103  "CookTorranceMat",
104  nullptr,
105  SLCol4f::RED * 0.5f,
106  Utils::clamp((float)r * deltaR, 0.05f, 1.0f),
107  (float)m * deltaM,
108  _sp);
109  }
110 
111  SLNode* node = new SLNode(new SLSpheric(am, 1.0f, 0.0f, 180.0f, 32, 32, "Sphere", mat[i]));
112  node->translate(x, y, 0);
113  scene->addChild(node);
114  x += spacing;
115  i++;
116  }
117  y += spacing;
118  }
119 
120  // Add 5 Lights: 2 point lights, 2 directional lights and 1 spotlight in the center.
121  SLLight::gamma = 2.2f;
122  SLLightSpot* light1 = new SLLightSpot(am,
123  this,
124  -maxX,
125  maxY,
126  maxY,
127  0.2f,
128  180,
129  0,
130  1000,
131  1000);
132  light1->attenuation(0, 0, 1);
133  SLLightDirect* light2 = new SLLightDirect(am,
134  this,
135  maxX,
136  maxY,
137  maxY,
138  0.5f,
139  0,
140  10,
141  10);
142  light2->lookAt(0, 0, 0);
143  light2->attenuation(0, 0, 1);
144  SLLightSpot* light3 = new SLLightSpot(am,
145  this,
146  0,
147  0,
148  maxY,
149  0.2f,
150  36,
151  0,
152  1000,
153  1000);
154  light3->attenuation(0, 0, 1);
155  SLLightDirect* light4 = new SLLightDirect(am,
156  this,
157  -maxX,
158  -maxY,
159  maxY,
160  0.5f,
161  0,
162  10,
163  10);
164  light4->lookAt(0, 0, 0);
165  light4->attenuation(0, 0, 1);
166  SLLightSpot* light5 = new SLLightSpot(am,
167  this,
168  maxX,
169  -maxY,
170  maxY,
171  0.2f,
172  180,
173  0,
174  1000,
175  1000);
176  light5->attenuation(0, 0, 1);
177  scene->addChild(light1);
178  scene->addChild(light2);
179  scene->addChild(light3);
180  scene->addChild(light4);
181  scene->addChild(light5);
182  sv->camera(cam1);
183 }
float SLfloat
Definition: SL.h:173
int SLint
Definition: SL.h:170
static SLDeviceRotation devRot
Mobile device rotation from IMU.
Definition: AppCommon.h:64
static SLDeviceLocation devLoc
Mobile device location from GPS.
Definition: AppCommon.h:65
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
void devRotLoc(SLDeviceRotation *devRot, SLDeviceLocation *devLoc)
Definition: SLCamera.h:120
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
static SLfloat gamma
final output gamma value
Definition: SLLight.h:204
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
void setInitialState()
Definition: SLNode.cpp:1084
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.h:652
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
SLSphere creates a sphere mesh based on SLRevolver.
Definition: SLSpheric.h:21
static SLVec4 BLACK
Definition: SLVec4.h:213
static SLVec4 RED
Definition: SLVec4.h:216
T clamp(T a, T min, T max)
Definition: Utils.h:253

◆ registerAssetsToLoad()

void AppDemoSceneShaderCook::registerAssetsToLoad ( SLAssetLoader al)
overridevirtual

All scene specific assets have to be registered for async loading in here.

All assets the should be loaded in parallel must be registered in here.

Remarks
All scene sspecific assets have to be loaded async by overriding SLScene::registerAssetsToLoad and SLScene::assemble. Async loading and assembling means that it happens in a parallel thread and that in there are no OpenGL calls allowed. OpenGL calls are only allowed in the main thread.

Reimplemented from SLScene.

Definition at line 31 of file AppDemoSceneShaderCook.cpp.

32 {
35  "rusty-metal_2048_C.jpg");
38  "rusty-metal_2048_N.jpg");
41  "rusty-metal_2048_M.jpg");
44  "rusty-metal_2048_R.jpg");
46  AppCommon::shaderPath + "PerPixCook.vert",
47  AppCommon::shaderPath + "PerPixCook.frag");
49  AppCommon::shaderPath + "PerPixCookTm.vert",
50  AppCommon::shaderPath + "PerPixCookTm.frag");
51 }
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
void addProgramToLoad(SLGLProgram *&program, const SLstring &vertShaderFile, const SLstring &fragShaderFile)
Add generic GLSL program with shader files to load.
void addTextureToLoad(SLGLTexture *&texture, const SLstring &path, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT)
Add 2D textures with internal image allocation.

Member Data Documentation

◆ _sp

SLGLProgram* AppDemoSceneShaderCook::_sp
private

Definition at line 46 of file AppDemoSceneShaderCook.h.

◆ _spTex

SLGLProgram* AppDemoSceneShaderCook::_spTex
private

Definition at line 47 of file AppDemoSceneShaderCook.h.

◆ _texC

SLGLTexture* AppDemoSceneShaderCook::_texC
private

Definition at line 48 of file AppDemoSceneShaderCook.h.

◆ _texM

SLGLTexture* AppDemoSceneShaderCook::_texM
private

Definition at line 50 of file AppDemoSceneShaderCook.h.

◆ _texN

SLGLTexture* AppDemoSceneShaderCook::_texN
private

Definition at line 49 of file AppDemoSceneShaderCook.h.

◆ _texR

SLGLTexture* AppDemoSceneShaderCook::_texR
private

Definition at line 51 of file AppDemoSceneShaderCook.h.


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