Nameless Engine
Loading...
Searching...
No Matches
ne::SpotlightNode Class Reference

#include <SpotlightNode.h>

Inheritance diagram for ne::SpotlightNode:
ne::SpatialNode ne::Node ne::Serializable

Classes

struct  ShaderData
 
struct  SpotlightShaderData
 

Public Member Functions

 SpotlightNode (const std::string &sNodeName)
 
void setLightColor (const glm::vec3 &color)
 
void setLightIntensity (float intensity)
 
void setLightDistance (float distance)
 
void setLightInnerConeAngle (float innerConeAngle)
 
void setLightOuterConeAngle (float outerConeAngle)
 
glm::vec3 getLightColor () const
 
float getLightIntensity () const
 
float getLightDistance () const
 
float getLightInnerConeAngle () const
 
float getLightOuterConeAngle () const
 
std::pair< std::mutex, Cone > * getShape ()
 
- Public Member Functions inherited from ne::SpatialNode
 SpatialNode (const std::string &sNodeName)
 
void setRelativeLocation (const glm::vec3 &location)
 
void setRelativeRotation (const glm::vec3 &rotation)
 
void setRelativeScale (const glm::vec3 &scale)
 
void setWorldLocation (const glm::vec3 &location)
 
void setWorldRotation (const glm::vec3 &rotation)
 
void setWorldScale (const glm::vec3 &scale)
 
glm::vec3 getRelativeLocation () const
 
glm::vec3 getRelativeRotation () const
 
glm::vec3 getRelativeScale () const
 
glm::mat4x4 getRelativeRotationMatrix ()
 
glm::vec3 getWorldLocation ()
 
glm::vec3 getWorldRotation ()
 
glm::quat getWorldRotationQuaternion ()
 
glm::vec3 getWorldScale ()
 
glm::vec3 getWorldForwardDirection ()
 
glm::vec3 getWorldRightDirection ()
 
glm::vec3 getWorldUpDirection ()
 
glm::mat4x4 getWorldMatrix ()
 
std::pair< std::recursive_mutex, sgc::GcPtr< SpatialNode > > * getClosestSpatialParent ()
 
- Public Member Functions inherited from ne::Node
 Node ()
 
 Node (const std::string &sName)
 
 Node (const Node &)=delete
 
Nodeoperator= (const Node &)=delete
 
 Node (Node &&)=delete
 
Nodeoperator= (Node &&)=delete
 
virtual ~Node () override
 
void setNodeName (const std::string &sName)
 
void detachFromParentAndDespawn ()
 
void addChildNode (const sgc::GcPtr< Node > &pNode, AttachmentRule locationRule=AttachmentRule::KEEP_WORLD, AttachmentRule rotationRule=AttachmentRule::KEEP_WORLD, AttachmentRule scaleRule=AttachmentRule::KEEP_WORLD)
 
void setSerialize (bool bSerialize)
 
std::optional< ErrorserializeNodeTree (const std::filesystem::path &pathToFile, bool bEnableBackup)
 
std::string getNodeName () const
 
sgc::GcPtr< NodegetWorldRootNode ()
 
std::pair< std::recursive_mutex, sgc::GcPtr< Node > > * getParentNode ()
 
std::pair< std::recursive_mutex, sgc::GcVector< sgc::GcPtr< Node > > > * getChildNodes ()
 
template<typename NodeType >
requires std::derived_from<NodeType, Node>
sgc::GcPtr< NodeType > getParentNodeOfType (const std::string &sParentNodeName="")
 
template<typename NodeType >
requires std::derived_from<NodeType, Node>
sgc::GcPtr< NodeType > getChildNodeOfType (const std::string &sChildNodeName="")
 
TickGroup getTickGroup () const
 
std::optional< size_t > getNodeId () const
 
bool isCalledEveryFrame ()
 
bool isReceivingInput ()
 
bool isSpawned ()
 
