SLProject 4.0.000
SLLightSpot Class Reference

SLLightSpot class for a spot light source. More...

#include <SLLightSpot.h>

Inheritance diagram for SLLightSpot:
[legend]

Public Member Functions

 SLLightSpot (SLAssetManager *assetMgr, SLScene *s, SLfloat radius=0.3f, SLfloat spotAngleDEG=180.0f, SLbool hasMesh=true)
 
 SLLightSpot (SLAssetManager *assetMgr, SLScene *s, SLfloat posx, SLfloat posy, SLfloat posz, SLfloat radius=0.3f, SLfloat spotAngleDEG=180.0f, SLfloat ambiPower=1.0f, SLfloat diffPower=10.0f, SLfloat specPower=10.0f, SLbool hasMesh=true)
 
 ~SLLightSpot () 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 samples (SLuint x, SLuint y)
 
SLfloat radius () const
 
SLuint samples ()
 
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")
 
 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)
 
virtual void cull2DRec (SLSceneView *sv)
 
virtual bool hitRec (SLRay *ray)
 
virtual void statsRec (SLNodeStats &stats)
 
virtual SLNodecopyRec ()
 
virtual SLAABBoxupdateAABBRec (SLbool updateAlsoAABBinOS)
 
virtual void dumpRec ()
 
void setDrawBitsRec (SLuint bit, SLbool state)
 
void setPrimitiveTypeRec (SLGLPrimitiveType primitiveType)
 
virtual void addMesh (SLMesh *mesh)
 
virtual void drawMesh (SLSceneView *sv)
 Draws the single mesh. More...
 
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 (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)
 
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 SLCol4f ambient ()=0
 Return normally _ambientColor * _ambientPower. More...
 
virtual SLCol4f diffuse ()=0
 Returns normally _diffuseColor * _diffusePower. More...
 
virtual SLCol4f specular ()=0
 Returns normally _specularColor * _specularPower. More...
 
virtual SLVec4f positionWS () const =0
 
virtual SLVec3f spotDirWS ()=0
 
virtual SLfloat shadowTest (SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D)=0
 
virtual SLfloat shadowTestMC (SLRay *ray, const SLVec3f &L, SLfloat lightDist, SLNode *root3D)=0
 
virtual void createShadowMap (float lightClipNear=0.1f, float lightClipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024))=0
 
virtual void createShadowMapAutoSize (SLCamera *camera, SLVec2i texSize=SLVec2i(1024, 1024), int numCascades=0)=0
 
virtual void renderShadowMap (SLSceneView *sv, SLNode *root)
 SLLight::renderShadowMap renders the shadow map of the light. More...
 

Private Attributes

SLfloat _radius
 The sphere lights radius. More...
 
SLRaySamples2D _samples
 2D sample points for soft shadows 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

SLLightSpot class for a spot light source.

SLLightSpot is a node and a light that can have a spot mesh for its representation. 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.

Constructor & Destructor Documentation

◆ SLLightSpot() [1/2]

SLLightSpot::SLLightSpot ( SLAssetManager assetMgr,
SLScene s,
SLfloat  radius = 0.3f,
SLfloat  spotAngleDEG = 180.0f,
SLbool  hasMesh = true 
)
explicit

◆ SLLightSpot() [2/2]

SLLightSpot::SLLightSpot ( SLAssetManager assetMgr,
SLScene s,
SLfloat  posx,
SLfloat  posy,
SLfloat  posz,
SLfloat  radius = 0.3f,
SLfloat  spotAngleDEG = 180.0f,
SLfloat  ambiPower = 1.0f,
SLfloat  diffPower = 10.0f,
SLfloat  specPower = 10.0f,
SLbool  hasMesh = true 
)

◆ ~SLLightSpot()

SLLightSpot::~SLLightSpot ( )
override

Member Function Documentation

◆ ambient()

SLCol4f SLLightSpot::ambient ( )
inlineoverridevirtual

Return normally _ambientColor * _ambientPower.

Implements SLLight.

◆ createShadowMap()

void SLLightSpot::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 the spotlight.

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

Implements SLLight.

◆ createShadowMapAutoSize()

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

Creates an automatic sized shadow map for the spot light.

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

Implements SLLight.

◆ diffuse()

SLCol4f SLLightSpot::diffuse ( )
inlineoverridevirtual

Returns normally _diffuseColor * _diffusePower.

Implements SLLight.

◆ drawMesh()

void SLLightSpot::drawMesh ( SLSceneView sv)
overridevirtual

SLLightSpot::drawMesh sets the light states and calls then the drawMesh method of its node.

Reimplemented from SLNode.

◆ hitRec()

SLbool SLLightSpot::hitRec ( SLRay ray)
overridevirtual

SLLightSpot::hitRec calls the recursive node intersection.

Reimplemented from SLNode.

◆ init()

void SLLightSpot::init ( SLScene s)

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

Todo:
properly remove this function and find a clean way to init lights in a scene

◆ positionWS()

SLVec4f SLLightSpot::positionWS ( ) const
inlineoverridevirtual

Implements SLLight.

◆ radius()

SLfloat SLLightSpot::radius ( ) const
inline

◆ samples() [1/2]

SLuint SLLightSpot::samples ( )
inline

◆ samples() [2/2]

void SLLightSpot::samples ( SLuint  x,
SLuint  y 
)
inline

◆ shadowTest()

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

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

Implements SLLight.

◆ shadowTestMC()

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

SLLightSpot::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.

◆ specular()

SLCol4f SLLightSpot::specular ( )
inlineoverridevirtual

Returns normally _specularColor * _specularPower.

Implements SLLight.

◆ spotDirWS()

SLVec3f SLLightSpot::spotDirWS ( )
inlineoverridevirtual

Implements SLLight.

◆ statsRec()

void SLLightSpot::statsRec ( SLNodeStats stats)
overridevirtual

SLLightSpot::statsRec updates the statistic parameters.

Reimplemented from SLNode.

Member Data Documentation

◆ _radius

SLfloat SLLightSpot::_radius
private

The sphere lights radius.

◆ _samples

SLRaySamples2D SLLightSpot::_samples
private

2D sample points for soft shadows


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