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

Class for demo scene with Blinn-Phong lighting per vertex or per pixel. More...

#include <AppDemoSceneShaderBlinn.h>

Inheritance diagram for AppDemoSceneShaderBlinn:
[legend]

Public Member Functions

 AppDemoSceneShaderBlinn (SLstring name, bool perVertex)
 
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

bool _perVertex
 
SLGLProgram_perVrtTm = nullptr
 
SLGLProgram_perVrt = nullptr
 
SLGLProgram_perPix = nullptr
 
SLGLTexture_texC = nullptr
 
SLGLTexture_texN = nullptr
 
SLGLTexture_texH = nullptr
 

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 with Blinn-Phong lighting per vertex or per pixel.

Definition at line 20 of file AppDemoSceneShaderBlinn.h.

Constructor & Destructor Documentation

◆ AppDemoSceneShaderBlinn()

AppDemoSceneShaderBlinn::AppDemoSceneShaderBlinn ( SLstring  name,
bool  perVertex 
)

Definition at line 21 of file AppDemoSceneShaderBlinn.cpp.

22  : SLScene(name),
23  _perVertex(perVertex)
24 {
25  if (_perVertex)
26  {
27  info("Per-vertex lighting with Blinn-Phong reflection model. "
28  "The reflection of 5 light sources is calculated per vertex. "
29  "The green and the white light are attached to the camera, the others are in the scene. "
30  "The light calculation per vertex is the fastest but leads to artefacts with spot lights");
31  }
32  else
33  {
34  info("Per-pixel lighting with Blinn-Phong reflection model. "
35  "The reflection of 5 light sources is calculated per pixel. "
36  "The light calculation is done in the fragment shader.");
37  }
38 }
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 AppDemoSceneShaderBlinn::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 64 of file AppDemoSceneShaderBlinn.cpp.

65 {
66  SLMaterial* mL = nullptr;
67  SLMaterial* mM = nullptr;
68  SLMaterial* mR = nullptr;
69 
70  if (_perVertex)
71  {
72  mL = new SLMaterial(am, "mL", _texC, nullptr, nullptr, nullptr, _perVrtTm);
73  mM = new SLMaterial(am, "mM", _perVrt);
74  mR = new SLMaterial(am, "mR", _texC, nullptr, nullptr, nullptr, _perVrtTm);
75  }
76  else
77  { // per pixel
78  SLGLUniform1f* scale = new SLGLUniform1f(UT_const, "u_scale", 0.02f, 0.002f, 0, 1);
79  SLGLUniform1f* offset = new SLGLUniform1f(UT_const, "u_offset", -0.02f, 0.002f, -1, 1);
80  _perPix->addUniform1f(scale);
81  _perPix->addUniform1f(offset);
82  mL = new SLMaterial(am, "mL", _texC);
83  mM = new SLMaterial(am, "mM");
84  mR = new SLMaterial(am, "mR", _texC, _texN, _texH, nullptr, _perPix);
85  }
86 
87  mM->shininess(500);
88 
89  // Base root group node for the scene
90  SLNode* scene = new SLNode;
91  this->root3D(scene);
92 
93  SLCamera* cam1 = new SLCamera("Camera 1");
94  cam1->translation(0, 0, 7);
95  cam1->lookAt(0, 0, 0);
96  cam1->focalDist(7);
97  cam1->background().colors(SLCol4f(0.1f, 0.1f, 0.1f));
98  cam1->setInitialState();
99  scene->addChild(cam1);
100 
101  // Define 5 light sources
102 
103  // A rectangular white light attached to the camera
104  SLLightRect* lightW = new SLLightRect(am, this, 2.0f, 1.0f);
105  lightW->ambiDiffPowers(0, 5);
106  lightW->translation(0, 2.5f, 0);
107  lightW->translation(0, 2.5f, -7);
108  lightW->rotate(-90, 1, 0, 0);
109  lightW->attenuation(0, 0, 1);
110  cam1->addChild(lightW);
111 
112  // A red point light from the front attached in the scene
113  SLLightSpot* lightR = new SLLightSpot(am, this, 0.1f);
114  lightR->ambientColor(SLCol4f(0, 0, 0));
115  lightR->diffuseColor(SLCol4f(1, 0, 0));
116  lightR->specularColor(SLCol4f(1, 0, 0));
117  lightR->translation(0, 0, 2);
118  lightR->lookAt(0, 0, 0);
119  lightR->attenuation(0, 0, 1);
120  scene->addChild(lightR);
121 
122  // A green spot head light with 40 deg. spot angle from front right
123  SLLightSpot* lightG = new SLLightSpot(am, this, 0.1f, 20, true);
124  lightG->ambientColor(SLCol4f(0, 0, 0));
125  lightG->diffuseColor(SLCol4f(0, 1, 0));
126  lightG->specularColor(SLCol4f(0, 1, 0));
127  lightG->translation(1.5f, 1, -5.5f);
128  lightG->lookAt(0, 0, -7);
129  lightG->attenuation(1, 0, 0);
130  cam1->addChild(lightG);
131 
132  // A blue spot light with 40 deg. spot angle from front left
133  SLLightSpot* lightB = new SLLightSpot(am, this, 0.1f, 20.0f, true);
134  lightB->ambientColor(SLCol4f(0, 0, 0));
135  lightB->diffuseColor(SLCol4f(0, 0, 1));
136  lightB->specularColor(SLCol4f(0, 0, 1));
137  lightB->translation(-1.5f, 1.5f, 1.5f);
138  lightB->lookAt(0, 0, 0);
139  lightB->attenuation(1, 0, 0);
140  SLAnimation* light3Anim = animManager().createNodeAnimation("Ball3_anim",
141  1.0f,
142  true,
143  EC_outQuad,
145  light3Anim->createNodeAnimTrackForTranslation(lightB, SLVec3f(0, -2, 0));
146  scene->addChild(lightB);
147 
148  // A yellow directional light from the back-bottom
149  // Do constant attenuation for directional lights since it is infinitely far away
150  SLLightDirect* lightY = new SLLightDirect(am, this);
151  lightY->ambientColor(SLCol4f(0, 0, 0));
152  lightY->diffuseColor(SLCol4f(1, 1, 0));
153  lightY->specularColor(SLCol4f(1, 1, 0));
154  lightY->translation(-1.5f, -1.5f, 1.5f);
155  lightY->lookAt(0, 0, 0);
156  lightY->attenuation(1, 0, 0);
157  scene->addChild(lightY);
158 
159  // Add some meshes to be lighted
160  SLNode* sphereL = new SLNode(new SLSpheric(am, 1.0f, 0.0f, 180.0f, 36, 36, "Sphere", mL));
161  sphereL->translate(-2, 0, 0);
162  sphereL->rotate(90, -1, 0, 0);
163  SLNode* sphereM = new SLNode(new SLSpheric(am, 1.0f, 0.0f, 180.0f, 36, 36, "Sphere", mM));
164  SLNode* sphereR = new SLNode(new SLSpheric(am, 1.0f, 0.0f, 180.0f, 36, 36, "Sphere", mR));
165  sphereR->translate(2, 0, 0);
166  sphereR->rotate(90, -1, 0, 0);
167 
168  scene->addChild(sphereL);
169  scene->addChild(sphereM);
170  scene->addChild(sphereR);
171  sv->camera(cam1);
172 }
@ EC_outQuad
quadratic easing out, decelerating to zero velocity
Definition: SLEnums.h:183
@ AL_pingPongLoop
loop forward and backwards
Definition: SLEnums.h:171
@ UT_const
constant value
Definition: SLEnums.h:233
SLGLUniform< SLfloat > SLGLUniform1f
Definition: SLGLUniform.h:162
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
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 * createNodeAnimTrackForTranslation(SLNode *target, const SLVec3f &endPos)
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
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 addUniform1f(SLGLUniform1f *u)
add float uniform
Template for a single GLSL uniform variable.
Definition: SLGLUniform.h:24
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
void ambientColor(const SLCol4f &ambi)
Definition: SLLight.h:105
void ambiDiffPowers(SLfloat ambiPow, SLfloat diffPow, const SLCol4f &ambiDiffCol=SLCol4f::WHITE)
Sets the ambient and diffuse powers with the same color.
Definition: SLLight.h:88
void diffuseColor(const SLCol4f &diff)
Definition: SLLight.h:107
void specularColor(const SLCol4f &spec)
Definition: SLLight.h:109
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
Light node class for a rectangular light source.
Definition: SLLightRect.h:39
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 shininess(SLfloat shin)
Definition: SLMaterial.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 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

◆ registerAssetsToLoad()

void AppDemoSceneShaderBlinn::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 41 of file AppDemoSceneShaderBlinn.cpp.

42 {
45  "earth2048_C_Q95.jpg");
48  "earth2048_N.jpg");
51  "earth2048_H.jpg");
53  AppCommon::shaderPath + "PerVrtBlinnTm.vert",
54  AppCommon::shaderPath + "PerVrtBlinnTm.frag");
56  AppCommon::shaderPath + "PerVrtBlinn.vert",
57  AppCommon::shaderPath + "PerVrtBlinn.frag");
59  AppCommon::shaderPath + "PerPixBlinnTmNm.vert",
60  AppCommon::shaderPath + "PerPixBlinnTmPm.frag");
61 }
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

◆ _perPix

SLGLProgram* AppDemoSceneShaderBlinn::_perPix = nullptr
private

Definition at line 50 of file AppDemoSceneShaderBlinn.h.

◆ _perVertex

bool AppDemoSceneShaderBlinn::_perVertex
private

Definition at line 47 of file AppDemoSceneShaderBlinn.h.

◆ _perVrt

SLGLProgram* AppDemoSceneShaderBlinn::_perVrt = nullptr
private

Definition at line 49 of file AppDemoSceneShaderBlinn.h.

◆ _perVrtTm

SLGLProgram* AppDemoSceneShaderBlinn::_perVrtTm = nullptr
private

Definition at line 48 of file AppDemoSceneShaderBlinn.h.

◆ _texC

SLGLTexture* AppDemoSceneShaderBlinn::_texC = nullptr
private

Definition at line 51 of file AppDemoSceneShaderBlinn.h.

◆ _texH

SLGLTexture* AppDemoSceneShaderBlinn::_texH = nullptr
private

Definition at line 53 of file AppDemoSceneShaderBlinn.h.

◆ _texN

SLGLTexture* AppDemoSceneShaderBlinn::_texN = nullptr
private

Definition at line 52 of file AppDemoSceneShaderBlinn.h.


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