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

Class for the ray tracing scene with sphere group. More...

#include <AppDemoSceneRTSpheres.h>

Inheritance diagram for AppDemoSceneRTSpheres:
[legend]

Public Member Functions

 AppDemoSceneRTSpheres (SLSceneID sceneID)
 
void registerAssetsToLoad (SLAssetLoader &al) override
 All assets the should be loaded in parallel must be registered in here. More...
 
void assemble (SLAssetManager *am, SLSceneView *sv) override
 After parallel loading of the assets the scene gets assembled in here. More...
 
SLNodeSphereGroupRT (SLAssetManager *am, SLint depth, SLfloat x, SLfloat y, SLfloat z, SLfloat scale, SLuint resolution, SLMaterial *matGlass, SLMaterial *matRed)
 Creates a recursive sphere group used for the ray tracing scenes. 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

SLSceneID _sceneID
 

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 the ray tracing scene with sphere group.

Definition at line 20 of file AppDemoSceneRTSpheres.h.

Constructor & Destructor Documentation

◆ AppDemoSceneRTSpheres()

AppDemoSceneRTSpheres::AppDemoSceneRTSpheres ( SLSceneID  sceneID)

Definition at line 22 of file AppDemoSceneRTSpheres.cpp.

23  : SLScene("Ray Tracing Spheres"),
25 {
26  if (sceneID == SID_RTSpheres)
27  info("Classic ray tracing scene with transparent and reflective "
28  "spheres. Be patient on mobile devices.");
29  else if (sceneID == SID_RTSoftShadows)
30  {
31  name("Soft Shadow Ray Tracing");
32  info("Ray tracing with soft shadow light sampling. Each light "
33  "source is sampled 64x per pixel. Be patient on mobile devices.");
34  }
35  else
36  SL_EXIT_MSG("Should not get here!");
37 }
@ SID_RTSoftShadows
@ SID_RTSpheres
#define SL_EXIT_MSG(message)
Definition: SL.h:240
SLScene SLSceneView SLint sceneID
Definition: SLScene.h:33
const SLstring & name() const
Definition: SLObject.h:38
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

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

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

Reimplemented from SLScene.

Definition at line 45 of file AppDemoSceneRTSpheres.cpp.

46 {
47 
48  if (_sceneID == SID_RTSpheres)
49  {
50  // define materials
51  SLMaterial* matGla = new SLMaterial(am,
52  "Glass",
53  SLCol4f(0.0f, 0.0f, 0.0f),
54  SLCol4f(0.5f, 0.5f, 0.5f),
55  100,
56  0.4f,
57  0.6f,
58  1.5f);
59  SLMaterial* matRed = new SLMaterial(am,
60  "Red",
61  SLCol4f(0.5f, 0.0f, 0.0f),
62  SLCol4f(0.5f, 0.5f, 0.5f),
63  100,
64  0.5f,
65  0.0f,
66  1.0f);
67  SLMaterial* matYel = new SLMaterial(am,
68  "Floor",
69  SLCol4f(0.8f, 0.6f, 0.2f),
70  SLCol4f(0.8f, 0.8f, 0.8f),
71  100,
72  0.5f,
73  0.0f,
74  1.0f);
75 
76  SLCamera* cam1 = new SLCamera();
77  cam1->translation(0, 0.1f, 2.5f);
78  cam1->lookAt(0, 0, 0);
79  cam1->focalDist(cam1->translationOS().length());
80  cam1->background().colors(SLCol4f(0.1f, 0.4f, 0.8f));
81  cam1->setInitialState();
83 
84  SLNode* rect = new SLNode(new SLRectangle(am,
85  SLVec2f(-3, -3),
86  SLVec2f(5, 4),
87  20,
88  20,
89  "Floor",
90  matYel));
91  rect->rotate(90, -1, 0, 0);
92  rect->translate(0, -1, -0.5f, TS_object);
93 
94  SLLightSpot* light1 = new SLLightSpot(am,
95  this,
96  2,
97  2,
98  2,
99  0.1f);
100  light1->powers(1, 7, 7);
101  light1->attenuation(0, 0, 1);
102 
103  SLLightSpot* light2 = new SLLightSpot(am,
104  this,
105  2,
106  2,
107  -2,
108  0.1f);
109  light2->powers(1, 7, 7);
110  light2->attenuation(0, 0, 1);
111 
112  SLNode* scene = new SLNode;
113  sv->camera(cam1);
114  scene->addChild(light1);
115  scene->addChild(light2);
116  scene->addChild(SphereGroupRT(am,
117  3,
118  0,
119  0,
120  0,
121  1,
122  30,
123  matGla,
124  matRed));
125  scene->addChild(rect);
126  scene->addChild(cam1);
127 
128  root3D(scene);
129  }
130  else if (_sceneID == SID_RTSoftShadows)
131  {
132  // Create root node
133  SLNode* scene = new SLNode;
134  root3D(scene);
135 
136  // define materials
137  SLCol4f spec(0.8f, 0.8f, 0.8f);
138  SLMaterial* matBlk = new SLMaterial(am,
139  "Glass",
140  SLCol4f(0.0f, 0.0f, 0.0f),
141  SLCol4f(0.5f, 0.5f, 0.5f),
142  100,
143  0.5f,
144  0.5f,
145  1.5f);
146  SLMaterial* matRed = new SLMaterial(am,
147  "Red",
148  SLCol4f(0.5f, 0.0f, 0.0f),
149  SLCol4f(0.5f, 0.5f, 0.5f),
150  100,
151  0.5f,
152  0.0f,
153  1.0f);
154  SLMaterial* matYel = new SLMaterial(am,
155  "Floor",
156  SLCol4f(0.8f, 0.6f, 0.2f),
157  SLCol4f(0.8f, 0.8f, 0.8f),
158  100,
159  0.0f,
160  0.0f,
161  1.0f);
162 
163  SLCamera* cam1 = new SLCamera;
164  cam1->translation(0, 0.1f, 4);
165  cam1->lookAt(0, 0, 0);
166  cam1->focalDist(cam1->translationOS().length());
167  cam1->background().colors(SLCol4f(0.1f, 0.4f, 0.8f));
168  cam1->setInitialState();
170  scene->addChild(cam1);
171 
172  SLNode* rect = new SLNode(new SLRectangle(am,
173  SLVec2f(-5, -5),
174  SLVec2f(5, 5),
175  1,
176  1,
177  "Rect",
178  matYel));
179  rect->rotate(90, -1, 0, 0);
180  rect->translate(0, 0, -0.5f);
181  rect->castsShadows(false);
182  scene->addChild(rect);
183 
184  SLLightSpot* light1 = new SLLightSpot(am,
185  this,
186  2,
187  2,
188  2,
189  0.3f);
190  light1->samples(8, 8);
191  light1->attenuation(0, 0, 1);
192  light1->createsShadows(true);
193  light1->createShadowMap();
194  scene->addChild(light1);
195 
196  SLLightSpot* light2 = new SLLightSpot(am,
197  this,
198  2,
199  2,
200  -2,
201  0.3f);
202  light2->samples(8, 8);
203  light2->attenuation(0, 0, 1);
204  light2->createsShadows(true);
205  light2->createShadowMap();
206  scene->addChild(light2);
207 
208  scene->addChild(SphereGroupRT(am,
209  1,
210  0,
211  0,
212  0,
213  1,
214  32,
215  matBlk,
216  matRed));
217 
218  sv->camera(cam1);
219  }
220 }
@ TS_object
Definition: SLEnums.h:210
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
SLNode * SphereGroupRT(SLAssetManager *am, SLint depth, SLfloat x, SLfloat y, SLfloat z, SLfloat scale, SLuint resolution, SLMaterial *matGlass, SLMaterial *matRed)
Creates a recursive sphere group used for the ray tracing scenes.
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
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
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 samples(SLuint x, SLuint y)
Definition: SLLightSpot.h:77
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 rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
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
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

