NAP
Classes | Public Member Functions | Public Attributes | List of all members
LightComponent Class Reference

#include <lightcomponent.h>

Classes

struct  Locator
 

Public Member Functions

virtual void getDependentComponents (std::vector< rtti::TypeInfo > &components) const override
 
- Public Member Functions inherited from Component
virtual const rtti::TypeInfo getInstanceType () const =0
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual bool init (utility::ErrorState &errorState)
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

bool mEnabled = true
 Property: 'Enabled' Whether the light is enabled. More...
 
bool mCastShadows = false
 Property: 'CastShadows' Enables shadows and creates shadow map resources for this light. More...
 
RGBColorFloat mColor = {1.0f, 1.0f, 1.0f}
 Property: 'Color' The light color. More...
 
float mIntensity = 1.0f
 Property: 'Intensity' The light intensity. More...
 
float mShadowStrength = 1.0f
 Property: 'ShadowStrength' The amount of light the shadow consumes. More...
 
Locator mLocator
 Property: 'Locator' Locator settings. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

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 components 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 LightComponent:
[legend]
Collaboration diagram for LightComponent:
[legend]

Member Function Documentation

◆ getDependentComponents()

virtual void getDependentComponents ( std::vector< rtti::TypeInfo > &  components) const
overridevirtual

Get a list of all component types that this component is dependent on (i.e. must be initialized before this one)

Parameters
componentsthe components this object depends on

Reimplemented from Component.

Member Data Documentation

◆ mCastShadows

bool mCastShadows = false

Property: 'CastShadows' Enables shadows and creates shadow map resources for this light.

◆ mColor

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

Property: 'Color' The light color.

◆ mEnabled

bool mEnabled = true

Property: 'Enabled' Whether the light is enabled.

◆ mIntensity

float mIntensity = 1.0f

Property: 'Intensity' The light intensity.

◆ mLocator

Locator mLocator

Property: 'Locator' Locator settings.

◆ mShadowStrength

float mShadowStrength = 1.0f

Property: 'ShadowStrength' The amount of light the shadow consumes.