NAP
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
LightComponentInstance Class Referenceabstract

#include <lightcomponent.h>

Public Member Functions

 LightComponentInstance (EntityInstance &entity, Component &resource)
 
virtual ~LightComponentInstance ()
 
virtual bool init (utility::ErrorState &errorState) override
 
virtual void onDestroy () override
 
virtual void enable (bool enable)
 
bool isEnabled () const
 
bool canCastShadows () const
 
bool castsShadows () const
 
virtual ELightType getLightType () const =0
 
virtual EShadowMapType getShadowMapType () const =0
 
virtual uint getShadowMapSize () const
 
virtual float getIntensity () const
 
void setIntensity (float intensity)
 
virtual float getShadowStrength () const
 
virtual void setShadowStrength (float strength)
 
virtual const RGBColorFloatgetColor () const
 
void setColor (const RGBColorFloat &color)
 
const glm::vec3 getLightPosition () const
 
const glm::vec3 getLightDirection () const
 
const TransformComponentInstancegetTransform () const
 
TransformComponentInstancegetTransform ()
 
bool hasCamera () const
 
CameraComponentInstancegetCamera () const
 
CameraComponentInstancegetCamera ()
 
const RenderGnomonComponentInstancegetGnomon () const
 
RenderGnomonComponentInstancegetGnomon ()
 
const RenderFrustumComponentInstancegetFrustrum () const
 
RenderFrustumComponentInstancegetFrustrum ()
 
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
 
virtual void update (double deltaTime)
 
nap::EntityInstancegetEntityInstance () const
 
nap::ComponentgetComponent () const
 
template<typename T >
T * getComponent () const
 
virtual bool init (utility::ErrorState &errorState)
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

float mIntensity = 1.0f
 
RGBColorFloat mColor = { 1.0f, 1.0f, 1.0f }
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Protected Member Functions

void registerUniformLightProperty (const std::string &memberName)
 
SpawnedEntityInstance spawnShadowCamera (const nap::Entity &entity, nap::utility::ErrorState &error)
 

Protected Attributes

LightComponentmResource = nullptr
 
TransformComponentInstancemTransform = nullptr
 
RenderAdvancedServicemService = nullptr
 
SpawnedEntityInstance mSpawnedCamera
 
bool mIsEnabled = true
 
bool mIsShadowEnabled = false
 
float mShadowStrength = 1.0f
 
uint mShadowMapSize = 512
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

Base class of light component instances for NAP RenderAdvanced's light system.

When present in the scene, the render advanced service can update light uniform data for material instances that are compatible with the light's shader interface. On initialization, each light component sets up its own registry of light uniform data and registers itself at the render advanced service. This way, the service is aware of the lights in the scene and creates the necessary resources for light information and shadow maps. NAP supports a limited number of lights per scene (RenderAdvancedService::getMaximumLightCount). The way in which these blend/interact depends on the implementation of the shader program. Increasing the maximum number of lights is trivial, however, with the current implementation it would take up more shader resource slots.

Each light component has three default uniforms that are set by the RenderAdvanced service:

Other uniforms may be defined by derived light types. They must be in accordance with the data and shader interface in the light.glslinc file in the RenderAdvanced shader folder. New light types can be added here in the future, or user implementations can use the 'Custom' enum.

NAP comes with a default nap::BlinnPhongShader that is compatible with the light system. Hooking this up to a nap::Material allows for quick scene lighting setups. Material surface uniforms as defined by the shader interface must be set in data or at runtime. A description of these can be found in the documentation of the shader or its source file.

The depth format of shadow maps can be configured in the nap::RenderAdvancedServiceConfiguration.

Rendering with lights requires an additional call to the render advanced service. You can either use pushLights on the render components you wish to render or renderShadows with the updateMaterials argument set to true if you wish to use shadows too.

Update light uniforms of lit components when shadows are disabled.

mRenderAdvancedService->pushLights(components_to_render, error_state);
// mRenderService->renderObjects ...

Re-render shadow map and update light uniforms.

if (mRenderService->beginHeadlessRecording())
{
mRenderAdvancedService->renderShadows(render_comps, true);
mRenderService->endHeadlessRecording();
}
Inheritance diagram for LightComponentInstance:
[legend]
Collaboration diagram for LightComponentInstance:
[legend]

Constructor & Destructor Documentation

◆ LightComponentInstance()

LightComponentInstance ( EntityInstance entity,
Component resource 
)

◆ ~LightComponentInstance()

virtual ~LightComponentInstance ( )
virtual

Derived lights destructors must remove themselves by calling LightComponentInstance::removeLightComponent();

Member Function Documentation

◆ canCastShadows()

