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

Light node class for a rectangular light source. More...

#include <SLLightRect.h>

Inheritance diagram for SLLightRect:
[legend]

Public Member Functions

 SLLightRect (SLAssetManager *assetMgr, SLScene *s, SLfloat width=1, SLfloat height=1, SLbool hasMesh=true)
 Construct a new SLLightRect::SLLightRect object. More...
 
 ~SLLightRect () override
 
void init (SLScene *s)
 
bool hitRec (SLRay *ray) override
 
void statsRec (SLNodeStats &stats) override
 SLLightSpot::statsRec updates the statistic parameters. More...
 
void drawMesh (SLSceneView *sv) override
 
void createShadowMap (float lightClipNear=0.1f, float lightClipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024)) override
 
void createShadowMapAutoSize (SLCamera *camera, SLVec2i texSize=SLVec2i(1024, 1024), int numCascades=0) override
 
SLfloat shadowTest (SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D) override
 
SLfloat shadowTestMC (SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D) override
 
void width (const SLfloat w)
 
void height (const SLfloat h)
 
void samples (SLVec2i samples)
 
void samplesXY (SLint x, SLint y)
 
SLfloat width () const
 
SLfloat height () const
 
SLCol4f ambient () override
 Return normally _ambientColor * _ambientPower. More...
 
SLCol4f diffuse () override
 Returns normally _diffuseColor * _diffusePower. More...
 
SLCol4f specular () override
 Returns normally _specularColor * _specularPower. More...
 
SLVec4f positionWS () const override
 
SLVec3f spotDirWS () override
 
- Public Member Functions inherited from SLNode
 SLNode (const SLstring &name="Node")
 Construct a new SLNode::SLNode object. More...
 
 SLNode (SLMesh *mesh, const SLstring &name="Node")
 
 SLNode (SLMesh *mesh, const SLVec3f &translation, const SLstring &name)
 
 ~SLNode () override
 
virtual void cull3DRec (SLSceneView *sv)
 
virtual void cullChildren3D (SLSceneView *sv)
 Initializer function to call SLNode::cull3DRec recursively. More...
 
virtual void cull2DRec (SLSceneView *sv)
 
virtual SLNodecopyRec ()
 
virtual SLAABBoxupdateAABBRec (SLbool updateAlsoAABBinOS)
 
virtual void dumpRec ()
 
void setDrawBitsRec (SLuint bit, SLbool state)
 
void setPrimitiveTypeRec (SLGLPrimitiveType primitiveType)
 
virtual void addMesh (SLMesh *mesh)
 
bool removeMesh ()
 Returns true if a mesh was assigned and set it to nullptr. More...
 
bool removeMesh (SLMesh *mesh)
 Returns true if the passed mesh was assigned and sets it to nullptr. More...
 
SLint numChildren ()
 
void addChild (SLNode *child)
 
bool insertChild (SLNode *insertC, SLNode *afterC)
 
void deleteChildren ()
 
bool deleteChild ()
 
bool deleteChild (SLNode *child)
 
bool deleteChild (const SLstring &name)
 
bool removeChild (SLNode *child)
 remove child from vector of children. Removes false if not found, else true. More...
 
template<typename T >
T * find (const SLstring &name="", SLbool findRecursive=true)
 
template<typename T >
T * findChild (const SLstring &name="", SLbool findRecursive=true)
 
template<typename T >
deque< T * > findChildren (const SLstring &name="", SLbool findRecursive=true, SLbool canContain=false)
 
deque< SLNode * > findChildren (const SLMesh *mesh, SLbool findRecursive=true)
 
deque< SLNode * > findChildren (SLuint drawbit, SLbool findRecursive=true)
 
SLVec3f translationOS () const
 
SLVec3f forwardOS () const
 
SLVec3f rightOS () const
 
SLVec3f upOS () const
 
SLVec3f axisXOS () const
 
SLVec3f axisYOS () const
 
SLVec3f axisZOS () const
 
SLVec3f translationWS () const
 
SLVec3f forwardWS () const
 
SLVec3f rightWS () const
 
SLVec3f upWS () const
 
SLVec3f axisXWS () const
 
SLVec3f axisYWS () const
 
SLVec3f axisZWS () const
 
