#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) |
![]() | |
UNPREFIXED_MODULE_NAME_INPUTCASE | Service (ServiceConfiguration *configuration) |
virtual void | update (double deltaTime) override |
Service (ServiceConfiguration *configuration) | |
virtual | ~Service () |
Core & | getCore () |
const Core & | getCore () const |
std::string | getTypeName () const |
const Module & | getModule () const |
Service (Service &)=delete | |
Service & | operator= (const Service &)=delete |
Service (Service &&)=delete | |
Service & | operator= (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) |
![]() | |
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 |
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.
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.
RenderAdvancedService | ( | ServiceConfiguration * | configuration | ) |
|
protected |
Destroys an entity hierarchy at runtime. The entity to destroy must have been created using the spawn method above
entityInstance | the spawned entity instance |
|
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
dependencies | rtti information of the services this service depends on |
Reimplemented from Service.
const std::vector<LightComponentInstance*>& getLights | ( | ) |
Returns total number of registered lights
|
static |
|
overrideprotectedvirtual |
Initializes the service
errorState | contains the error message on failure |
Reimplemented from Service.
bool isShadowMappingEnabled | ( | ) | const |
Returns if global shadow mapping is enabled
|
overrideprotectedvirtual |
Invoked after the resource manager successfully loaded resources.
Reimplemented from Service.
|
protectedvirtual |
Invoked by core in the app loop. Update order depends on service dependency This call is invoked after the application update call
deltaTime | the time in seconds between calls |
Reimplemented from Service.
|
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.
|
overrideprotectedvirtual |
void pushLights | ( | const std::vector< RenderableComponentInstance * > & | renderComps | ) |
Push light data to the shader programs of the given render components. This function must be called exactly once before rendering when shadows are not used, ie: 'renderShadows' is not invoked.
This call searches for a method called 'getOrCreateMaterial' to locate and extract the program from the component. If the shader program cannot be found, no action is taken, as the method is not exposed via RTTI. Refer to 'RenderableMeshComponentInstance::getOrCreateMaterial' for an example.
Additional data related to the material surface is excluded from the system and must be set by the user.
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.
renderComps | the render components whose uniforms and samplers must be updated |
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.
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
.
renderComps | the render components to include in the shadow map, and whose uniforms and samplers must be updated |
updateMaterials | whether to update uniform and sampler data with a call to pushLights |
renderMask | render mask specifying what components to include in the shadow map |
|
overrideprotectedvirtual |
|
protected |
Spawns an entity camera hierarchy at runtime. This entity is spawned into a dedicated light scene, independent from the regular user scene.
entity | the entity resource to spawning fails |
error | contains the error if spawning fails. |