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

Class for demo scene with all shadow mapping types. More...

#include <AppDemoSceneShadowLightTypes.h>

Inheritance diagram for AppDemoSceneShadowLightTypes:
[legend]

Public Member Functions

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

SLNode_teapot
 

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 demo scene with all shadow mapping types.

Definition at line 20 of file AppDemoSceneShadowLightTypes.h.

Constructor & Destructor Documentation

◆ AppDemoSceneShadowLightTypes()

AppDemoSceneShadowLightTypes::AppDemoSceneShadowLightTypes ( )

Definition at line 22 of file AppDemoSceneShadowLightTypes.cpp.

23  : SLScene("Shadow Mapping Types Demo Scene")
24 {
25  info("Shadow Mapping is implemented for these light types.");
26 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneShadowLightTypes::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 37 of file AppDemoSceneShadowLightTypes.cpp.

38 {
39  SLMaterial* mat1 = new SLMaterial(am, "mat1");
40 
41  // Base root group node for the scene
42  SLNode* scene = new SLNode;
43  this->root3D(scene);
44 
45  SLCamera* cam1 = new SLCamera("Camera 1");
46  cam1->translation(0, 2, 20);
47  cam1->lookAt(0, 2, 0);
48  cam1->focalDist(20);
49  cam1->background().colors(SLCol4f(0.1f, 0.1f, 0.1f));
50  cam1->setInitialState();
51  scene->addChild(cam1);
52 
53  // Create light sources
54  vector<SLLight*> lights = {
55  new SLLightDirect(am, this),
56  new SLLightRect(am, this),
57  new SLLightSpot(am, this, 0.3f, 25.0f),
58  new SLLightSpot(am, this, 0.1f, 180.0f)};
59 
60  for (SLint i = 0; i < lights.size(); ++i)
61  {
62  SLLight* light = lights[i];
63  SLNode* node = dynamic_cast<SLNode*>(light);
64  SLfloat x = ((float)i - ((SLfloat)lights.size() - 1.0f) / 2.0f) * 5;
65 
66  if (i == 0) // Make direct light less bright
67  {
68  light->powers(0.0f, 0.4f, 0.4f);
69  light->attenuation(1, 0, 0);
70  }
71  else
72  {
73  light->powers(0.0f, 2.0f, 2.0f);
74  light->attenuation(0, 0, 1);
75  }
76 
77  node->translation(x, 5, 0);
78  node->lookAt(x, 0, 0);
79  light->createsShadows(true);
80  light->createShadowMap();
81  light->shadowMap()->rayCount(SLVec2i(16, 16));
82  scene->addChild(node);
83  }
84 
85  SLAnimation* teapotAnim = this->animManager().createNodeAnimation("teapot_anim",
86  8.0f,
87  true,
88  EC_linear,
89  AL_loop);
90 
91  for (SLLight* light : lights)
92  {
93  SLNode* teapot = _teapot->copyRec();
94 
95  teapot->translate(light->positionWS().x, 2, 0);
96  teapot->children()[0]->castsShadows(true);
97  scene->addChild(teapot);
98 
99  // Create animation
100  SLNodeAnimTrack* track = teapotAnim->createNodeAnimTrack();
101  track->animatedNode(teapot);
102 
103  SLTransformKeyframe* frame0 = track->createNodeKeyframe(0.0f);
104  frame0->translation(teapot->translationWS());
105  frame0->rotation(SLQuat4f(0, 0, 0));
106 
107  SLTransformKeyframe* frame1 = track->createNodeKeyframe(4.0f);
108  frame1->translation(teapot->translationWS());
109  frame1->rotation(SLQuat4f(0, 1 * PI, 0));
110 
111  SLTransformKeyframe* frame2 = track->createNodeKeyframe(8.0f);
112  frame2->translation(teapot->translationWS());
113  frame2->rotation(SLQuat4f(0, 2 * PI, 0));
114  }
115 
116  // Add a box which receives shadows
117  SLfloat minx = lights.front()->positionWS().x - 3;
118  SLfloat maxx = lights.back()->positionWS().x + 3;
119  SLNode* boxNode = new SLNode(new SLBox(am,
120  minx,
121  -1,
122  -5,
123  maxx,
124  0,
125  5,
126  "Box",
127  mat1));
128  boxNode->castsShadows(false);
129  scene->addChild(boxNode);
130 
131  sv->camera(cam1);
132 }
float SLfloat
Definition: SL.h:173
int SLint
Definition: SL.h:170
@ EC_linear
linear easing with constant velocity
Definition: SLEnums.h:181
@ AL_loop
loop
Definition: SLEnums.h:169
SLQuat4< SLfloat > SLQuat4f
Definition: SLQuat4.h:846
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
SLAnimation * createNodeAnimation(SLfloat duration)
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
SLNodeAnimTrack * createNodeAnimTrack()
Definition: SLAnimation.cpp:94
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Axis aligned box mesh.
Definition: SLBox.h:31
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
Abstract Light class for OpenGL light sources.
Definition: SLLight.h:61
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
void shadowMap(SLShadowMap *shadowMap)
Definition: SLLight.h:125
virtual SLVec4f positionWS() const =0
virtual void createShadowMap(float lightClipNear=0.1f, float lightClipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024))=0
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
void powers(SLfloat ambiPow, SLfloat diffPow, SLfloat specPow, const SLCol4f &ambiDiffSpecCol=SLCol4f::WHITE)
Sets the ambient, diffuse and specular powers all with the same color.
Definition: SLLight.h:74
Light node class for a rectangular light source.
Definition: SLLightRect.h:39
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
Specialized animation track for node animations.
Definition: SLAnimTrack.h:66
void animatedNode(SLNode *target)
Definition: SLAnimTrack.h:73
SLTransformKeyframe * createNodeKeyframe(SLfloat time)
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
SLVNode & children()
Definition: SLNode.h:305
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
void castsShadows(SLbool castsShadows)
Definition: SLNode.h:282
virtual SLNode * copyRec()
Definition: SLNode.cpp:572
SLVec3f translationWS() const
Definition: SLNode.h:531
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
SLVLight & lights()
Definition: SLScene.h:107
friend class SLNode
Definition: SLScene.h:48
SLAnimManager & animManager()
Definition: SLScene.h:97
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
SLTransformKeyframe is a specialized SLKeyframe for node transformations.
void translation(const SLVec3f &t)
void rotation(const SLQuat4f &r)
T x
Definition: SLVec4.h:32
static const float PI
Definition: Utils.h:237

◆ registerAssetsToLoad()

void AppDemoSceneShadowLightTypes::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 29 of file AppDemoSceneShadowLightTypes.cpp.

30 {
33  "FBX/Teapot/Teapot.fbx");
34 }
static SLstring modelPath
Path to 3D models.
Definition: AppCommon.h:85
void addNodeToLoad(SLNode *&node, const SLstring &modelPath, SLSkybox *skybox=nullptr, SLbool deleteTexImgAfterBuild=false, SLbool loadMeshesOnly=true, SLMaterial *overrideMat=nullptr, float ambientFactor=0.5f, SLbool forceCookTorranceRM=false, SLuint flags=SLProcess_Triangulate|SLProcess_JoinIdenticalVertices|SLProcess_RemoveRedundantMaterials|SLProcess_FindDegenerates|SLProcess_FindInvalidData|SLProcess_SplitLargeMeshes)
Add mesh from file to load via assimp loader.

Member Data Documentation

◆ _teapot

SLNode* AppDemoSceneShadowLightTypes::_teapot
private

Definition at line 45 of file AppDemoSceneShadowLightTypes.h.


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