NAP
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
RenderAdvancedService Class Reference

#include <renderadvancedservice.h>

Public Member Functions

 RenderAdvancedService (ServiceConfiguration *configuration)
 
bool isShadowMappingEnabled () const
 
const std::vector< LightComponentInstance * > & getLights ()
 
void renderShadows (const std::vector< RenderableComponentInstance * > &renderComps, bool updateMaterials=true, RenderMask renderMask=0)
 
void renderLocators (IRenderTarget &renderTarget, CameraComponentInstance &camera, bool drawFrustrum)
 
void pushLights (const std::vector< RenderableComponentInstance * > &renderComps)
 
- Public Member Functions inherited from Service
UNPREFIXED_MODULE_NAME_INPUTCASE Service (ServiceConfiguration *configuration)
 
virtual void update (double deltaTime) override
 
 Service (ServiceConfiguration *configuration)
 
virtual ~Service ()
 
CoregetCore ()
 
const CoregetCore () const
 
std::string getTypeName () const
 
const ModulegetModule () const
 
 Service (Service &)=delete
 
Serviceoperator= (const Service &)=delete
 
 Service (Service &&)=delete
 
Serviceoperator= (Service &&)=delete
 

Static Public Member Functions

static uint getMaximumLightCount ()
 

Protected Member Functions

virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override
 
virtual bool init (nap::utility::ErrorState &errorState) override
 
virtual void preShutdown () override
 
virtual void shutdown () override
 
virtual void preResourcesLoaded () override
 
virtual void postResourcesLoaded () override
 
SpawnedEntityInstance spawn (const nap::Entity &entity, nap::utility::ErrorState &error)
 
void destroy (SpawnedEntityInstance &entityInstance)
 
virtual void postUpdate (double deltaTime)
 
- Protected Member Functions inherited from Service
virtual void registerObjectCreators (rtti::Factory &factory)
 
virtual void created ()
 
virtual void preUpdate (double deltaTime)
 
virtual void update (double deltaTime)
 
template<typename SERVICE_CONFIG >
SERVICE_CONFIG * getConfiguration ()
 
template<typename SERVICE_CONFIG >
const SERVICE_CONFIG * getConfiguration () const
 
std::string getIniFilePath () const
 
std::string getIniFilePath (const std::string &appendix) const
 

Description

Supplementary interface for a Vulkan Render (2D/3D) and Vulkan Compute operations. This service keeps track of light components, shadow rendering and cube maps. Resources that are required to prepare these objects (e.g. render targets, textures, materials etc.) are created after resource initialization and managed at runtime.

The RenderAdvanced service adds a light system to the render engine which can be used to create great-looking and consistent lighting setups fast. On initialization, each light component sets up its own light uniform data and registers itself at the RenderAdvanced service. In order for shaders to be compatible with the light system they must include an uniform struct with the name light, and additionally shadow when shadows are supported. Additional data related to the material surface is excluded from the system and must be set by the user. In the case of the nap::BlinnPhongShader these include ambient, diffuse and specular because they relate to material properties rather than light properties. The maximum number of lights per scene is always limited to getMaximumLightCount, superfluous lights are ignored. Rendering with lights requires an additional call to pushLights with the render components whose material instances you wish to update light uniforms of. Alternatively, renderShadows with the updateMaterials argument set to true updates light uniforms and renders a shadow map. Light components are deregistered and registered again when appropriate on hot-reloads.

nap::CubeMapFromFile objects are gathered after initialization to setup up a render command that generates cube maps from the supplemented equirectangular image files.

// Handles render commands in the headless render command queue,
// including operations to pre-render `nap::CubeMapFromFile`
if (mRenderService->beginHeadlessRecording())
{
mRenderAdvancedService->renderShadows(render_comps, true, shadow_mask);
mRenderService->endHeadlessRecording();
}

The depth format of quad and cube shadow maps can be changed in the nap::RenderAdvancedServiceConfiguration as well as whether shadow mapping is enabled at all.

The RenderAdvanced service also adds a number of useful shader include files .glslinc which can be found in the module's data directory. To include a shader file simply add the following #extension line to your shader file.

#extension GL_GOOGLE_include_directive : enable
#include "utils.glslinc"
Inheritance diagram for RenderAdvancedService:
[legend]
Collaboration diagram for RenderAdvancedService:
[legend]

Constructor & Destructor Documentation

◆ RenderAdvancedService()

Member Function Documentation

◆ destroy()

void destroy ( SpawnedEntityInstance entityInstance)
protected

Destroys an entity hierarchy at runtime. The entity to destroy must have been created using the spawn method above