bool isParentOf (Node *pNode)
 
bool isChildOf (Node *pNode)
 
bool isSerialized () const
 
- Public Member Functions inherited from ne::Serializable
std::optional< Errorserialize (std::filesystem::path pathToFile, bool bEnableBackup, const std::unordered_map< std::string, std::string > &customAttributes={})
 
std::variant< std::string, Errorserialize (toml::value &tomlData, const std::string &sEntityId="", const std::unordered_map< std::string, std::string > &customAttributes={}, const std::optional< std::filesystem::path > &optionalPathToFile={}, bool bEnableBackup=false)
 
std::variant< std::string, Errorserialize (toml::value &tomlData, Serializable *pOriginalObject, std::string sEntityId="", const std::unordered_map< std::string, std::string > &customAttributes={}, const std::optional< std::filesystem::path > &optionalPathToFile={}, bool bEnableBackup=false)
 
std::optional< std::pair< std::string, std::string > > getPathDeserializedFromRelativeToRes () const
 

Static Public Member Functions

static constexpr float getMaxLightConeAngle ()
 
- Static Public Member Functions inherited from ne::Node
static size_t getAliveNodeCount ()
 
static std::variant< sgc::GcPtr< Node >, ErrordeserializeNodeTree (const std::filesystem::path &pathToFile)
 
static GameInstancegetGameInstance ()
 
- Static Public Member Functions inherited from ne::Serializable
static std::optional< ErrorserializeMultiple (std::filesystem::path pathToFile, std::vector< SerializableObjectInformation > vObjects, bool bEnableBackup)
 
static std::variant< std::set< std::string >, ErrorgetIdsFromFile (std::filesystem::path pathToFile)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (const std::filesystem::path &pathToFile)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (const std::filesystem::path &pathToFile, std::unordered_map< std::string, std::string > &customAttributes)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (std::filesystem::path pathToFile, std::unordered_map< std::string, std::string > &customAttributes, const std::string &sEntityId)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (const std::filesystem::path &pathToFile, const std::string &sEntityId)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::same_as<SmartPointer, sgc::GcPtr<Serializable>> || std::same_as<SmartPointer, std::unique_ptr<Serializable>>
static std::variant< std::vector< DeserializedObjectInformation< SmartPointer > >, ErrordeserializeMultiple (std::filesystem::path pathToFile, const std::set< std::string > &ids)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (const toml::value &tomlData, std::unordered_map< std::string, std::string > &customAttributes, std::string sEntityId="", std::optional< std::filesystem::path > optionalPathToFile={})
 

Protected Member Functions

virtual void onAfterDeserialized () override
 
virtual void onSpawning () override
 
virtual void onDespawning () override
 
virtual void onWorldLocationRotationScaleChanged () override
 
- Protected Member Functions inherited from ne::SpatialNode
virtual void onAfterDeserialized () override
 
virtual void onSpawning () override
 
virtual void onAfterAttachedToNewParent (bool bThisNodeBeingAttached) override
 
virtual void onWorldLocationRotationScaleChanged ()
 
- Protected Member Functions inherited from ne::Node
void setIsCalledEveryFrame (bool bEnable)
 
void setTickGroup (TickGroup tickGroup)
 
void setIsReceivingInput (bool bEnable)
 
TimercreateTimer (const std::string &sTimerName)
 
template<typename FunctionType >
NodeNotificationBroadcaster< FunctionType > * createNotificationBroadcaster ()
 
std::pair< std::recursive_mutex, std::unordered_map< unsigned int, std::function< void(KeyboardModifiers, bool)> > > * getActionEventBindings ()
 
std::pair< std::recursive_mutex, std::unordered_map< unsigned int, std::function< void(KeyboardModifiers, float)> > > * getAxisEventBindings ()
 
std::recursive_mutex * getSpawnDespawnMutex ()
 
virtual void onMouseMove (double xOffset, double yOffset)
 
