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

Class for image base lighting demo scene. More...

#include <AppDemoSceneShaderIBL.h>

Inheritance diagram for AppDemoSceneShaderIBL:
[legend]

Public Member Functions

 AppDemoSceneShaderIBL ()
 
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

SLGLTexture_texC
 
SLGLTexture_texN
 
SLGLTexture_texM
 
SLGLTexture_texR
 
SLGLTexture_texA
 
SLSkybox_skybox
 

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 image base lighting demo scene.

Definition at line 20 of file AppDemoSceneShaderIBL.h.

Constructor & Destructor Documentation

◆ AppDemoSceneShaderIBL()

AppDemoSceneShaderIBL::AppDemoSceneShaderIBL ( )

Definition at line 21 of file AppDemoSceneShaderIBL.cpp.

22  : SLScene("Image Based Lighting Test Scene")
23 {
24  info("Image-based lighting from skybox using high dynamic range images. "
25  "It uses the Cook-Torrance reflection model also to calculate the "
26  "ambient light part from the surrounding HDR skybox.");
27 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneShaderIBL::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 55 of file AppDemoSceneShaderIBL.cpp.

56 {
57  // Create a scene group node
58  SLNode* scene = new SLNode("scene node");
59  this->root3D(scene);
60 
61  // Create camera and initialize its parameters
62  SLCamera* cam1 = new SLCamera("Camera 1");
63  cam1->translation(0, 0, 30);
64  cam1->lookAt(0, 0, 0);
65  cam1->background().colors(SLCol4f(0.2f, 0.2f, 0.2f));
66  cam1->focalDist(30);
67  cam1->setInitialState();
68  scene->addChild(cam1);
69 
70  // Add directional light with a position that corresponds roughly to the sun direction
71  SLLight::gamma = 2.2f;
72  SLLightDirect* light1 = new SLLightDirect(am,
73  this,
74  4.0f,
75  .3f,
76  2.0f,
77  0.5f,
78  0,
79  1,
80  1);
81  light1->lookAt(0, 0, 0);
82  light1->attenuation(1, 0, 0);
83  light1->createsShadows(true);
84  light1->createShadowMapAutoSize(cam1, SLVec2i(2048, 2048), 4);
85  light1->shadowMap()->cascadesFactor(30.0);
86  light1->doSmoothShadows(true);
87  light1->castsShadows(false);
88  light1->shadowMinBias(0.001f);
89  light1->shadowMaxBias(0.003f);
90  scene->addChild(light1);
91 
92  // Create spheres and materials with roughness & metallic values between 0 and 1
93  const SLint nrRows = 7;
94  const SLint nrCols = 7;
95  SLfloat spacing = 2.5f;
96  SLfloat maxX = (float)((int)(nrCols / 2) * spacing);
97  SLfloat maxY = (float)((int)(nrRows / 2) * spacing);
98  SLfloat deltaR = 1.0f / (float)(nrRows - 1);
99  SLfloat deltaM = 1.0f / (float)(nrCols - 1);
100 
101  SLMaterial* mat[nrRows * nrCols];
102  SLint i = 0;
103  SLfloat y = -maxY;
104  for (SLint m = 0; m < nrRows; ++m)
105  {
106  SLfloat x = -maxX;
107  for (SLint r = 0; r < nrCols; ++r)
108  {
109  if (m == nrRows / 2 && r == nrCols / 2)
110  {
111  // The center sphere has roughness and metallic encoded in textures
112  // and the prefiltered textures for IBL
113  mat[i] = new SLMaterial(am,
114  "IBLMatTex",
115  _skybox,
116  _texC,
117  _texN,
118  _texM,
119  _texR,
120  _texA);
121  }
122  else
123  {
124  // Cook-Torrance material with IBL but without textures
125  mat[i] = new SLMaterial(am,
126  "IBLMat",
127  _skybox,
128  SLCol4f::WHITE * 0.5f,
129  Utils::clamp((float)r * deltaR, 0.05f, 1.0f),
130  (float)m * deltaM);
131  }
132 
133  SLNode* node = new SLNode(new SLSpheric(am,
134  1.0f,
135  0.0f,
136  180.0f,
137  32,
138  32,
139  "Sphere",
140  mat[i]));
141  node->translate(x, y, 0);
142  scene->addChild(node);
143  x += spacing;
144  i++;
145  }
146  y += spacing;
147  }
148 
149  sv->camera(cam1);
150  this->skybox(_skybox);
151 
152  // Save energy
153  sv->doWaitOnIdle(true);
154 }
float SLfloat
Definition: SL.h:173
int SLint
Definition: SL.h:170
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
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
void createShadowMapAutoSize(SLCamera *camera, SLVec2i texSize=SLVec2i(1024, 1024), int numCascades=4) override
static SLfloat gamma
final output gamma value
Definition: SLLight.h:204
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
void shadowMaxBias(SLfloat maxBias)
Definition: SLLight.h:129
void shadowMap(SLShadowMap *shadowMap)
Definition: SLLight.h:125
void doSmoothShadows(SLbool doSS)
Definition: SLLight.h:126
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
void shadowMinBias(SLfloat minBias)
Definition: SLLight.h:128
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 castsShadows(SLbool castsShadows)
Definition: SLNode.h:282
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
SLSkybox * skybox()
Definition: SLScene.h:101
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
void doWaitOnIdle(SLbool doWI)
Definition: SLSceneView.h:149
SLSphere creates a sphere mesh based on SLRevolver.
Definition: SLSpheric.h:21
static SLVec4 WHITE
Definition: SLVec4.h:215
T clamp(T a, T min, T max)
Definition: Utils.h:253

◆ registerAssetsToLoad()

void AppDemoSceneShaderIBL::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 30 of file AppDemoSceneShaderIBL.cpp.

31 {
34  "gold-scuffed_2048_C.png");
37  "gold-scuffed_2048_N.png");
40  "gold-scuffed_2048_M.png");
43  "gold-scuffed_2048_R.png");
46  "gold-scuffed_2048_A.png");
47 
49  al.texturePath() + "env_barce_rooftop.hdr",
50  SLVec2i(256, 256),
51  "HDR Skybox");
52 }
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
SLstring texturePath() const
Definition: SLAssetLoader.h:71
void addSkyboxToLoad(SLSkybox *&skybox, const SLstring &path, SLVec2i resolution, SLstring name)
Add skybox with HDR texture 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

◆ _skybox

SLSkybox* AppDemoSceneShaderIBL::_skybox
private

Definition at line 51 of file AppDemoSceneShaderIBL.h.

◆ _texA

SLGLTexture* AppDemoSceneShaderIBL::_texA
private

Definition at line 50 of file AppDemoSceneShaderIBL.h.

◆ _texC

SLGLTexture* AppDemoSceneShaderIBL::_texC
private

Definition at line 46 of file AppDemoSceneShaderIBL.h.

◆ _texM

SLGLTexture* AppDemoSceneShaderIBL::_texM
private

Definition at line 48 of file AppDemoSceneShaderIBL.h.

◆ _texN

SLGLTexture* AppDemoSceneShaderIBL::_texN
private

Definition at line 47 of file AppDemoSceneShaderIBL.h.

◆ _texR

SLGLTexture* AppDemoSceneShaderIBL::_texR
private

Definition at line 49 of file AppDemoSceneShaderIBL.h.


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