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

Class for demo scene for point light shadow mapping. More...

#include <AppDemoSceneShadowLightPoint.h>

Inheritance diagram for AppDemoSceneShadowLightPoint:
[legend]

Public Member Functions

 AppDemoSceneShadowLightPoint ()
 
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 point light shadow mapping.

Definition at line 20 of file AppDemoSceneShadowLightPoint.h.

Constructor & Destructor Documentation

◆ AppDemoSceneShadowLightPoint()

AppDemoSceneShadowLightPoint::AppDemoSceneShadowLightPoint ( )

Definition at line 22 of file AppDemoSceneShadowLightPoint.cpp.

23  : SLScene("Shadow Mapping for point lights")
24 {
25  info("Point lights use cubemaps to store shadow maps.");
26 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneShadowLightPoint::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 34 of file AppDemoSceneShadowLightPoint.cpp.

35 {
36  // Setup shadow mapping material
37  SLMaterial* matPerPixSM = new SLMaterial(am, "m1");
38 
39  // Base root group node for the scene
40  SLNode* scene = new SLNode;
41  this->root3D(scene);
42 
43  // Create camera
44  SLCamera* cam1 = new SLCamera;
45  cam1->translation(0, 0, 8);
46  cam1->lookAt(0, 0, 0);
47  cam1->fov(27);
48  cam1->focalDist(cam1->translationOS().length());
49  cam1->background().colors(SLCol4f(0.1f, 0.1f, 0.1f));
50  cam1->setInitialState();
52 
53  // Create lights
54  SLAnimation* anim = this->animManager().createNodeAnimation("light_anim", 4.0f);
55 
56  for (SLint i = 0; i < 3; ++i)
57  {
58  SLLightSpot* light = new SLLightSpot(am, this, 0.1f);
59  light->powers(0.2f,
60  1.5f,
61  1.0f,
62  SLCol4f(i == 0, i == 1, i == 2));
63  light->attenuation(0, 0, 1);
64  light->translate((float)i - 1.0f, (float)i - 1.0f, (float)i - 1.0f);
65  light->createsShadows(true);
66  light->createShadowMap();
67  light->shadowMap()->rayCount(SLVec2i(16, 16));
68  scene->addChild(light);
70  0.2f,
71  A_x,
72  0.2f,
73  A_z);
74  }
75 
76  // Create wall polygons
77  SLfloat pL = -1.48f, pR = 1.48f; // left/right
78  SLfloat pB = -1.25f, pT = 1.19f; // bottom/top
79  SLfloat pN = 1.79f, pF = -1.55f; // near/far
80 
81  // Bottom plane
82  SLNode* b = new SLNode(new SLRectangle(am,
83  SLVec2f(pL, -pN),
84  SLVec2f(pR, -pF),
85  6,
86  6,
87  "bottom",
88  matPerPixSM));
89  b->rotate(90, -1, 0, 0);
90  b->translate(0, 0, pB, TS_object);
91  scene->addChild(b);
92 
93  // Top plane
94  SLNode* t = new SLNode(new SLRectangle(am,
95  SLVec2f(pL, pF),
96  SLVec2f(pR, pN),
97  6,
98  6,
99  "top",
100  matPerPixSM));
101  t->rotate(90, 1, 0, 0);
102  t->translate(0, 0, -pT, TS_object);
103  scene->addChild(t);
104 
105  // Far plane
106  SLNode* f = new SLNode(new SLRectangle(am,
107  SLVec2f(pL, pB),
108  SLVec2f(pR, pT),
109  6,
110  6,
111  "far",
112  matPerPixSM));
113  f->translate(0, 0, pF, TS_object);
114  scene->addChild(f);
115 
116  // near plane
117  SLNode* n = new SLNode(new SLRectangle(am,
118  SLVec2f(pL, pT),
119  SLVec2f(pR, pB),
120  6,
121  6,
122  "near",
123  matPerPixSM));
124  n->translate(0, 0, pN, TS_object);
125  scene->addChild(n);
126 
127  // left plane
128  SLNode* l = new SLNode(new SLRectangle(am,
129  SLVec2f(-pN, pB),
130  SLVec2f(-pF, pT),
131  6,
132  6,
133  "left",
134  matPerPixSM));
135  l->rotate(90, 0, 1, 0);
136  l->translate(0, 0, pL, TS_object);
137  scene->addChild(l);
138 
139  // Right plane
140  SLNode* r = new SLNode(new SLRectangle(am,
141  SLVec2f(pF, pB),
142  SLVec2f(pN, pT),
143  6,
144  6,
145  "right",
146  matPerPixSM));
147  r->rotate(90, 0, -1, 0);
148  r->translate(0, 0, -pR, TS_object);
149  scene->addChild(r);
150 
151  // Create cubes which cast shadows
152  for (SLint i = 0; i < 64; ++i)
153  {
154  SLBox* box = new SLBox(am);
155  box->mat(matPerPixSM);
156  SLNode* boxNode = new SLNode(box);
157 
158  boxNode->scale(Utils::random(0.01f, 0.1f));
159  boxNode->translate(Utils::random(pL + 0.3f, pR - 0.3f),
160  Utils::random(pB + 0.3f, pT - 0.3f),
161  Utils::random(pF + 0.3f, pN - 0.3f),
162  TS_world);
163  boxNode->castsShadows(true);
164 
165  scene->addChild(boxNode);
166  }
167 
168  sv->camera(cam1);
169 }
float SLfloat
Definition: SL.h:173
int SLint
Definition: SL.h:170
@ A_z
Definition: SLEnums.h:82
@ A_x
Definition: SLEnums.h:80
@ TS_world
Definition: SLEnums.h:208
@ TS_object
Definition: SLEnums.h:210
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
static SLDeviceRotation devRot
Mobile device rotation from IMU.
Definition: AppCommon.h:64
static SLDeviceLocation devLoc
Mobile device location from GPS.
Definition: AppCommon.h:65
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 devRotLoc(SLDeviceRotation *devRot, SLDeviceLocation *devLoc)
Definition: SLCamera.h:120
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
void fov(const SLfloat fov)
vertical field of view
Definition: SLCamera.h:98
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
SLMaterial * mat() const
Definition: SLMesh.h:177
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 rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
void scale(SLfloat s)
Definition: SLNode.h:640
void castsShadows(SLbool castsShadows)
Definition: SLNode.h:282
SLVec3f translationOS() const
Definition: SLNode.h:468
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
SLRectangle creates a rectangular mesh with a certain resolution.
Definition: SLRectangle.h:29
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
T length() const
Definition: SLVec3.h:122
float random(float min, float max)
Returns a uniform distributed random float number between min and max.
Definition: Utils.h:265

◆ registerAssetsToLoad()

void AppDemoSceneShadowLightPoint::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 AppDemoSceneShadowLightPoint.cpp.

30 {
31 }

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