virtual void onMouseScrollMove (int iOffset)
 
virtual void onBeforeNewFrame (float timeSincePrevFrameInSec)
 
virtual void onSpawning ()
 
virtual void onChildNodesSpawned ()
 
virtual void onDespawning ()
 
virtual void onBeforeDetachedFromParent (bool bThisNodeBeingDetached)
 
virtual void onAfterAttachedToNewParent (bool bThisNodeBeingAttached)
 
virtual void onAfterDeserialized ()
 

Private Member Functions

ShadowMapHandlegetShadowMapHandle () const
 
unsigned int getIndexIntoShadowPassInfoShaderArray ()
 
void onShadowMapArrayIndexChanged (unsigned int iNewIndexIntoArray)
 
void * onStartedUpdatingShaderData ()
 
void onFinishedUpdatingShaderData ()
 
void * onStartedUpdatingShadowPassData ()
 
void onFinishedUpdatingShadowPassData ()
 
void recalculateShadowMappingShaderData ()
 
void recalculateAndMarkShaderDataToBeCopiedToGpu ()
 
void markShaderDataToBeCopiedToGpu ()
 
void recalculateShape ()
 

Private Attributes

std::pair< std::recursive_mutex, ShaderDatamtxShaderData
 
std::pair< std::mutex, ConemtxShape
 
std::unique_ptr< ShadowMapHandlepShadowMapHandle
 
glm::vec3 color = glm::vec3(1.0F, 1.0F, 1.0F)
 
float intensity = 1.0F
 
float distance = 15.0F
 
float innerConeAngle = 25.0F
 
float outerConeAngle = 45.0F
 

Static Private Attributes

static constexpr float maxConeAngle = 80.0F
 

Friends

class Renderer
 

Additional Inherited Members

- Public Types inherited from ne::Node
enum class  AttachmentRule { RESET_RELATIVE , KEEP_RELATIVE , KEEP_WORLD }
 

Detailed Description

Represents a spotlight in world.

Constructor & Destructor Documentation

◆ SpotlightNode()

ne::SpotlightNode::SpotlightNode ( const std::string &  sNodeName)

Creates a new node with the specified name.

Parameters
sNodeNameName of this node.

Member Function Documentation

◆ getIndexIntoShadowPassInfoShaderArray()

unsigned int ne::SpotlightNode::getIndexIntoShadowPassInfoShaderArray ( )
private

Used by renderer and returns the current index (because it may change later) into the shader array that stores shadow pass info of spawned light sources.

Returns
Index into array.

◆ getLightColor()

glm::vec3 ne::SpotlightNode::getLightColor ( ) const

Returns color of this light source.

Returns
Color in RGB format in range [0.0; 1.0].

◆ getLightDistance()

float ne::SpotlightNode::getLightDistance ( ) const

Returns lit distance.

Returns
Distance.

◆ getLightInnerConeAngle()

float ne::SpotlightNode::getLightInnerConeAngle ( ) const

Returns light cutoff angle of the inner cone (hard light edge).

Returns
Angle in degrees in range [0.0; getMaxLightConeAngle].

◆ getLightIntensity()

float ne::SpotlightNode::getLightIntensity ( ) const

Returns intensity of this light source.

Returns
Intensity in range [0.0; 1.0].

◆ getLightOuterConeAngle()

float ne::SpotlightNode::getLightOuterConeAngle ( ) const

Returns light cutoff angle of the outer cone (soft light edge).

Returns
Angle in degrees in range [getLightInnerConeAngle; getMaxLightConeAngle].

◆ getMaxLightConeAngle()

static constexpr float ne::SpotlightNode::getMaxLightConeAngle ( )
inlinestaticconstexpr

Returns the maximum angle for getLightInnerConeAngle and getLightOuterConeAngle.

Returns
Maximum cone angle (in degrees).

◆ getShadowMapHandle()

ShadowMapHandle * ne::SpotlightNode::getShadowMapHandle ( ) const
private

Used by renderer and returns handle to shadow map texture that this light source uses.

Remarks
Do not delete (free) returned pointer.
Returns
nullptr if node is not spawned, otherwise valid pointer.

◆ getShape()

std::pair< std::mutex, Cone > * ne::SpotlightNode::getShape ( )

Returns shape of this light source in world space.

Warning
Only valid while spawned.
Must be used under mutex.
Do not delete (free) returned pointer.
Returns
Shape.

◆ markShaderDataToBeCopiedToGpu()

void ne::SpotlightNode::markShaderDataToBeCopiedToGpu ( )
private

Marks array slot at mtxShaderData as "needs update" (if the slot is created) to later be copied to the GPU resource.

Remarks
Does nothing if the slot is nullptr.

◆ onAfterDeserialized()

void ne::SpotlightNode::onAfterDeserialized ( )
overrideprotectedvirtual

Called after the object was successfully deserialized. Used to execute post-deserialization logic.

Warning
If overriding you must call the parent's version of this function first (before executing your login) to execute parent's logic.

Reimplemented from ne::SpatialNode.

◆ onDespawning()

void ne::SpotlightNode::onDespawning ( )
overrideprotectedvirtual

Called before this node is despawned from the world to execute custom despawn logic.

Remarks
This node will be marked as despawned after this function is called.
This function is called after all child nodes were despawned.
Warning
If overriding you must call the parent's version of this function first (before executing your login) to execute parent's logic.

Reimplemented from ne::Node.

◆ onFinishedUpdatingShaderData()

void ne::SpotlightNode::onFinishedUpdatingShaderData ( )
private

Called after onStartedUpdatingShaderData to notify this node that the renderer has finished copying the data to the GPU resource.

◆ onFinishedUpdatingShadowPassData()

void ne::SpotlightNode::onFinishedUpdatingShadowPassData ( )
private

Called after onStartedUpdatingShadowPassData to notify this node that the renderer has finished copying the data to the GPU resource.

◆ onShadowMapArrayIndexChanged()

void ne::SpotlightNode::onShadowMapArrayIndexChanged ( unsigned int  iNewIndexIntoArray)
private

Called after the index into a descriptor array of pShadowMapHandle was initialized/changed.

Parameters
iNewIndexIntoArrayNew index to use.

◆ onSpawning()

void ne::SpotlightNode::onSpawning ( )
overrideprotectedvirtual

Called when this node was not spawned previously and it was either attached to a parent node that is spawned or set as world's root node to execute custom spawn logic.

Remarks
This node will be marked as spawned before this function is called.
This function is called before any of the child nodes are spawned. If you need to do some logic after child nodes are spawned use onChildNodesSpawned.
Warning
If overriding you must call the parent's version of this function first (before executing your login) to execute parent's logic.

Reimplemented from ne::SpatialNode.

◆ onStartedUpdatingShaderData()

void * ne::SpotlightNode::onStartedUpdatingShaderData ( )
private

Callback that will be called by the renderer when it's ready to copy new (updated) mtxShaderData to the GPU resource.

Returns
Pointer to the shader data at mtxShaderData.

◆ onStartedUpdatingShadowPassData()

void * ne::SpotlightNode::onStartedUpdatingShadowPassData ( )
private

Callback that will be called by the renderer when it's ready to copy new (updated) viewProjectionMatrix of the light source to the GPU resource.

Returns
Pointer to the viewProjectionMatrix at mtxShaderData.

◆ onWorldLocationRotationScaleChanged()

void ne::SpotlightNode::onWorldLocationRotationScaleChanged ( )
overrideprotectedvirtual

Called after node's world location/rotation/scale was changed.

Warning
If overriding you must call the parent's version of this function first (before executing your login) to execute parent's logic.
Remarks
If you change location/rotation/scale inside of this function, this function will not be called again (no recursion will occur).

