SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLLightDirect.h
Go to the documentation of this file.
1 /**
2  * \file SLLightDirect.h
3  * \date July 2016
4  * \authors Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLLIGHTDIRECT_H
11 #define SLLIGHTDIRECT_H
12 
13 #include <SLLight.h>
14 #include <SLNode.h>
15 #include <SLRaySamples2D.h>
16 #include <SLTexColorLUT.h>
17 
18 class SLRay;
19 class SLScene;
20 class SLSceneView;
21 
22 //-----------------------------------------------------------------------------
23 //! SLLightDirect class for a directional light source
24 /*!
25  SLLightDirect is a node and a light that can have a sphere mesh with a line for
26  its direction representation. For directional lights the position vector is in
27  infinite distance. We use its homogeneous component w as zero as the
28  directional light flag. The spot direction is used in the shaders for the
29  light direction.\n
30  If a light node is added to the scene it stays fix in the scene.\n
31  If a light node is added to the camera it moves with the camera.\n
32  See the scene examples for Per-Vertex-Blinn or Per-Pixel-Blinn lighting where
33  all light node types are used. \n
34  All light nodes inherited from SLLight work automatically together with the
35  automatically generated shader in SLGLProgramGenerated.
36 */
38  : public SLNode
39  , public SLLight
40 {
41 public:
42  SLLightDirect(SLAssetManager* assetMgr,
43  SLScene* s,
44  SLfloat arrowLength = 0.5f,
45  SLbool hasMesh = true,
46  SLbool doCascadedShadows = false);
47  SLLightDirect(SLAssetManager* assetMgr,
48  SLScene* s,
49  SLfloat posx,
50  SLfloat posy,
51  SLfloat posz,
52  SLfloat arrowLength = 0.5f,
53  SLfloat ambiPower = 1.0f,
54  SLfloat diffPower = 10.0f,
55  SLfloat specPower = 10.0f,
56  SLbool hasMesh = true,
57  SLbool doCascadedShadows = false);
58  ~SLLightDirect() override;
59 
60  void init(SLScene* s);
61  bool hitRec(SLRay* ray) override;
62  void statsRec(SLNodeStats& stats) override;
63  void drawMesh(SLSceneView* sv) override;
65  const SLVec3f& L,
66  SLfloat lightDist,
67  SLNode* root3D) override;
69  const SLVec3f& L,
70  SLfloat lightDist,
71  SLNode* root3D) override;
72  void createShadowMap(float clipNear = 0.1f,
73  float clipFar = 20.0f,
74  SLVec2f size = SLVec2f(8, 8),
75  SLVec2i texSize = SLVec2i(1024, 1024)) override;
76  void createShadowMapAutoSize(SLCamera* camera,
77  SLVec2i texSize = SLVec2i(1024, 1024),
78  int numCascades = 4) override;
79  SLCol4f calculateSunLight(SLfloat standardPower);
80 
81  // Setters
82  void doSunPowerAdaptation(SLbool enabled) { _doSunPowerAdaptation = enabled; }
83  void sunLightPowerMin(SLfloat minPower) { _sunLightPowerMin = minPower; }
84  void doCascadedShadows(bool b) { _doCascadedShadows = b; }
85 
86  // Getters
87  SLfloat radius() const { return _arrowRadius; }
88  SLfloat dirLength() const { return _arrowLength; }
91  SLbool doCascadedShadows() const override { return _doCascadedShadows; }
92 
93  // For directional lights the position vector is interpreted as a
94  // direction with the homogeneous component equals zero:
95  SLVec4f positionWS() const override
96  {
98  pos.w = 0.0f;
99  return pos;
100  }
101  SLVec3f spotDirWS() override { return forwardOS(); }
102  SLCol4f ambient() override;
103  SLCol4f diffuse() override;
104  SLCol4f specular() override;
105 
106 protected:
107  void renderShadowMap(SLSceneView* sv, SLNode* root) override;
108 
109 private:
110  SLfloat _arrowRadius; //!< The sphere lights radius
111  SLfloat _arrowLength; //!< Length of direction line
112  SLbool _doSunPowerAdaptation; //!< Flag for sun power scaling
113  SLfloat _sunLightPowerMin; //!< Min. zenith power scale factor for sun
114  SLTexColorLUT _sunLightColorLUT; //!< Sun light color LUT
115  bool _doCascadedShadows; //!< Cascaded shadow
116 };
117 //-----------------------------------------------------------------------------
118 #endif
float SLfloat
Definition: SL.h:173
bool SLbool
Definition: SL.h:175
Declares a color look up table functionality.
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
Toplevel holder of the assets meshes, materials, textures and shaders.
Active or visible camera node class.
Definition: SLCamera.h:54
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
SLbool _doSunPowerAdaptation
Flag for sun power scaling.
~SLLightDirect() override
void sunLightPowerMin(SLfloat minPower)
Definition: SLLightDirect.h:83
SLCol4f ambient() override
Returns the product of the ambient light color and the ambient light power.
void doCascadedShadows(bool b)
Definition: SLLightDirect.h:84
SLVec4f positionWS() const override
Definition: SLLightDirect.h:95
SLLightDirect(SLAssetManager *assetMgr, SLScene *s, SLfloat arrowLength=0.5f, SLbool hasMesh=true, SLbool doCascadedShadows=false)
Construct a new SLLightDirect::SLLightDirect object.
SLfloat _sunLightPowerMin
Min. zenith power scale factor for sun.
SLfloat shadowTest(SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D) override
SLCol4f specular() override
Returns the product of the specular light color and the specular light power.
bool hitRec(SLRay *ray) override
SLVec3f spotDirWS() override
void renderShadowMap(SLSceneView *sv, SLNode *root) override
SLLight::renderShadowMap renders the shadow map of the light.
SLfloat radius() const
Definition: SLLightDirect.h:87
SLCol4f diffuse() override
Returns the product of the diffuse light color and the diffuse light power.
SLfloat _arrowLength
Length of direction line.
void createShadowMap(float clipNear=0.1f, float clipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024)) override
SLfloat _arrowRadius
The sphere lights radius.
void drawMesh(SLSceneView *sv) override
SLCol4f calculateSunLight(SLfloat standardPower)
Calculates the sunlight color depending on the zenith angle.
SLfloat shadowTestMC(SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D) override
SLbool doSunPowerAdaptation()
Definition: SLLightDirect.h:89
bool _doCascadedShadows
Cascaded shadow.
void init(SLScene *s)
void doSunPowerAdaptation(SLbool enabled)
Definition: SLLightDirect.h:82
SLfloat dirLength() const
Definition: SLLightDirect.h:88
SLbool doCascadedShadows() const override
Definition: SLLightDirect.h:91
SLTexColorLUT _sunLightColorLUT
Sun light color LUT.
void createShadowMapAutoSize(SLCamera *camera, SLVec2i texSize=SLVec2i(1024, 1024), int numCascades=4) override
SLTexColorLUT * sunLightColorLUT()
Definition: SLLightDirect.h:90
void statsRec(SLNodeStats &stats) override
SLLightDirect::statsRec updates the statistic parameters.
Abstract Light class for OpenGL light sources.
Definition: SLLight.h:61
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
SLVec3f forwardOS() const
Definition: SLNode.h:477
const SLMat4f & updateAndGetWM() const
Definition: SLNode.cpp:703
Ray class with ray and intersection properties.
Definition: SLRay.h:40
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
SLTexColorLUT defines a lookup table as an 1D texture of (256) RGBA values.
Definition: SLTexColorLUT.h:70
T w
Definition: SLVec4.h:32
Struct for scene graph statistics.
Definition: SLNode.h:37