◆ registerAssetsToLoad()

void AppDemoSceneRTSpheres::registerAssetsToLoad ( SLAssetLoader al)
overridevirtual

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

Reimplemented from SLScene.

Definition at line 40 of file AppDemoSceneRTSpheres.cpp.

41 {
42 }

◆ SphereGroupRT()

SLNode * AppDemoSceneRTSpheres::SphereGroupRT ( SLAssetManager am,
SLint  depth,
SLfloat  x,
SLfloat  y,
SLfloat  z,
SLfloat  scale,
SLuint  resolution,
SLMaterial matGlass,
SLMaterial matRed 
)

Creates a recursive sphere group used for the ray tracing scenes.

Definition at line 223 of file AppDemoSceneRTSpheres.cpp.

232 {
233 
234  SLstring name = matGlass->kt() > 0 ? "GlassSphere" : "RedSphere";
235  if (depth == 0)
236  {
237  SLSphere* sphere = new SLSphere(am, 0.5f * scale, resolution, resolution, name, matRed);
238  SLNode* sphNode = new SLNode(sphere, "Sphere");
239  sphNode->translate(x, y, z, TS_object);
240  return sphNode;
241  }
242  else
243  {
244  depth--;
245  SLNode* sGroup = new SLNode(new SLSphere(am, 0.5f * scale, resolution, resolution, name, matGlass), "SphereGroupRT");
246  sGroup->translate(x, y, z, TS_object);
247  SLuint newRes = (SLuint)std::max((SLint)resolution - 4, 8);
248  sGroup->addChild(SphereGroupRT(am, depth, 0.643951f * scale, 0, 0.172546f * scale, scale / 3, newRes, matRed, matRed));
249  sGroup->addChild(SphereGroupRT(am, depth, 0.172546f * scale, 0, 0.643951f * scale, scale / 3, newRes, matRed, matRed));
250  sGroup->addChild(SphereGroupRT(am, depth, -0.471405f * scale, 0, 0.471405f * scale, scale / 3, newRes, matRed, matRed));
251  sGroup->addChild(SphereGroupRT(am, depth, -0.643951f * scale, 0, -0.172546f * scale, scale / 3, newRes, matRed, matRed));
252  sGroup->addChild(SphereGroupRT(am, depth, -0.172546f * scale, 0, -0.643951f * scale, scale / 3, newRes, matRed, matRed));
253  sGroup->addChild(SphereGroupRT(am, depth, 0.471405f * scale, 0, -0.471405f * scale, scale / 3, newRes, matRed, matRed));
254  sGroup->addChild(SphereGroupRT(am, depth, 0.272166f * scale, 0.544331f * scale, 0.272166f * scale, scale / 3, newRes, matRed, matRed));
255  sGroup->addChild(SphereGroupRT(am, depth, -0.371785f * scale, 0.544331f * scale, 0.099619f * scale, scale / 3, newRes, matRed, matRed));
256  sGroup->addChild(SphereGroupRT(am, depth, 0.099619f * scale, 0.544331f * scale, -0.371785f * scale, scale / 3, newRes, matRed, matRed));
257  return sGroup;
258  }
259 }
unsigned int SLuint
Definition: SL.h:171
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
void kt(SLfloat kt)
Definition: SLMaterial.h:190
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33

Member Data Documentation

◆ _sceneID

SLSceneID AppDemoSceneRTSpheres::_sceneID
private

Definition at line 36 of file AppDemoSceneRTSpheres.h.


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