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

Class for the Muttenzer Box ray tracing scene. More...

#include <AppDemoSceneRTMuttenzerBox.h>

Inheritance diagram for AppDemoSceneRTMuttenzerBox:
[legend]

Public Member Functions

 AppDemoSceneRTMuttenzerBox ()
 
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_tex1
 
SLGLProgram_spRefl
 
SLGLProgram_spRefr
 

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 Muttenzer Box ray tracing scene.

Definition at line 20 of file AppDemoSceneRTMuttenzerBox.h.

Constructor & Destructor Documentation

◆ AppDemoSceneRTMuttenzerBox()

AppDemoSceneRTMuttenzerBox::AppDemoSceneRTMuttenzerBox ( )

Definition at line 21 of file AppDemoSceneRTMuttenzerBox.cpp.

22  : SLScene("Muttenzer Box Ray Tracing")
23 {
24  info("Muttenzer Box with environment mapped reflective sphere and "
25  "transparent refractive glass sphere. Try ray tracing for real "
26  "reflections and soft shadows.");
27 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneRTMuttenzerBox::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 50 of file AppDemoSceneRTMuttenzerBox.cpp.

52 {
53  SLCol4f lightEmisRGB(7.0f, 7.0f, 7.0f);
54  SLCol4f grayRGB(0.75f, 0.75f, 0.75f);
55  SLCol4f redRGB(0.75f, 0.25f, 0.25f);
56  SLCol4f blueRGB(0.25f, 0.25f, 0.75f);
57  SLCol4f blackRGB(0.00f, 0.00f, 0.00f);
58 
59  // create materials
60  SLMaterial* cream = new SLMaterial(am,
61  "cream",
62  grayRGB,
64  0);
65  SLMaterial* red = new SLMaterial(am,
66  "red",
67  redRGB,
69  0);
70  SLMaterial* blue = new SLMaterial(am,
71  "blue",
72  blueRGB,
74  0);
75 
76  // Material for mirror sphere
77  SLMaterial* refl = new SLMaterial(am,
78  "refl",
79  blackRGB,
81  1000,
82  1.0f);
83  refl->addTexture(_tex1);
84  refl->program(_spRefl);
85 
86  // Material for glass sphere
87  SLMaterial* refr = new SLMaterial(am,
88  "refr",
89  blackRGB,
90  blackRGB,
91  100,
92  0.05f,
93  0.95f,
94  1.5f);
95  refr->translucency(1000);
97  refr->addTexture(_tex1);
98  refr->program(_spRefr);
99 
100  SLNode* sphere1 = new SLNode(new SLSphere(am,
101  0.5f,
102  32,
103  32,
104  "Sphere1",
105  refl));
106  sphere1->translate(-0.65f, -0.75f, -0.55f, TS_object);
107 
108  SLNode* sphere2 = new SLNode(new SLSphere(am,
109  0.45f,
110  32,
111  32,
112  "Sphere2",
113  refr));
114  sphere2->translate(0.73f, -0.8f, 0.10f, TS_object);
115 
116  SLNode* balls = new SLNode;
117  balls->addChild(sphere1);
118  balls->addChild(sphere2);
119 
120  // Rectangular light
121  SLLightRect* lightRect = new SLLightRect(am,
122  this,
123  1,
124  0.65f);
125  lightRect->rotate(90, -1.0f, 0.0f, 0.0f);
126  lightRect->translate(0.0f, -0.25f, 1.18f, TS_object);
127  lightRect->spotCutOffDEG(90);
128  lightRect->spotExponent(1.0);
129  lightRect->ambientColor(SLCol4f::WHITE);
130  lightRect->ambientPower(0.25f);
131  lightRect->diffuseColor(lightEmisRGB);
132  lightRect->attenuation(0, 0, 1);
133  lightRect->samplesXY(11, 7);
134  lightRect->createsShadows(true);
135  lightRect->createShadowMap();
136 
137  SLLight::globalAmbient.set(lightEmisRGB * 0.01f);
138 
139  // create camera
140  SLCamera* cam1 = new SLCamera();
141  cam1->translation(0, 0, 7.2f);
142  cam1->fov(27);
143  cam1->focalDist(cam1->translationOS().length());
144  cam1->background().colors(SLCol4f(0.0f, 0.0f, 0.0f));
145  cam1->setInitialState();
147 
148  // assemble scene
149  SLNode* scene = new SLNode;
150  root3D(scene);
151  scene->addChild(cam1);
152  scene->addChild(lightRect);
153 
154  // create wall polygons
155  SLfloat pL = -1.48f, pR = 1.48f; // left/right
156  SLfloat pB = -1.25f, pT = 1.19f; // bottom/top
157  SLfloat pN = 1.79f, pF = -1.55f; // near/far
158 
159  // bottom plane
160  SLNode* b = new SLNode(new SLRectangle(am,
161  SLVec2f(pL, -pN),
162  SLVec2f(pR, -pF),
163  6,
164  6,
165  "bottom",
166  cream));
167  b->rotate(90, -1, 0, 0);
168  b->translate(0, 0, pB, TS_object);
169  scene->addChild(b);
170 
171  // top plane
172  SLNode* t = new SLNode(new SLRectangle(am,
173  SLVec2f(pL, pF),
174  SLVec2f(pR, pN),
175  6,
176  6,
177  "top",
178  cream));
179  t->rotate(90, 1, 0, 0);
180  t->translate(0, 0, -pT, TS_object);
181  scene->addChild(t);
182 
183  // far plane
184  SLNode* f = new SLNode(new SLRectangle(am,
185  SLVec2f(pL, pB),
186  SLVec2f(pR, pT),
187  6,
188  6,
189  "far",
190  cream));
191  f->translate(0, 0, pF, TS_object);
192  scene->addChild(f);
193 
194  // left plane
195  SLNode* l = new SLNode(new SLRectangle(am,
196  SLVec2f(-pN, pB),
197  SLVec2f(-pF, pT),
198  6,
199  6,
200  "left",
201  red));
202  l->rotate(90, 0, 1, 0);
203  l->translate(0, 0, pL, TS_object);
204  scene->addChild(l);
205 
206  // right plane
207  SLNode* r = new SLNode(new SLRectangle(am,
208  SLVec2f(pF, pB),
209  SLVec2f(pN, pT),
210  6,
211  6,
212  "right",
213  blue));
214  r->rotate(90, 0, -1, 0);
215  r->translate(0, 0, -pR, TS_object);
216  scene->addChild(r);
217 
218  scene->addChild(balls);
219 
220  sv->camera(cam1);
221 }
float SLfloat
Definition: SL.h:173
@ 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
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 fov(const SLfloat fov)
vertical field of view
Definition: SLCamera.h:98
void ambientColor(const SLCol4f &ambi)
Definition: SLLight.h:105
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
static SLCol4f globalAmbient
static global ambient light intensity
Definition: SLLight.h:202
void ambientPower(const SLfloat ambPow)
Definition: SLLight.h:106
void spotCutOffDEG(SLfloat cutOffAngleDEG)
Definition: SLLight.cpp:92
void diffuseColor(const SLCol4f &diff)
Definition: SLLight.h:107
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
void spotExponent(const SLfloat exp)
Definition: SLLight.h:111
Light node class for a rectangular light source.
Definition: SLLightRect.h:39
void samplesXY(SLint x, SLint y)
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
void translucency(SLfloat transl)
Definition: SLMaterial.h:176
void addTexture(SLGLTexture *texture)
Adds the passed texture to the equivalent texture type vector.
Definition: SLMaterial.cpp:348
void transmissive(const SLCol4f &transm)
Definition: SLMaterial.h:175
void program(SLGLProgram *sp)
Definition: SLMaterial.h:205
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
SLVec3f translationOS() const
Definition: SLNode.h:468
void setInitialState()
Definition: SLNode.cpp:1084
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
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33
T length() const
Definition: SLVec3.h:122
static SLVec4 BLACK
Definition: SLVec4.h:213
static SLVec4 WHITE
Definition: SLVec4.h:215
void set(const T X, const T Y, const T Z, const T W=1)
Definition: SLVec4.h:49

◆ registerAssetsToLoad()

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

31 {
32 
34  AppCommon::texturePath + "MuttenzerBox+X0512_C.png",
35  AppCommon::texturePath + "MuttenzerBox-X0512_C.png",
36  AppCommon::texturePath + "MuttenzerBox+Y0512_C.png",
37  AppCommon::texturePath + "MuttenzerBox-Y0512_C.png",
38  AppCommon::texturePath + "MuttenzerBox+Z0512_C.png",
39  AppCommon::texturePath + "MuttenzerBox-Z0512_C.png");
40 
42  AppCommon::shaderPath + "Reflect.vert",
43  AppCommon::shaderPath + "Reflect.frag");
45  AppCommon::shaderPath + "RefractReflect.vert",
46  AppCommon::shaderPath + "RefractReflect.frag");
47 }
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
void addProgramToLoad(SLGLProgram *&program, const SLstring &vertShaderFile, const SLstring &fragShaderFile)
Add generic GLSL program with shader files 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

◆ _spRefl

SLGLProgram* AppDemoSceneRTMuttenzerBox::_spRefl
private

Definition at line 46 of file AppDemoSceneRTMuttenzerBox.h.

◆ _spRefr

SLGLProgram* AppDemoSceneRTMuttenzerBox::_spRefr
private

Definition at line 47 of file AppDemoSceneRTMuttenzerBox.h.

◆ _tex1

SLGLTexture* AppDemoSceneRTMuttenzerBox::_tex1
private

Definition at line 45 of file AppDemoSceneRTMuttenzerBox.h.


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