#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 float | getShadowSpread () const |
virtual void | setShadowSpread (float spread) |
virtual const RGBColorFloat & | getColor () const |
void | setColor (const RGBColorFloat &color) |
const glm::vec3 | getLightPosition () const |
const glm::vec3 | getLightDirection () const |
const TransformComponentInstance & | getTransform () const |
TransformComponentInstance & | getTransform () |
bool | hasCamera () const |
CameraComponentInstance & | getCamera () const |
CameraComponentInstance & | getCamera () |
const RenderGnomonComponentInstance & | getGnomon () const |
RenderGnomonComponentInstance & | getGnomon () |
const RenderFrustumComponentInstance * | getFrustrum () const |
RenderFrustumComponentInstance * | getFrustrum () |
![]() | |
ComponentInstance (EntityInstance &entity, Component &resource) | |
virtual void | update (double deltaTime) |
nap::EntityInstance * | getEntityInstance () const |
nap::Component * | getComponent () const |
template<typename T > | |
T * | getComponent () const |
virtual bool | init (utility::ErrorState &errorState) |
![]() | |
Object () | |
virtual | ~Object () |
Object (Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&)=delete | |
Object & | operator= (Object &&)=delete |
Public Attributes | |
float | mIntensity = 1.0f |
RGBColorFloat | mColor = { 1.0f, 1.0f, 1.0f } |
![]() | |
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 | |
LightComponent * | mResource = nullptr |
TransformComponentInstance * | mTransform = nullptr |
RenderAdvancedService * | mService = nullptr |
SpawnedEntityInstance | mSpawnedCamera |
bool | mIsEnabled = true |
bool | mIsShadowEnabled = false |
float | mShadowStrength = 1.0f |
float | mShadowSpread = 2.0f |
uint | mShadowMapSize = 512 |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
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:
origin
: vec3
world position of the light.direction
: vec3
direction of the light. Some lights may choose to ignore this however (e.g. point lights).flags
: an unsigned integer encoding information such as whether shadows are enabled, see lightflags.h
.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.
Re-render shadow map and update light uniforms.
LightComponentInstance | ( | EntityInstance & | entity, |
Component & | resource | ||
) |
|
virtual |
Derived lights destructors must remove themselves by calling LightComponentInstance::removeLightComponent();
bool canCastShadows | ( | ) | const |
Returns whether this light component can cast shadows. Override if your light doesn't support shadows.
bool castsShadows | ( | ) | const |
|
virtual |
Activates the light
enable | if the light is activate or not |
CameraComponentInstance& getCamera | ( | ) |
CameraComponentInstance& getCamera | ( | ) | const |
|
virtual |
RenderFrustumComponentInstance* getFrustrum | ( | ) |
const RenderFrustumComponentInstance* getFrustrum | ( | ) | const |
RenderGnomonComponentInstance& getGnomon | ( | ) |
const RenderGnomonComponentInstance& getGnomon | ( | ) | const |
|
virtual |
const glm::vec3 getLightDirection | ( | ) | const |
const glm::vec3 getLightPosition | ( | ) | const |
|
pure virtual |
Implemented in SpotLightComponentInstance, PointLightComponentInstance, and DirectionalLightComponentInstance.
|
virtual |
|
pure virtual |
Implemented in SpotLightComponentInstance, PointLightComponentInstance, and DirectionalLightComponentInstance.
|
virtual |
|
virtual |
TransformComponentInstance& getTransform | ( | ) |
const TransformComponentInstance& getTransform | ( | ) | const |
bool hasCamera | ( | ) | const |
|
overridevirtual |
Initialize LightComponentInstance based on the LightComponent resource
errorState | should hold the error message when initialization fails |
Reimplemented from ComponentInstance.
Reimplemented in SpotLightComponentInstance, PointLightComponentInstance, and DirectionalLightComponentInstance.
bool isEnabled | ( | ) | const |
|
overridevirtual |
Unregisters itself from the advanced render service
Reimplemented from Object.
|
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.
memberName | light property member name, must be registered using the RTTI_PROPERTY macro. |
void setColor | ( | const RGBColorFloat & | color | ) |
Set the light color
void setIntensity | ( | float | intensity | ) |
Set the light intensity
|
virtual |
Sets the shadow strength
|
virtual |
Sets the shadow strength
|
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!
entity | the entity resource to spawn |
error | contains the error if spawning fails |
RGBColorFloat mColor = { 1.0f, 1.0f, 1.0f } |
float mIntensity = 1.0f |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |