SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneShaderEarth.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneShaderEarth.cpp
3  * \brief Implementation for an SLScene inherited class
4  * \details For more info about App framework and the scene assembly see:
5  * https://cpvrlab.github.io/SLProject4/app-framework.html
6  * \date May 2024
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9  * \authors Marcus Hudritsch, Earth Shader from Markus Knecht
10  * \copyright http://opensource.org/licenses/GPL-3.0
11 */
12 
14 #include <SLAssetLoader.h>
15 #include <SLLightSpot.h>
16 #include <SLSphere.h>
17 #include <AppCommon.h>
18 
19 //-----------------------------------------------------------------------------
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 F2 to change scale of the parallax mapping\n"
26  "Use (SHIFT) & key F3 to change offset of the parallax mapping");
27 }
28 //-----------------------------------------------------------------------------
29 //! All assets the should be loaded in parallel must be registered in here.
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 }
54 //-----------------------------------------------------------------------------
55 //! After parallel loading of the assets the scene gets assembled in here.
57 {
59  "u_scale",
60  0.02f,
61  0.002f,
62  0,
63  1,
64  (SLKey)K_F2);
65  SLGLUniform1f* offset = new SLGLUniform1f(UT_const,
66  "u_offset",
67  -0.02f,
68  0.002f,
69  -1,
70  1,
71  (SLKey)K_F3);
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 }
127 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
Class declaration for an SLScene inherited class.
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
@ K_F2
Definition: SLEnums.h:50
@ K_F3
Definition: SLEnums.h:51
SLGLUniform< SLfloat > SLGLUniform1f
Definition: SLGLUniform.h:162
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
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
void assemble(SLAssetManager *am, SLSceneView *sv) override
After parallel loading of the assets the scene gets assembled in here.
void registerAssetsToLoad(SLAssetLoader &al) override
All scene specific assets have to be registered for async loading in here.
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 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.
Toplevel holder of the assets meshes, materials, textures and shaders.
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
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
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
SLstring & info()
Definition: SLScene.h:102
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