Parameters
entityInstancethe spawned entity instance

◆ getDependentServices()

virtual void getDependentServices ( std::vector< rtti::TypeInfo > &  dependencies)
overrideprotectedvirtual

Registers service dependencies A service that depends on another service is initialized after all it's associated dependencies This will ensure correct order of initialization, update calls and shutdown of all services

Parameters
dependenciesrtti information of the services this service depends on

Reimplemented from Service.

◆ getLights()

const std::vector<LightComponentInstance*>& getLights ( )

Returns total number of registered lights

Returns
total number of registered light components.

◆ getMaximumLightCount()

static uint getMaximumLightCount ( )
static
Returns
the maximum number of lights supported by the RenderAdvanced light system.

◆ init()

virtual bool init ( nap::utility::ErrorState errorState)
overrideprotectedvirtual

Initializes the service

Parameters
errorStatecontains the error message on failure
Returns
if the video service was initialized correctly

Reimplemented from Service.

◆ isShadowMappingEnabled()

bool isShadowMappingEnabled ( ) const

Returns if global shadow mapping is enabled

Returns
whether global shadow mapping is enabled.

◆ postResourcesLoaded()

virtual void postResourcesLoaded ( )
overrideprotectedvirtual

Invoked after the resource manager successfully loaded resources.

Reimplemented from Service.

◆ postUpdate()

virtual void postUpdate ( double  deltaTime)
protectedvirtual

Invoked by core in the app loop. Update order depends on service dependency This call is invoked after the application update call

Parameters
deltaTimethe time in seconds between calls

Reimplemented from Service.

◆ preResourcesLoaded()

virtual void preResourcesLoaded ( )
overrideprotectedvirtual

Invoked when the resource manager is about to load resources. This is when essential RenderAdvanced resources are created as resources can now be accessed in the scene and light components have been registered.

Reimplemented from Service.

◆ preShutdown()

virtual void preShutdown ( )
overrideprotectedvirtual

Invoked when exiting the main loop, after app shutdown is called Use this function if your service needs to reset its state before resources are destroyed When service B depends on A, Service B is shutdown before A

Reimplemented from Service.

◆ pushLights()

void pushLights ( const std::vector< RenderableComponentInstance * > &  renderComps)

Push light data In order for shaders to be compatible with the light system they must include an uniform struct with the name light, and additionally shadow when shadows are supported. Additional data related to the material surface is excluded from the system and must be set by the user.

if (mRenderService->beginHeadlessRecording())
{
mRenderAdvancedService->pushLights(render_comps, error_state);
mRenderService->endHeadlessRecording();
}
Parameters
renderCompsthe render components whose uniforms and samplers must be updated

◆ renderLocators()

void renderLocators ( IRenderTarget renderTarget,
CameraComponentInstance camera,
bool  drawFrustrum 
)

Renders the origin gnomon including optional frustrum of all enabled lights to the requested render target. The objects to render are sorted using the default sort function (front-to-back). The sort function is provided by the render service itself, using the default NAP DepthSorter.

◆ renderShadows()

void renderShadows ( const std::vector< RenderableComponentInstance * > &  renderComps,
bool  updateMaterials = true,
RenderMask  renderMask = 0 
)

Renders shadow maps using the specified render components for all registered lights. Must be recorded to a headless command buffer. The shadow maps that are updated are managed by the RenderAdvanced service. This call also updates the appropriate uniforms and samplers in the material instances of the render components passed into renderComps.

if (mRenderService->beginHeadlessRecording())
{
mRenderAdvancedService->renderShadows(render_comps, true, shadow_mask);
mRenderService->endHeadlessRecording();
}
Parameters
renderCompsthe render components to include in the shadow map, and whose uniforms and samplers must be updated
updateMaterialswhether to update uniform and sampler data with a call to pushLights
renderMaskrender mask specifying what components to include in the shadow map

◆ shutdown()

virtual void shutdown ( )
overrideprotectedvirtual

Invoked when exiting the main loop, after app shutdown is called Use this function to close service specific handles, drivers or devices When service B depends on A, Service B is shutdown before A

Reimplemented from Service.

◆ spawn()

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

Spawns an entity camera hierarchy at runtime. This entity is spawned into a dedicated light scene, independent from the regular user scene.

Parameters
entitythe entity resource to spawning fails
Returns
the spawned light entity instance, nullptr when invalid
Parameters
errorcontains the error if spawning fails.
nap::RenderService::beginHeadlessRecording
bool beginHeadlessRecording()
nap::RenderService::endHeadlessRecording
void endHeadlessRecording()