void translation (const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
 
void translation (SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_parent)
 
void rotation (const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
 
void rotation (SLfloat angleDeg, const SLVec3f &axis, SLTransformSpace relativeTo=TS_parent)
 
void scaling (SLfloat s)
 
void scaling (SLfloat x, SLfloat y, SLfloat z)
 
void scaling (const SLVec3f &scaling)
 
void lookAt (SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
 
void lookAt (const SLVec3f &target, const SLVec3f &up=SLVec3f::AXISY, SLTransformSpace relativeTo=TS_world)
 
void translate (const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
 
void translate (SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_object)
 
void rotate (const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
 
void rotate (SLfloat angleDeg, const SLVec3f &axis, SLTransformSpace relativeTo=TS_object)
 
void rotate (SLfloat angleDeg, SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_object)
 
void rotateAround (const SLVec3f &point, SLVec3f &axis, SLfloat angleDeg, SLTransformSpace relativeTo=TS_world)
 
void scale (SLfloat s)
 
void scale (SLfloat x, SLfloat y, SLfloat z)
 
void scale (const SLVec3f &scale)
 
void scaleToCenter (SLfloat maxDim)
 
void setInitialState ()
 
void resetToInitialState ()
 
void parent (SLNode *p)
 
void entityID (SLint entityID)
 
void om (const SLMat4f &mat)
 
void animation (SLAnimation *a)
 
void castsShadows (SLbool castsShadows)
 
virtual void needUpdate ()
 
void needWMUpdate ()
 
void needAABBUpdate ()
 
void isSelected (bool isSelected)
 
void minLodCoverage (SLfloat minLodCoverage)
 
void levelForSM (SLubyte lfsm)
 
void onUpdateCB (function< void()> callbackFunc)
 
SLNodeparent ()
 
SLint depth () const
 
SLint entityID () const
 
const SLMat4fom ()
 
const SLMat4finitialOM ()
 
const SLMat4fupdateAndGetWM () const
 
const SLMat4fupdateAndGetWMI () const
 
SLDrawBitsdrawBits ()
 
SLbool drawBit (SLuint bit)
 
SLAABBoxaabb ()
 
SLAnimationanimation ()
 
SLbool castsShadows ()
 
SLMeshmesh ()
 
SLVNodechildren ()
 
const SLAnimSkeletonskeleton ()
 Returns the first skeleton found in the meshes. More...
 
void updateRec ()
 
virtual void doUpdate ()
 
bool updateMeshSkins (bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
 Update all skinned meshes recursively. More...
 
void updateMeshAccelStructs ()
 
void updateMeshMat (std::function< void(SLMaterial *m)> setMat, bool recursive)
 Updates the mesh material recursively with a material lambda. More...
 
void setMeshMat (SLMaterial *mat, bool recursive)
 Set the mesh material recursively. More...
 
bool isSelected ()
 
SLfloat minLodCoverage ()
 
SLubyte levelForSM ()
 
- 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
 
- Public Member Functions inherited from SLEventHandler
 SLEventHandler ()
 
virtual ~SLEventHandler ()
 
virtual SLbool onMouseDown (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseUp (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseMove (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onDoubleClick (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseWheel (const SLint delta, const SLKey mod)
 
virtual SLbool onTouch2Down (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Move (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Up (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch3Down (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Move (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Up (const SLint x1, const SLint y1)
 
virtual SLbool onKeyPress (const SLKey key, const SLKey mod)
 
virtual SLbool onKeyRelease (const SLKey key, const SLKey mod)
 
virtual SLbool onRotationPYR (const SLfloat pitchRAD, const SLfloat yawRAD, const SLfloat rollRAD)
 
void mouseRotationFactor (SLfloat rf)
 
SLfloat mouseRotationFactor ()
 
- Public Member Functions inherited from SLLight
 SLLight (SLfloat ambiPower=0.1f, SLfloat diffPower=1.0f, SLfloat specPower=1.0f, SLint id=-1)
 Construct a new SLLight::SLLight object. More...
 
virtual ~SLLight ()=default
 
void id (const SLint id)
 
void isOn (const SLbool on)
 
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. More...
 
void ambiDiffPowers (SLfloat ambiPow, SLfloat diffPow, const SLCol4f &ambiDiffCol=SLCol4f::WHITE)
 Sets the ambient and diffuse powers with the same color. More...
 
void ambiDiffColor (const SLCol4f &ambiDiffCol)
 Sets the same color to the ambient and diffuse colors. More...
 
void ambientColor (const SLCol4f &ambi)
 
void ambientPower (const SLfloat ambPow)
 
void diffuseColor (const SLCol4f &diff)
 
void diffusePower (const SLfloat diffPow)
 
void specularColor (const SLCol4f &spec)
 
void specularPower (const SLfloat specPow)
 
void spotExponent (const SLfloat exp)
 
void spotCutOffDEG (SLfloat cutOffAngleDEG)
 
void kc (SLfloat kc)
 
void kl (SLfloat kl)
 
void kq (SLfloat kq)
 
void attenuation (const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
 
void createsShadows (SLbool createsShadows)
 
void shadowMap (SLShadowMap *shadowMap)
 
void doSmoothShadows (SLbool doSS)
 
void smoothShadowLevel (SLuint ssLevel)
 
void shadowMinBias (SLfloat minBias)
 
void shadowMaxBias (SLfloat maxBias)
 
SLint id () const
 
SLbool isOn () const
 
SLCol4f ambientColor ()
 
SLfloat ambientPower () const
 
SLCol4f diffuseColor ()
 
SLfloat diffusePower () const
 
SLCol4f specularColor ()
 
SLfloat specularPower () const
 
SLfloat spotCutOffDEG () const
 
SLfloat spotCosCut () const
 
SLfloat spotExponent () const
 
SLfloat kc () const
 
SLfloat kl () const
 
SLfloat kq () const
 
SLbool isAttenuated () const
 
SLfloat attenuation (SLfloat dist) const
 
SLbool createsShadows () const
 
SLShadowMapshadowMap ()
 
SLbool doSoftShadows () const
 
SLuint softShadowLevel () const
 
SLfloat shadowMinBias () const
 
SLfloat shadowMaxBias () const
 
virtual SLbool doCascadedShadows () const
 
virtual void renderShadowMap (SLSceneView *sv, SLNode *root)
 SLLight::renderShadowMap renders the shadow map of the light. More...
 

Private Attributes

SLfloat _width
 Width of square light in x direction. More...
 
SLfloat _height
 Lenght of square light in y direction. More...
 
SLfloat _halfWidth
 Half width of square light in x dir. More...
 
SLfloat _halfHeight
 Half height of square light in y dir. More...
 
SLVec2i _samples
 Uneven NO. of samples in x and y dir. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from SLLight
static SLfloat oneOverGamma ()
 
- Static Public Attributes inherited from SLNode
static SLuint numWMUpdates = 0
 NO. of calls to updateWMRec per frame. More...
 
static unsigned int instanceIndex = 0
 ??? More...
 
- Static Public Attributes inherited from SLLight
static SLCol4f globalAmbient = SLCol4f(0.1f, 0.1f, 0.1f, 1.0f)
 static global ambient light intensity More...
 
static SLfloat gamma = 1.0f
 final output gamma value More...
 
static SLbool doColoredShadows = false
 flag if shadows should be displayed with colors for debugging More...
 
- Protected Attributes inherited from SLNode
SLNode_parent
 pointer to the parent node More...
 
SLVNode _children
 vector of children nodes More...
 
SLMesh_mesh
 pointer to a single mesh More...
 
SLint _depth
 depth of the node in a scene tree More...
 
SLint _entityID
 ID in the SLVEntity graph for Data Oriented Design. More...
 
SLMat4f _om
 object matrix for local transforms More...
 
SLMat4f _initialOM
 the initial om state More...
 
SLMat4f _wm
 world matrix for world transform More...
 
SLMat4f _wmI
 inverse world matrix More...
 
SLbool _isWMUpToDate
 is the WM of this node still valid More...
 
SLbool _isWMIUpToDate
 is the inverse WM of this node still valid More...
 
SLbool _isAABBUpToDate
 is the saved aabb still valid More...
 
bool _castsShadows
 flag if meshes of node should cast shadows More...
 
bool _isSelected
 flag if node and one or more of its meshes are selected More...
 
SLDrawBits _drawBits
 node level drawing flags More...
 
SLAABBox _aabb
 axis aligned bounding box More...
 
SLAnimation_animation
 animation of the node More...
 
SLfloat _minLodCoverage
 Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0) More...
 
SLubyte _levelForSM
 Level of LOD to use for shadow mapping (0 = the visible one will be drawn) More...
 
function< void()> _onUpdateCB
 Optional lambda callback once per update. More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 
- Protected Attributes inherited from SLEventHandler
SLfloat _mouseRotationFactor
 Mouse rotation sensibility. More...
 
SLfloat _keyboardDeltaPos
 Delta dist. for keyboard translation. More...
 
- Protected Attributes inherited from SLLight
SLint _id
 OpenGL light number (0-7) More...
 
SLbool _isOn
 Flag if light is on or off. More...
 
SLCol4f _ambientColor
 Ambient light color (RGB 0-1) More...
 
SLfloat _ambientPower
 Ambient light power (0-N) More...
 
SLCol4f _diffuseColor
 Diffuse light color (RGB 0-1) More...
 
SLfloat _diffusePower
 Diffuse light power (0-N) More...
 
SLCol4f _specularColor
 Specular light color (RGB 0-1) More...
 
SLfloat _specularPower
 Specular light power (0-N) More...
 
SLfloat _spotCutOffDEG
 Half the spot cone angle. More...
 
SLfloat _spotCosCutOffRAD
 cosine of spotCutoff angle More...
 
SLfloat _spotExponent
 Spot attenuation from center to edge of cone. More...
 
SLfloat _kc
 Constant light attenuation. More...
 
SLfloat _kl
 Linear light attenuation. More...
 
SLfloat _kq
 Quadratic light attenuation. More...
 
SLbool _isAttenuated
 fast attenuation flag for ray tracing More...
 
SLbool _createsShadows
 flag if light creates shadows or not More...
 
SLShadowMap_shadowMap
 Used for shadow mapping. More...
 
SLbool _doSoftShadows
 flag if percentage-closer filtering for smooth shadows is enabled More...
 
SLuint _softShadowLevel
 Radius to smoothing (1 = 3 * 3; 2 = 5 * 5; ...) More...
 
SLfloat _shadowMinBias
 Min. bias at 0 deg. to use to prevent shadow acne. More...
 
SLfloat _shadowMaxBias
 Max. bias at 90 deg. to use to prevent shadow acne. More...
 

Detailed Description

Light node class for a rectangular light source.

SLLightRect is a node that renders in OpenGL a light rectangle object and applies the OpenGL light settings through the SLLight class. The light rectangle is defined with its width and height and lies initially centered in the x-y-plane. The light shines as a spotlight with 90 degrees cutoff angle towards the negative z-axis.
If a light node is added to the scene it stays fix in the scene.
If a light node is added to the camera it moves with the camera.
See the scene examples for Per-Vertex-Blinn or Per-Pixel-Blinn lighting where all light node types are used.
All light nodes inherited from SLLight work automatically together with the automatically generated shader in SLGLProgramGenerated.

Definition at line 37 of file SLLightRect.h.

Constructor & Destructor Documentation

◆ SLLightRect()

SLLightRect::SLLightRect ( SLAssetManager assetMgr,
SLScene s,
SLfloat  w = 1,
SLfloat  h = 1,
SLbool  hasMesh = true 
)

Construct a new SLLightRect::SLLightRect object.

Remarks
It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within an SLScene::registerAssetsToLoad or SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread.
Parameters
assetMgrAssetManager that will own the light mesh
sSLScene pointer
wWidth of the light rectangle
hHeight if the light rectangle
hasMeshBoolean if a mesh should be created and shown

Definition at line 34 of file SLLightRect.cpp.

38  : SLNode("LightRect Node")
39 {
40  width(w);
41  height(h);
42  _castsShadows = false;
43  _samples.set(1, 1);
44 
45  // make sample number even
46  if (_samples.x % 2 == 0) _samples.x++;
47  if (_samples.y % 2 == 0) _samples.y++;
48 
49  spotCutOffDEG(90.0f);
50  spotExponent(1.0);
51 
52  if (hasMesh)
53  {
54  SLMaterial* mat = new SLMaterial(assetMgr,
55  "LightRect Mesh Mat",
58  addMesh(new SLPolygon(assetMgr, w, h, "LightRect Mesh", mat));
59  _castsShadows = false;
60  }
61  init(s);
62 }
SLfloat spotCutOffDEG() const
Definition: SLLight.h:140
SLfloat spotExponent() const
Definition: SLLight.h:142
void init(SLScene *s)
Definition: SLLightRect.cpp:73
SLfloat width() const
Definition: SLLightRect.h:84
SLfloat height() const
Definition: SLLightRect.h:85
SLVec2i _samples
Uneven NO. of samples in x and y dir.
Definition: SLLightRect.h:105
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
bool _castsShadows
flag if meshes of node should cast shadows
Definition: SLNode.h:357
virtual void addMesh(SLMesh *mesh)
Definition: SLNode.cpp:157
SLNode(const SLstring &name="Node")
Construct a new SLNode::SLNode object.
Definition: SLNode.cpp:40
SLPolygon creates a convex polyon mesh.
Definition: SLPolygon.h:29
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
T y
Definition: SLVec2.h:30
T x
Definition: SLVec2.h:30
void set(const T X, const T Y)
Definition: SLVec2.h:40
static SLVec4 BLACK
Definition: SLVec4.h:213

◆ ~SLLightRect()

SLLightRect::~SLLightRect ( )
override

Definition at line 64 of file SLLightRect.cpp.

65 {
66  delete _shadowMap;
67 }
SLShadowMap * _shadowMap
Used for shadow mapping.
Definition: SLLight.h:224

Member Function Documentation

◆ ambient()

SLCol4f SLLightRect::ambient ( )
inlineoverridevirtual

Return normally _ambientColor * _ambientPower.

Implements SLLight.

Definition at line 88 of file SLLightRect.h.

88 { return _ambientColor * _ambientPower; }
SLCol4f _ambientColor
Ambient light color (RGB 0-1)
Definition: SLLight.h:210
SLfloat _ambientPower
Ambient light power (0-N)
Definition: SLLight.h:211

◆ createShadowMap()

void SLLightRect::createShadowMap ( float  lightClipNear = 0.1f,
float  lightClipFar = 20.0f,
SLVec2f  size = SLVec2f(8, 8),
SLVec2i  texSize = SLVec2i(1024, 1024) 
)
overridevirtual

Creates an fixed sized standard shadow map for a rectangular light.

Parameters
lightClipNearThe light frustums near clipping distance
lightClipFarThe light frustums near clipping distance
sizeIgnored for rectangular lights
texSizeShadow texture map size

Implements SLLight.

Definition at line 289 of file SLLightRect.cpp.

293 {
294  if (!_shadowMap)
295  delete _shadowMap;
296 
297  _shadowMap = new SLShadowMap(this,
298  lightClipNear,
299  lightClipFar,
300  size,
301  texSize);
302 }
Class for standard and cascaded shadow mapping.
Definition: SLShadowMap.h:39

◆ createShadowMapAutoSize()

void SLLightRect::createShadowMapAutoSize ( SLCamera camera,
SLVec2i  texSize = SLVec2i(1024, 1024),
int  numCascades = 0 
)
overridevirtual

Creates an automatic sized shadow map for the rectangular light.

Parameters
cameraPointer to the camera for witch the shadow map gets sized
texSizeShadow texture map size (equal for all cascades)
numCascadesThis value is ignored (default 0)

Implements SLLight.

Definition at line 309 of file SLLightRect.cpp.

312 {
313  (void)numCascades;
314  if (!_shadowMap)
315  delete _shadowMap;
316 
317  _shadowMap = new SLShadowMap(this,
318  camera,
319  texSize,
320  0);
321 }
typedef void(SL_STDCALL *cbOnImGuiBuild)(SLScene *s
Callback function typedef for ImGui build function.

◆ diffuse()

SLCol4f SLLightRect::diffuse ( )
inlineoverridevirtual

Returns normally _diffuseColor * _diffusePower.

Implements SLLight.

Definition at line 89 of file SLLightRect.h.

89 { return _diffuseColor * _diffusePower; }
SLfloat _diffusePower
Diffuse light power (0-N)
Definition: SLLight.h:213
SLCol4f _diffuseColor
Diffuse light color (RGB 0-1)
Definition: SLLight.h:212

◆ drawMesh()

void SLLightRect::drawMesh ( SLSceneView sv)
overridevirtual

SLLightRect::drawMeshes sets the light states and calls then the drawMeshes method of its node.

Reimplemented from SLNode.

Definition at line 119 of file SLLightRect.cpp.

120 {
121  if (_id != -1)
122  {
123  // Set emissive light material to the lights diffuse color
124  if (_mesh)
125  {
126  if (_mesh->mat())
128  }
129 
130  // now draw the meshes of the node
132 
133  // Draw the volume affected by the shadow map
134  if (_createsShadows && _isOn && sv->s()->singleNodeSelected() == this)
135  {
137  _shadowMap->drawRays();
138  }
139  }
140 }
SLint _id
OpenGL light number (0-7)
Definition: SLLight.h:208
SLbool _isOn
Flag if light is on or off.
Definition: SLLight.h:209
SLbool _createsShadows
flag if light creates shadows or not
Definition: SLLight.h:223
SLCol4f diffuse() override
Returns normally _diffuseColor * _diffusePower.
Definition: SLLightRect.h:89
void emissive(const SLCol4f &emis)
Definition: SLMaterial.h:174
SLMaterial * mat() const
Definition: SLMesh.h:177
virtual void drawMesh(SLSceneView *sv)
Draws the single mesh.
Definition: SLNode.cpp:176
SLMesh * _mesh
pointer to a single mesh
Definition: SLNode.h:346
SLNode * singleNodeSelected()
Returns the node if only one is selected. See also SLMesh::selectNodeMesh.
Definition: SLScene.h:116
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
SLScene * s()
Definition: SLSceneView.h:167
void drawFrustum()
SLShadowMap::drawFrustum draws the volume affected by the shadow map.
void drawRays()

◆ height() [1/2]

SLfloat SLLightRect::height ( ) const
inline

Definition at line 85 of file SLLightRect.h.

85 { return _height; }
SLfloat _height
Lenght of square light in y direction.
Definition: SLLightRect.h:102

◆ height() [2/2]

void SLLightRect::height ( const SLfloat  h)
inline

Definition at line 75 of file SLLightRect.h.

76  {
77  _height = h;
78  _halfHeight = h * 0.5f;
79  }
SLfloat _halfHeight
Half height of square light in y dir.
Definition: SLLightRect.h:104

◆ hitRec()

SLbool SLLightRect::hitRec ( SLRay ray)
overridevirtual

SLLightRect::hitRec calls the nodes intersection code.

Reimplemented from SLNode.

Definition at line 96 of file SLLightRect.cpp.

97 {
98  // do not intersect shadow rays
99  if (ray->type == SHADOW) return false;
100 
101  // only allow intersection with primary rays (no lights in reflections)
102  // if (ray->type!=PRIMARY) return false;
103 
104  // call the intersection routine of the node
105  return SLNode::hitRec(ray);
106 }
@ SHADOW
Definition: SLRay.h:26
virtual bool hitRec(SLRay *ray)
Definition: SLNode.cpp:508
SLRayType type
PRIMARY, REFLECTED, REFRACTED, SHADOW.
Definition: SLRay.h:92

◆ init()

void SLLightRect::init ( SLScene s)

SLLightRect::init sets the light id, the light states & creates an emissive mat.

Definition at line 73 of file SLLightRect.cpp.

74 {
75  // Check if OpenGL lights are available
76  if (s->lights().size() >= SL_MAX_LIGHTS)
77  SL_EXIT_MSG("Max. NO. of lights is exceeded!");
78 
79  // Add the light to the lights vector of the scene
80  if (_id == -1)
81  {
82  _id = (SLint)s->lights().size();
83  s->lights().push_back(this);
84  }
85 
86  // Set emissive light material to the lights diffuse color
87  if (_mesh)
88  if (_mesh->mat())
90 }
#define SL_EXIT_MSG(message)
Definition: SL.h:240
int SLint
Definition: SL.h:170
static const SLint SL_MAX_LIGHTS
max. number of used lights
Definition: SLGLState.h:49
SLCol4f diffuseColor()
Definition: SLLight.h:136
SLVLight & lights()
Definition: SLScene.h:107

◆ positionWS()

SLVec4f SLLightRect::positionWS ( ) const
inlineoverridevirtual

Implements SLLight.

Definition at line 91 of file SLLightRect.h.

91 { return SLVec4f(updateAndGetWM().translation()); }
SLVec4< SLfloat > SLVec4f
Definition: SLVec4.h:235
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
const SLMat4f & updateAndGetWM() const
Definition: SLNode.cpp:703

◆ samples()

void SLLightRect::samples ( SLVec2i  samples)

Definition at line 323 of file SLLightRect.cpp.

324 {
325  assert(samples.x % 2 == 1 && samples.y % 2 == 1);
326  _samples = samples;
327 }
void samples(SLVec2i samples)

◆ samplesXY()

void SLLightRect::samplesXY ( SLint  x,
SLint  y 
)

Definition at line 329 of file SLLightRect.cpp.

330 {
331  assert(x % 2 == 1 && y % 2 == 1);
332  _samples.set(x, y);
333 }

◆ shadowTest()

SLfloat SLLightRect::shadowTest ( SLRay ray,
const SLVec3f L,
SLfloat  lightDist,
SLNode root3D 
)
overridevirtual

SLLightRect::shadowTest returns 0.0 if the hit point is completely shaded and 1.0 if it is 100% lighted. A return value inbetween is calculate by the ratio of the shadow rays not blocked to the total number of casted shadow rays.

Implements SLLight.

Definition at line 147 of file SLLightRect.cpp.

151 {
152  if (_samples.x == 1 && _samples.y == 1)
153  {
154  // define shadow ray
155  SLRay shadowRay(lightDist, L, ray);
156 
157  root3D->hitRec(&shadowRay);
158 
159  return (shadowRay.length < lightDist) ? 0.0f : 1.0f;
160  }
161  else // do light sampling for soft shadows
162  {
163  SLfloat dw = (SLfloat)_width / (SLfloat)_samples.x; // width of a sample cell
164  SLfloat dl = (SLfloat)_height / (SLfloat)_samples.y; // length of a sample cell
165  SLint x = 0, y = 0, hx = _samples.x / 2, hy = _samples.y / 2;
167  SLVbool isSampled;
168  SLbool importantPointsAreLighting = true;
169  SLfloat lighted = 0.0f; // return value
170  SLfloat invSamples = 1.0f / (SLfloat)(samples);
171  SLVec3f SP; // vector hit point to sample point in world coords
172 
173  isSampled.resize((SLuint)samples);
174 
175  for (y = 0; y < _samples.y; ++y)
176  {
177  for (x = 0; x < _samples.x; ++x)
178  {
179  SLint iSP = y * _samples.x + x;
180  isSampled[(SLuint)iSP] = false;
181  }
182  }
183 
184  /*
185  Important sample points (X) on a 7 by 5 rectangular light.
186  If all of them are lighting the hit point the sample points
187  in between (O) are not tested anymore.
188 
189  0 1 2 3 4 5 6
190  +---+---+---+---+---+---+---+
191  0 | X | . | . | X | . | . | X |
192  +---+---+---+---+---+---+---+
193  1 | . | . | . | . | . | . | . |
194  +---+---+---+---+---+---+---+
195  2 | X | . | . | X | . | . | X |
196  +---+---+---+---+---+---+---+
197  3 | . | . | . | . | . | . | . |
198  +---+---+---+---+---+---+---+
199  4 | X | . | . | X | . | . | X |
200  +---+---+---+---+---+---+---+
201  */
202 
203  // Double loop for the important sample points
204  for (y = -hy; y <= hy; y += hy)
205  {
206  for (x = -hx; x <= hx; x += hx)
207  {
208  SLint iSP = (y + hy) * _samples.x + x + hx;
209  isSampled[(SLuint)iSP] = true;
210 
211  SP.set(updateAndGetWM().multVec(SLVec3f(x * dw, y * dl, 0)) - ray->hitPoint);
212  SLfloat SPDist = SP.length();
213  SP.normalize();
214  SLRay shadowRay(SPDist, SP, ray);
215 
216  root3D->hitRec(&shadowRay);
217 
218  if (shadowRay.length >= SPDist - FLT_EPSILON)
219  lighted += invSamples; // sum up the light
220  else
221  importantPointsAreLighting = false;
222  }
223  }
224 
225  if (importantPointsAreLighting)
226  lighted = 1.0f;
227  else
228  { // Double loop for the sample points in between
229  for (y = -hy; y <= hy; ++y)
230  {
231  for (x = -hx; x <= hx; ++x)
232  {
233  SLint iSP = (y + hy) * _samples.x + x + hx;
234  if (!isSampled[(SLuint)iSP])
235  {
236  SP.set(updateAndGetWM().multVec(SLVec3f(x * dw, y * dl, 0)) - ray->hitPoint);
237  SLfloat SPDist = SP.length();
238  SP.normalize();
239  SLRay shadowRay(SPDist, SP, ray);
240 
241  root3D->hitRec(&shadowRay);
242 
243  // sum up the light
244  if (shadowRay.length >= SPDist - FLT_EPSILON)
245  lighted += invSamples;
246  }
247  }
248  }
249  }
250  return lighted;
251  }
252 }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
vector< SLbool > SLVbool
Definition: SL.h:189
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
SLfloat _width
Width of square light in x direction.
Definition: SLLightRect.h:101
SLVec3< T > multVec(SLVec3< T > v) const
Definition: SLMat4.h:576
Ray class with ray and intersection properties.
Definition: SLRay.h:40
SLVec3f hitPoint
Point of intersection.
Definition: SLRay.h:110
SLVec3 & normalize()
Definition: SLVec3.h:124
T length() const
Definition: SLVec3.h:122
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59

◆ shadowTestMC()

SLfloat SLLightRect::shadowTestMC ( SLRay ray,
const SLVec3f L,
SLfloat  lightDist,
SLNode root3D 
)
overridevirtual

SLLightRect::shadowTestMC returns 0.0 if the hit point is shaded and 1.0 if it lighted. Only one shadow sample is tested for path tracing.

Implements SLLight.

Definition at line 258 of file SLLightRect.cpp.

262 {
263  SLfloat rndX = rnd01();
264  SLfloat rndY = rnd01();
265 
266  // Sample point in object space
267  SLVec3f spOS(SLVec3f(rndX * _width - _width * 0.5f,
268  rndY * _height - _height * 0.5f,
269  0.0f));
270 
271  // Sample point in world space
272  SLVec3f spWS(updateAndGetWM().multVec(spOS) - ray->hitPoint);
273 
274  SLfloat spDistWS = spWS.length();
275  spWS.normalize();
276  SLRay shadowRay(spDistWS, spWS, ray);
277 
278  root3D->hitRec(&shadowRay);
279 
280  return (shadowRay.length < spDistWS) ? 0.0f : 1.0f;
281 }
SLfloat rnd01()
Definition: SLRay.cpp:39

◆ specular()

SLCol4f SLLightRect::specular ( )
inlineoverridevirtual

Returns normally _specularColor * _specularPower.

Implements SLLight.

Definition at line 90 of file SLLightRect.h.

90 { return _specularColor * _specularPower; }
SLfloat _specularPower
Specular light power (0-N)
Definition: SLLight.h:215
SLCol4f _specularColor
Specular light color (RGB 0-1)
Definition: SLLight.h:214

◆ spotDirWS()

SLVec3f SLLightRect::spotDirWS ( )
inlineoverridevirtual

Implements SLLight.

Definition at line 92 of file SLLightRect.h.

93  {
94  return SLVec3f(_wm.m(8),
95  _wm.m(9),
96  _wm.m(10)) *
97  -1.0;
98  }
void m(int i, T val)
Definition: SLMat4.h:93
SLMat4f _wm
world matrix for world transform
Definition: SLNode.h:352

◆ statsRec()

void SLLightRect::statsRec ( SLNodeStats stats)
overridevirtual

SLLightSpot::statsRec updates the statistic parameters.

Reimplemented from SLNode.

Definition at line 109 of file SLLightRect.cpp.

110 {
111  stats.numBytes += sizeof(SLLightRect);
112  SLNode::statsRec(stats);
113 }
SLLightRect(SLAssetManager *assetMgr, SLScene *s, SLfloat width=1, SLfloat height=1, SLbool hasMesh=true)
Construct a new SLLightRect::SLLightRect object.
Definition: SLLightRect.cpp:34
virtual void statsRec(SLNodeStats &stats)
Definition: SLNode.cpp:479
SLuint numBytes
NO. of bytes allocated.
Definition: SLNode.h:39

◆ width() [1/2]

SLfloat SLLightRect::width ( ) const
inline

Definition at line 84 of file SLLightRect.h.

84 { return _width; }

◆ width() [2/2]

void SLLightRect::width ( const SLfloat  w)
inline

Definition at line 70 of file SLLightRect.h.

71  {
72  _width = w;
73  _halfWidth = w * 0.5f;
74  }
SLfloat _halfWidth
Half width of square light in x dir.
Definition: SLLightRect.h:103

Member Data Documentation

◆ _halfHeight

SLfloat SLLightRect::_halfHeight
private

Half height of square light in y dir.

Definition at line 104 of file SLLightRect.h.

◆ _halfWidth

SLfloat SLLightRect::_halfWidth
private

Half width of square light in x dir.

Definition at line 103 of file SLLightRect.h.

◆ _height

SLfloat SLLightRect::_height
private

Lenght of square light in y direction.

Definition at line 102 of file SLLightRect.h.

◆ _samples

SLVec2i SLLightRect::_samples
private

Uneven NO. of samples in x and y dir.

Definition at line 105 of file SLLightRect.h.

◆ _width

SLfloat SLLightRect::_width
private

Width of square light in x direction.

Definition at line 101 of file SLLightRect.h.


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