SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLLightSpot.h
Go to the documentation of this file.
1 /**
2  * \file SLLightSpot.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 SLLIGHTSPHERE_H
12 #define SLLIGHTSPHERE_H
13 
14 #include <SLLight.h>
15 #include <SLNode.h>
16 #include <SLRaySamples2D.h>
17 
18 class SLSceneView;
19 class SLRay;
20 class SLScene;
21 
22 //-----------------------------------------------------------------------------
23 //! SLLightSpot class for a spot light source
24 /*!
25  SLLightSpot is a node and a light that can have a spot mesh for its
26  representation.
27  If a light node is added to the scene it stays fix in the scene.\n
28  If a light node is added to the camera it moves with the camera.\n
29  See the scene examples for Per-Vertex-Blinn or Per-Pixel-Blinn lighting where
30  all light node types are used. \n
31  All light nodes inherited from SLLight work automatically together with the
32  automatically generated shader in SLGLProgramGenerated.
33 */
34 class SLLightSpot : public SLNode
35  , public SLLight
36 {
37 public:
38  explicit SLLightSpot(SLAssetManager* assetMgr,
39  SLScene* s,
40  SLfloat radius = 0.3f,
41  SLfloat spotAngleDEG = 180.0f,
42  SLbool hasMesh = true);
43  SLLightSpot(SLAssetManager* assetMgr,
44  SLScene* s,
45  SLfloat posx,
46  SLfloat posy,
47  SLfloat posz,
48  SLfloat radius = 0.3f,
49  SLfloat spotAngleDEG = 180.0f,
50  SLfloat ambiPower = 1.0f,
51  SLfloat diffPower = 10.0f,
52  SLfloat specPower = 10.0f,
53  SLbool hasMesh = true);
54  ~SLLightSpot() override;
55 
56  void init(SLScene* s);
57  bool hitRec(SLRay* ray) override;
58  void statsRec(SLNodeStats& stats) override;
59  void drawMesh(SLSceneView* sv) override;
60  void createShadowMap(float lightClipNear = 0.1f,
61  float lightClipFar = 20.0f,
62  SLVec2f size = SLVec2f(8, 8),
63  SLVec2i texSize = SLVec2i(1024, 1024)) override;
64  void createShadowMapAutoSize(SLCamera* camera,
65  SLVec2i texSize = SLVec2i(1024, 1024),
66  int numCascades = 0) override;
68  const SLVec3f& L,
69  SLfloat lightDist,
70  SLNode* root3D) override;
72  const SLVec3f& L,
73  SLfloat lightDist,
74  SLNode* root3D) override;
75 
76  // Setters
77  void samples(SLuint x, SLuint y) { _samples.samples(x, y, false); }
78 
79  // Getters
80  SLfloat radius() const { return _radius; }
81  SLuint samples() { return _samples.samples(); }
82 
83  // Overrides
84  SLCol4f ambient() override { return _ambientColor * _ambientPower; }
85  SLCol4f diffuse() override { return _diffuseColor * _diffusePower; }
86  SLCol4f specular() override { return _specularColor * _specularPower; }
87  SLVec4f positionWS() const override { return SLVec4f(translationWS()); }
88  SLVec3f spotDirWS() override { return forwardWS(); }
89 
90 #ifdef SL_HAS_OPTIX
91  ortLight optixLight(bool doDistributed)
92  {
93  ortSamples loc_samples{};
94  float loc_radius;
95  if (doDistributed)
96  {
97  loc_samples.samplesX = _samples.samplesX();
98  loc_samples.samplesY = _samples.samplesY();
99  loc_radius = radius();
100  }
101  else
102  {
103  loc_samples = {1, 1};
104  loc_radius = 0.0f;
105  }
106  return {make_float4(diffuse()),
107  make_float4(ambient()),
108  make_float4(specular()),
109  make_float3({positionWS().x, positionWS().y, positionWS().z}),
110  spotCutOffDEG(),
111  spotExponent(),
112  spotCosCut(),
113  make_float3(spotDirWS()),
114  kc(),
115  kl(),
116  kq(),
117  loc_samples,
118  loc_radius};
119  }
120 #endif
121 
122 private:
123  SLfloat _radius; //!< The sphere lights radius
124  SLRaySamples2D _samples; //!< 2D sample points for soft shadows
125 };
126 //-----------------------------------------------------------------------------
127 #endif
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
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
SLfloat kc() const
Definition: SLLight.h:143
SLCol4f _ambientColor
Ambient light color (RGB 0-1)
Definition: SLLight.h:210
SLfloat kq() const
Definition: SLLight.h:145
SLfloat _diffusePower
Diffuse light power (0-N)
Definition: SLLight.h:213
SLfloat spotCutOffDEG() const
Definition: SLLight.h:140
SLfloat spotCosCut() const
Definition: SLLight.h:141
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
SLfloat spotExponent() const
Definition: SLLight.h:142
SLfloat kl() const
Definition: SLLight.h:144
SLCol4f _specularColor
Specular light color (RGB 0-1)
Definition: SLLight.h:214
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
bool hitRec(SLRay *ray) override
void samples(SLuint x, SLuint y)
Definition: SLLightSpot.h:77
SLVec3f spotDirWS() override
Definition: SLLightSpot.h:88
SLfloat shadowTestMC(SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D) override
SLRaySamples2D _samples
2D sample points for soft shadows
Definition: SLLightSpot.h:124
SLfloat radius() const
Definition: SLLightSpot.h:80
void createShadowMapAutoSize(SLCamera *camera, SLVec2i texSize=SLVec2i(1024, 1024), int numCascades=0) override
SLuint samples()
Definition: SLLightSpot.h:81
void createShadowMap(float lightClipNear=0.1f, float lightClipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024)) override
SLCol4f diffuse() override
Returns normally _diffuseColor * _diffusePower.
Definition: SLLightSpot.h:85
void drawMesh(SLSceneView *sv) override
void statsRec(SLNodeStats &stats) override
SLLightSpot::statsRec updates the statistic parameters.
SLCol4f specular() override
Returns normally _specularColor * _specularPower.
Definition: SLLightSpot.h:86
~SLLightSpot() override
SLfloat shadowTest(SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D) override
SLfloat _radius
The sphere lights radius.
Definition: SLLightSpot.h:123
SLCol4f ambient() override
Return normally _ambientColor * _ambientPower.
Definition: SLLightSpot.h:84
SLVec4f positionWS() const override
Definition: SLLightSpot.h:87
void init(SLScene *s)
SLLightSpot(SLAssetManager *assetMgr, SLScene *s, SLfloat radius=0.3f, SLfloat spotAngleDEG=180.0f, SLbool hasMesh=true)
Construct a new SLLightSpot::SLLightSpot object.
Definition: SLLightSpot.cpp:33
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
SLVec3f translationWS() const
Definition: SLNode.h:531
SLVec3f forwardWS() const
Definition: SLNode.h:541
Ray class with ray and intersection properties.
Definition: SLRay.h:40
Class for 2D disk sample points.
void samples(SLuint x, SLuint y, SLbool evenlyDistributed=true)
Resets the sample point array by the sqrt of the no. of samples.
SLuint samplesY()
SLuint samplesX()
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
T z
Definition: SLVec4.h:32
T y
Definition: SLVec4.h:32
T x
Definition: SLVec4.h:32
Struct for scene graph statistics.
Definition: SLNode.h:37