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

Class for image base lighting demo scene. More...

#include <AppDemoSceneShaderEarth.h>

Inheritance diagram for AppDemoSceneShaderEarth:
[legend]

Public Member Functions

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

SLGLProgram_sp
 
SLGLTexture_texC
 
SLGLTexture_texN
 
SLGLTexture_texH
 
SLGLTexture_texG
 
SLGLTexture_texNC
 
SLGLTexture_texClC
 

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 image base lighting demo scene.

Definition at line 20 of file AppDemoSceneShaderEarth.h.

Constructor & Destructor Documentation

◆ AppDemoSceneShaderEarth()

AppDemoSceneShaderEarth::AppDemoSceneShaderEarth ( )

Definition at line 20 of file AppDemoSceneShaderEarth.cpp.

21  : SLScene("Earth Shader Test")
22 {
23  info("Complex earth shader with 7 textures: day color, night color, "
24  "normal, height & gloss map of earth, color & alpha-map of clouds.\n"
25  "Use (SHIFT) & key X to change scale of the parallax mapping\n"
26  "Use (SHIFT) & key O to change offset of the parallax mapping");
27 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneShaderEarth::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 56 of file AppDemoSceneShaderEarth.cpp.

57 {
59  "u_scale",
60  0.02f,
61  0.002f,
62  0,
63  1,
64  (SLKey)'X');
65  SLGLUniform1f* offset = new SLGLUniform1f(UT_const,
66  "u_offset",
67  -0.02f,
68  0.002f,
69  -1,
70  1,
71  (SLKey)'O');
72  this->eventHandlers().push_back(scale);
73  this->eventHandlers().push_back(offset);
74  _sp->addUniform1f(scale);
75  _sp->addUniform1f(offset);
76 
77  // Create materials
78  SLMaterial* matEarth = new SLMaterial(am,
79  "matEarth",
80  _texC,
81  _texN,
82  _texH,
83  _texG,
84  _sp);
85  matEarth->addTexture(_texClC);
86  matEarth->addTexture(_texNC);
87  matEarth->shininess(4000);
88  matEarth->program(_sp);
89 
90  SLCamera* cam1 = new SLCamera("Camera 1");
91  cam1->translation(0, 0, 4);
92  cam1->lookAt(0, 0, 0);
93  cam1->focalDist(4);
94  cam1->background().colors(SLCol4f(0, 0, 0));
95  cam1->setInitialState();
97 
98  SLLightSpot* sun = new SLLightSpot(am, this);
99  sun->powers(0.0f, 1.0f, 0.2f);
100  sun->attenuation(1, 0, 0);
101 
102  SLAnimation* anim = this->animManager().createNodeAnimation("light1_anim",
103  24.0f);
105  50.0f,
106  A_x,
107  50.0f,
108  A_z);
109 
110  SLuint res = 30;
111  SLNode* earth = new SLNode(new SLSphere(am,
112  1,
113  res,
114  res,
115  "Earth",
116  matEarth));
117  earth->rotate(90, -1, 0, 0);
118 
119  SLNode* scene = new SLNode;
120  this->root3D(scene);
121  scene->addChild(sun);
122  scene->addChild(earth);
123  scene->addChild(cam1);
124 
125  sv->camera(cam1);
126 }
unsigned int SLuint
Definition: SL.h:171
@ A_z
Definition: SLEnums.h:82
@ A_x
Definition: SLEnums.h:80
@ UT_const
constant value
Definition: SLEnums.h:233
SLKey
Keyboard key codes enumeration.
Definition: SLEnums.h:16
SLGLUniform< SLfloat > SLGLUniform1f
Definition: SLGLUniform.h:149
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.
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 addUniform1f(SLGLUniform1f *u)
add float uniform
Template for a single GLSL uniform variable.
Definition: SLGLUniform.h:24
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
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
void addTexture(SLGLTexture *texture)
Adds the passed texture to the equivalent texture type vector.
Definition: SLMaterial.cpp:348
void shininess(SLfloat shin)
Definition: SLMaterial.h:177
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
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
SLNode * root3D()
Definition: SLScene.h:99
SLVEventHandler & eventHandlers()
Definition: SLScene.h:105
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 SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33

◆ registerAssetsToLoad()

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

31 {
34  "earth2048_C.png");
37  "earth2048_N.jpg");
40  "earth2048_H.jpg");
43  "earth2048_S.jpg");
46  "earthNight2048_C.jpg");
49  "earthCloud1024_alpha_C.png");
51  AppCommon::shaderPath + "PerPixBlinnTmNm.vert",
52  AppCommon::shaderPath + "PerPixBlinnTmNmEarth.frag");
53 }
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

◆ _sp

SLGLProgram* AppDemoSceneShaderEarth::_sp
private

Definition at line 46 of file AppDemoSceneShaderEarth.h.

◆ _texC

SLGLTexture* AppDemoSceneShaderEarth::_texC
private

Definition at line 47 of file AppDemoSceneShaderEarth.h.

◆ _texClC

SLGLTexture* AppDemoSceneShaderEarth::_texClC
private

Definition at line 52 of file AppDemoSceneShaderEarth.h.

◆ _texG

SLGLTexture* AppDemoSceneShaderEarth::_texG
private

Definition at line 50 of file AppDemoSceneShaderEarth.h.

◆ _texH

SLGLTexture* AppDemoSceneShaderEarth::_texH
private

Definition at line 49 of file AppDemoSceneShaderEarth.h.

◆ _texN

SLGLTexture* AppDemoSceneShaderEarth::_texN
private

Definition at line 48 of file AppDemoSceneShaderEarth.h.

◆ _texNC

SLGLTexture* AppDemoSceneShaderEarth::_texNC
private

Definition at line 51 of file AppDemoSceneShaderEarth.h.


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