Reimplemented from ne::SpatialNode.

◆ recalculateAndMarkShaderDataToBeCopiedToGpu()

void ne::SpotlightNode::recalculateAndMarkShaderDataToBeCopiedToGpu ( )
private

Recalculates shader data according to the current spotlight data and calls markShaderDataToBeCopiedToGpu.

Remarks
Does nothing if the slot is nullptr.

◆ recalculateShadowMappingShaderData()

void ne::SpotlightNode::recalculateShadowMappingShaderData ( )
private

(Re)calculates data used for shadow pass and shadow mapping mapping.

Remarks
Does not call markShaderDataToBeCopiedToGpu.

◆ recalculateShape()

void ne::SpotlightNode::recalculateShape ( )
private

Recalculates mtxShaderData according to the current parameters (state).

Remarks
Takes information from mtxShaderData and expects that it's updated.

◆ setLightColor()

void ne::SpotlightNode::setLightColor ( const glm::vec3 &  color)

Sets light's color.

Parameters
colorColor in RGB format in range [0.0; 1.0].

◆ setLightDistance()

void ne::SpotlightNode::setLightDistance ( float  distance)

Sets lit distance (i.e. attenuation distance).

Parameters
distanceLit distance.

◆ setLightInnerConeAngle()

void ne::SpotlightNode::setLightInnerConeAngle ( float  innerConeAngle)

Sets angle of spotlight's inner cone (cone that will have hard light edges), see setLightOuterConeAngle for configuring soft light edges.

Parameters
innerConeAngleAngle in degrees in range [0.0; getMaxLightConeAngle] (will be clamped if outside of the range).

◆ setLightIntensity()

void ne::SpotlightNode::setLightIntensity ( float  intensity)

Sets light's intensity.

Parameters
intensityIntensity in range [0.0; 1.0] (will be clamped if outside of the range).

◆ setLightOuterConeAngle()

void ne::SpotlightNode::setLightOuterConeAngle ( float  outerConeAngle)

Sets angle of spotlight's inner cone (cone that will have hard light edges), see setLightOuterConeAngle for configuring soft light edges.

Parameters
outerConeAngleAngle in degrees in range [getLightInnerConeAngle; getMaxLightConeAngle] (will be clamped if outside of the range).

Member Data Documentation

◆ color

glm::vec3 ne::SpotlightNode::color = glm::vec3(1.0F, 1.0F, 1.0F)
private

Color of the light source.

◆ distance

float ne::SpotlightNode::distance = 15.0F
private

Lit distance.

◆ innerConeAngle

float ne::SpotlightNode::innerConeAngle = 25.0F
private

Light cutoff angle (in degrees) of the inner cone (hard light edge). Valid values range is [0.0F, maxConeAngle].

◆ intensity

float ne::SpotlightNode::intensity = 1.0F
private

Light intensity, valid values range is [0.0F; 1.0F].

◆ maxConeAngle

constexpr float ne::SpotlightNode::maxConeAngle = 80.0F
staticconstexprprivate

Maximum value for innerConeAngle and outerConeAngle.

◆ mtxShaderData

std::pair<std::recursive_mutex, ShaderData> ne::SpotlightNode::mtxShaderData
private

Only valid while spawned. Up to date data that will be copied to the GPU.

◆ mtxShape

std::pair<std::mutex, Cone> ne::SpotlightNode::mtxShape
private

Stores up-to-date cone shape (in world space) that represents the spotlight.

Remarks
Only valid while spawned.

◆ outerConeAngle

float ne::SpotlightNode::outerConeAngle = 45.0F
private

Light cutoff angle (in degrees) of the outer cone (soft light edge). Valid values range is [innerConeAngle, maxConeAngle].

◆ pShadowMapHandle

std::unique_ptr<ShadowMapHandle> ne::SpotlightNode::pShadowMapHandle
private

References shadow map of the light source.

Remarks
Only valid while spawned.

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