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

Class for demo scene for spotlight shadow mapping. More...

#include <AppDemoSceneShadowLightSpot.h>

Inheritance diagram for AppDemoSceneShadowLightSpot:
[legend]

Public Member Functions

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

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 for spotlight shadow mapping.

Definition at line 20 of file AppDemoSceneShadowLightSpot.h.

Constructor & Destructor Documentation

◆ AppDemoSceneShadowLightSpot()

AppDemoSceneShadowLightSpot::AppDemoSceneShadowLightSpot ( )

Definition at line 21 of file AppDemoSceneShadowLightSpot.cpp.

22  : SLScene("Shadow Mapping for 8 Spot lights")
23 {
24  info("8 Spot lights use a perspective projection for their light space.");
25 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneShadowLightSpot::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 33 of file AppDemoSceneShadowLightSpot.cpp.

34 {
35  // Setup shadow mapping material
36  SLMaterial* matPerPixSM = new SLMaterial(am, "m1");
37 
38  // Base root group node for the scene
39  SLNode* scene = new SLNode;
40  this->root3D(scene);
41 
42  SLCamera* cam1 = new SLCamera("Camera 1");
43  cam1->translation(0, 5, 13);
44  cam1->lookAt(0, 1, 0);
45  cam1->focalDist(8);
46  cam1->background().colors(SLCol4f(0.1f, 0.1f, 0.1f));
47  cam1->setInitialState();
48  scene->addChild(cam1);
49 
50  // Create light sources
51  for (int i = 0; i < SL_MAX_LIGHTS; ++i)
52  {
53  SLLightSpot* light = new SLLightSpot(am,
54  this,
55  0.3f,
56  45.0f);
57  SLCol4f color;
58  color.hsva2rgba(SLVec4f(Utils::TWOPI * (float)i / (float)SL_MAX_LIGHTS,
59  1.0f,
60  1.0f));
61  light->powers(0.0f, 5.0f, 5.0f, color);
62  light->translation(2 * sin((Utils::TWOPI / (float)SL_MAX_LIGHTS) * (float)i),
63  5,
64  2 * cos((Utils::TWOPI / (float)SL_MAX_LIGHTS) * (float)i));
65  light->lookAt(0, 0, 0);
66  light->attenuation(0, 0, 1);
67  light->createsShadows(true);
68  light->createShadowMap();
69  light->shadowMap()->rayCount(SLVec2i(16, 16));
70  scene->addChild(light);
71  }
72 
73  // Add a sphere which casts shadows
74  SLNode* sphereNode = new SLNode(new SLSpheric(am,
75  1,
76  0,
77  180,
78  20,
79  20,
80  "Sphere",
81  matPerPixSM));
82  sphereNode->translate(0, 2.0, 0);
83  sphereNode->castsShadows(true);
84  scene->addChild(sphereNode);
85 
86  SLAnimation* anim = this->animManager().createNodeAnimation("sphere_anim",
87  2.0f);
88  anim->createNodeAnimTrackForEllipse(sphereNode,
89  1.0f,
90  A_x,
91  1.0f,
92  A_z);
93 
94  // Add a box which receives shadows
95  SLNode* boxNode = new SLNode(new SLBox(am,
96  -5,
97  -1,
98  -5,
99  5,
100  0,
101  5,
102  "Box",
103  matPerPixSM));
104  boxNode->castsShadows(false);
105  scene->addChild(boxNode);
106 
107  sv->camera(cam1);
108 }
@ A_z
Definition: SLEnums.h:82
@ A_x
Definition: SLEnums.h:80
static const SLint SL_MAX_LIGHTS
max. number of used lights
Definition: SLGLState.h:49
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec4< SLfloat > SLVec4f
Definition: SLVec4.h:235
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 * createNodeAnimTrackForEllipse(SLNode *target, SLfloat radiusA, SLAxis axisA, SLfloat radiusB, SLAxis axisB)
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
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
void shadowMap(SLShadowMap *shadowMap)
Definition: SLLight.h:125
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
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
void createShadowMap(float lightClipNear=0.1f, float lightClipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024)) override
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
SLNode * root3D()
Definition: SLScene.h:99
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
SLSphere creates a sphere mesh based on SLRevolver.
Definition: SLSpheric.h:21
void hsva2rgba(const SLVec4 &hsva)
HSVA to RGBA color conversion (http://www.rapidtables.com/convert/color/hsv-to-rgb....
Definition: SLVec4.h:191
static const float TWOPI
Definition: Utils.h:240

◆ registerAssetsToLoad()

void AppDemoSceneShadowLightSpot::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 28 of file AppDemoSceneShadowLightSpot.cpp.

29 {
30 }

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