SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLLightRect.h
Go to the documentation of this file.
1 /**
2  * \file SLLightRect.h
3  * \authors Marcus Hudritsch
4  * \date July 2014
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
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 */
10 
11 #ifndef SLLIGHTRECT_H
12 #define SLLIGHTRECT_H
13 
14 #include <SLLight.h>
15 #include <SLNode.h>
16 
17 class SLSceneView;
18 class SLRay;
19 class SLAssetManager;
20 class SLScene;
21 
22 //-----------------------------------------------------------------------------
23 //! Light node class for a rectangular light source
24 /*!
25  SLLightRect is a node that renders in OpenGL a light rectangle
26  object and applies the OpenGL light settings through the SLLight class.
27  The light rectangle is defined with its width and height and lies initially
28  centered in the x-y-plane. The light shines as a spotlight with 90 degrees
29  cutoff angle towards the negative z-axis.\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 */
37 class SLLightRect : public SLNode
38  , public SLLight
39 {
40 public:
41  SLLightRect(SLAssetManager* assetMgr,
42  SLScene* s,
43  SLfloat width = 1,
44  SLfloat height = 1,
45  SLbool hasMesh = true);
46 
47  ~SLLightRect() override;
48 
49  void init(SLScene* s);
50  bool hitRec(SLRay* ray) override;
51  void statsRec(SLNodeStats& stats) override;
52  void drawMesh(SLSceneView* sv) override;
53  void createShadowMap(float lightClipNear = 0.1f,
54  float lightClipFar = 20.0f,
55  SLVec2f size = SLVec2f(8, 8),
56  SLVec2i texSize = SLVec2i(1024, 1024)) override;
57  void createShadowMapAutoSize(SLCamera* camera,
58  SLVec2i texSize = SLVec2i(1024, 1024),
59  int numCascades = 0) override;
61  const SLVec3f& L,
62  SLfloat lightDist,
63  SLNode* root3D) override;
65  const SLVec3f& L,
66  SLfloat lightDist,
67  SLNode* root3D) override;
68 
69  // Setters
70  void width(const SLfloat w)
71  {
72  _width = w;
73  _halfWidth = w * 0.5f;
74  }
75  void height(const SLfloat h)
76  {
77  _height = h;
78  _halfHeight = h * 0.5f;
79  }
80  void samples(SLVec2i samples);
81  void samplesXY(SLint x, SLint y);
82 
83  // Getters
84  SLfloat width() const { return _width; }
85  SLfloat height() const { return _height; }
86 
87  // Overrides
88  SLCol4f ambient() override { return _ambientColor * _ambientPower; }
89  SLCol4f diffuse() override { return _diffuseColor * _diffusePower; }
90  SLCol4f specular() override { return _specularColor * _specularPower; }
91  SLVec4f positionWS() const override { return SLVec4f(updateAndGetWM().translation()); }
92  SLVec3f spotDirWS() override
93  {
94  return SLVec3f(_wm.m(8),
95  _wm.m(9),
96  _wm.m(10)) *
97  -1.0;
98  }
99 
100 private:
101  SLfloat _width; //!< Width of square light in x direction
102  SLfloat _height; //!< Lenght of square light in y direction
103  SLfloat _halfWidth; //!< Half width of square light in x dir
104  SLfloat _halfHeight; //!< Half height of square light in y dir
105  SLVec2i _samples; //!< Uneven NO. of samples in x and y dir
106 };
107 //-----------------------------------------------------------------------------
108 #endif
float SLfloat
Definition: SL.h:173
bool SLbool
Definition: SL.h:175
int SLint
Definition: SL.h:170
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
SLVec4< SLfloat > SLVec4f
Definition: SLVec4.h:235
Toplevel holder of the assets meshes, materials, textures and shaders.
Active or visible camera node class.
Definition: SLCamera.h:54
Abstract Light class for OpenGL light sources.
Definition: SLLight.h:61
SLCol4f _ambientColor
Ambient light color (RGB 0-1)
Definition: SLLight.h:210
SLfloat _diffusePower
Diffuse light power (0-N)
Definition: SLLight.h:213
SLfloat _specularPower
Specular light power (0-N)
Definition: SLLight.h:215
SLCol4f _diffuseColor
Diffuse light color (RGB 0-1)
Definition: SLLight.h:212
SLfloat _ambientPower
Ambient light power (0-N)
Definition: SLLight.h:211
SLCol4f _specularColor
Specular light color (RGB 0-1)
Definition: SLLight.h:214
Light node class for a rectangular light source.
Definition: SLLightRect.h:39
SLfloat shadowTest(SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D) override
SLCol4f ambient() override
Return normally _ambientColor * _ambientPower.
Definition: SLLightRect.h:88
void init(SLScene *s)
Definition: SLLightRect.cpp:73
void height(const SLfloat h)
Definition: SLLightRect.h:75
SLfloat width() const
Definition: SLLightRect.h:84
SLfloat height() const
Definition: SLLightRect.h:85
void statsRec(SLNodeStats &stats) override
SLLightSpot::statsRec updates the statistic parameters.
SLLightRect(SLAssetManager *assetMgr, SLScene *s, SLfloat width=1, SLfloat height=1, SLbool hasMesh=true)
Construct a new SLLightRect::SLLightRect object.
Definition: SLLightRect.cpp:34
SLfloat _halfHeight
Half height of square light in y dir.
Definition: SLLightRect.h:104
SLfloat shadowTestMC(SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D) override
void samples(SLVec2i samples)
SLCol4f specular() override
Returns normally _specularColor * _specularPower.
Definition: SLLightRect.h:90
SLVec2i _samples
Uneven NO. of samples in x and y dir.
Definition: SLLightRect.h:105
void drawMesh(SLSceneView *sv) override
void createShadowMapAutoSize(SLCamera *camera, SLVec2i texSize=SLVec2i(1024, 1024), int numCascades=0) override
SLVec4f positionWS() const override
Definition: SLLightRect.h:91
~SLLightRect() override
Definition: SLLightRect.cpp:64
SLfloat _width
Width of square light in x direction.
Definition: SLLightRect.h:101
SLfloat _height
Lenght of square light in y direction.
Definition: SLLightRect.h:102
void samplesXY(SLint x, SLint y)
bool hitRec(SLRay *ray) override
Definition: SLLightRect.cpp:96
void createShadowMap(float lightClipNear=0.1f, float lightClipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024)) override
SLfloat _halfWidth
Half width of square light in x dir.
Definition: SLLightRect.h:103
void width(const SLfloat w)
Definition: SLLightRect.h:70
SLCol4f diffuse() override
Returns normally _diffuseColor * _diffusePower.
Definition: SLLightRect.h:89
SLVec3f spotDirWS() override
Definition: SLLightRect.h:92
void m(int i, T val)
Definition: SLMat4.h:93
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
const SLMat4f & updateAndGetWM() const
Definition: SLNode.cpp:703
SLMat4f _wm
world matrix for world transform
Definition: SLNode.h:352
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
Struct for scene graph statistics.
Definition: SLNode.h:37