bool canCastShadows ( ) const

Returns whether this light component can cast shadows. Override if your light doesn't support shadows.

Returns
whether this light component can cast shadows

◆ castsShadows()

bool castsShadows ( ) const
Returns
whether this light component currently casts shadows

◆ enable()

virtual void enable ( bool  enable)
virtual

Activates the light

Parameters
enableif the light is activate or not

◆ getCamera() [1/2]

CameraComponentInstance& getCamera ( )
Returns
the shadow camera.

◆ getCamera() [2/2]

CameraComponentInstance& getCamera ( ) const
Returns
the shadow camera.

◆ getColor()

virtual const RGBColorFloat& getColor ( ) const
virtual
Returns
the light color

◆ getFrustrum() [1/2]

Returns
the shadow camera frustrum.

◆ getFrustrum() [2/2]

const RenderFrustumComponentInstance* getFrustrum ( ) const
Returns
the shadow camera frustrum.

◆ getGnomon() [1/2]

Returns
the origin gnomon.

◆ getGnomon() [2/2]

const RenderGnomonComponentInstance& getGnomon ( ) const
Returns
the origin gnomon.

◆ getIntensity()

virtual float getIntensity ( ) const
virtual
Returns
the light intensity

◆ getLightDirection()

const glm::vec3 getLightDirection ( ) const
Returns
the direction of the light in world space

◆ getLightPosition()

const glm::vec3 getLightPosition ( ) const
Returns
the position of the light in world space

◆ getLightType()

virtual ELightType getLightType ( ) const
pure virtual

◆ getShadowMapSize()

virtual uint getShadowMapSize ( ) const
virtual
Returns
the shadow map resolution

◆ getShadowMapType()

virtual EShadowMapType getShadowMapType ( ) const
pure virtual

◆ getShadowStrength()

virtual float getShadowStrength ( ) const
virtual
Returns
the shadow strength

◆ getTransform() [1/2]

TransformComponentInstance& getTransform ( )
Returns
the light transform

◆ getTransform() [2/2]

const TransformComponentInstance& getTransform ( ) const
Returns
the light transform

◆ hasCamera()

bool hasCamera ( ) const
Returns
if this light has a shadow camera

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initialize LightComponentInstance based on the LightComponent resource

Parameters
errorStateshould hold the error message when initialization fails
Returns
if the LightComponentInstance is initialized successfully

Reimplemented from ComponentInstance.

Reimplemented in SpotLightComponentInstance, PointLightComponentInstance, and DirectionalLightComponentInstance.

◆ isEnabled()

bool isEnabled ( ) const
Returns
whether this light is active

◆ onDestroy()

virtual void onDestroy ( )
overridevirtual

Unregisters itself from the advanced render service

Reimplemented from Object.

◆ registerUniformLightProperty()

void registerUniformLightProperty ( const std::string &  memberName)
protected

Registers a light property as a uniform light member, which is automatically pushed by the render advanced service. Note that the property must be must be defined for this or derived classes using the RTTI_PROPERTY macro.

Parameters
memberNamelight property member name, must be registered using the RTTI_PROPERTY macro.

◆ setColor()

void setColor ( const RGBColorFloat color)

Set the light color

◆ setIntensity()

void setIntensity ( float  intensity)

Set the light intensity

◆ setShadowStrength()

virtual void setShadowStrength ( float  strength)
virtual

Sets the shadow strength

◆ spawnShadowCamera()

SpawnedEntityInstance spawnShadowCamera ( const nap::Entity entity,
nap::utility::ErrorState error 
)
protected

Spawns a light camera entity. The lifetime of that entity is managed by this component. The light camera entity is used to calculate the shadow maps This entity is spawned into a dedicated light scene, independent from the regular user scene. Call this function on init of your derived light component, only once!

Parameters
entitythe entity resource to spawn
errorcontains the error if spawning fails
Returns
the spawned light entity instance.

Member Data Documentation

◆ mColor

RGBColorFloat mColor = { 1.0f, 1.0f, 1.0f }

◆ mIntensity

float mIntensity = 1.0f

◆ mIsEnabled

bool mIsEnabled = true
protected

◆ mIsShadowEnabled

bool mIsShadowEnabled = false
protected

◆ mResource

LightComponent* mResource = nullptr
protected

◆ mService

RenderAdvancedService* mService = nullptr
protected

◆ mShadowMapSize

uint mShadowMapSize = 512
protected

◆ mShadowStrength

float mShadowStrength = 1.0f
protected

◆ mSpawnedCamera

SpawnedEntityInstance mSpawnedCamera
protected

◆ mTransform

TransformComponentInstance* mTransform = nullptr
protected