Nameless Engine
Loading...
Searching...
No Matches
ne::LightingShaderResourceManager Class Reference

#include <LightingShaderResourceManager.h>

Classes

struct  ComputeShaderData
 
struct  GeneralLightingShaderData
 
struct  GpuData
 
struct  LightArrays
 

Public Member Functions

ShaderLightArraygetPointLightDataArray () const
 
ShaderLightArraygetDirectionalLightDataArray () const
 
ShaderLightArraygetSpotlightDataArray () const
 
ShaderLightArraygetShadowPassLightInfoArray () const
 
std::optional< ErrorbindDescriptorsToRecreatedPipelineResources ()
 
std::optional< ErrorupdateDescriptorsForPipelineResource (Pipeline *pPipeline)
 
std::pair< std::recursive_mutex, GpuData > * getInternalResources ()
 

Static Public Member Functions

static std::string getGeneralLightingDataShaderResourceName ()
 
static std::string getPointLightsShaderResourceName ()
 
static std::string getDirectionalLightsShaderResourceName ()
 
static std::string getSpotlightsShaderResourceName ()
 
static std::string getPointLightsInCameraFrustumIndicesShaderResourceName ()
 
static std::string getSpotlightsInCameraFrustumIndicesShaderResourceName ()
 
static std::string getShadowPassLightInfoArrayShaderResourceName ()
 
static std::string getPointLightWorldLocationsShaderResourceName ()
 

Private Member Functions

 LightingShaderResourceManager (Renderer *pRenderer)
 
std::optional< ErrorrecalculateLightTileFrustums (const std::pair< unsigned int, unsigned int > &renderTargetSize, const glm::mat4 &inverseProjectionMatrix)
 
void onEngineShadersCompiled ()
 
void setAmbientLight (const glm::vec3 &ambientLight)
 
void updateResources (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex)
 
void onPointLightArraySizeChanged (size_t iNewSize)
 
void onPointLightsInFrustumCulled (size_t iCurrentFrameResourceIndex)
 
void onDirectionalLightArraySizeChanged (size_t iNewSize)
 
void onSpotlightArraySizeChanged (size_t iNewSize)
 
void onSpotlightsInFrustumCulled (size_t iCurrentFrameResourceIndex)
 
void copyDataToGpu (size_t iCurrentFrameResourceIndex)
 
std::optional< ErrorrebindGpuDataToAllPipelines ()
 
std::optional< ErrorrebindGpuDataToPipeline (Pipeline *pPipeline)
 

Static Private Member Functions

static std::unique_ptr< LightingShaderResourceManagercreate (Renderer *pRenderer)
 
static std::optional< ErrorrebindBufferResourceToPipeline (VulkanPipeline *pVulkanPipeline, VkDevice pLogicalDevice, const std::string &sShaderResourceName, VkDeviceSize iResourceSize, VkDescriptorType descriptorType, std::array< VkBuffer, FrameResourcesManager::getFrameResourcesCount()> vBuffersToBind)
 
static std::optional< ErrorrebindImageResourceToPipeline (VulkanPipeline *pVulkanPipeline, VkDevice pLogicalDevice, const std::string &sShaderResourceName, VkDescriptorType descriptorType, VkImageLayout imageLayout, VkSampler pSampler, std::array< VkImageView, FrameResourcesManager::getFrameResourcesCount()> vImagesToBind)
 

Private Attributes

LightArrays lightArrays
 
std::pair< std::recursive_mutex, GpuDatamtxGpuData
 
ComputeShaderData::FrustumGridComputeShader::ComputeShader frustumGridComputeShaderData
 
ComputeShaderData::LightCullingComputeShader::ComputeShader lightCullingComputeShaderData
 
std::unique_ptr< ComputeShaderInterfacepPrepareLightCullingComputeInterface
 
RendererpRenderer = nullptr
 
bool bEngineShadersCompiled = false
 

Static Private Attributes

static const std::string sGeneralLightingDataShaderResourceName = "generalLightingData"
 
static const std::string sPointLightsShaderResourceName = "pointLights"
 
static const std::string sDirectionalLightsShaderResourceName = "directionalLights"
 
static const std::string sSpotlightsShaderResourceName = "spotlights"
 
static const std::string sPointLightsInCameraFrustumIndicesShaderResourceName
 
static const std::string sSpotlightsInCameraFrustumIndicesShaderResourceName
 
static const std::string sShadowPassLightInfoShaderResourceName = "shadowPassLightInfo"
 
static constexpr auto generalLightingDataDescriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
 

Friends

class Renderer
 

Detailed Description

Manages GPU resources that store lighting related data (such as data of all spawned light sources (data such as color, intensity, position, etc.)).

Constructor & Destructor Documentation

◆ LightingShaderResourceManager()

ne::LightingShaderResourceManager::LightingShaderResourceManager ( Renderer pRenderer)
private

Initializes a new manager.

Parameters
pRendererUsed renderer.

Member Function Documentation

◆ bindDescriptorsToRecreatedPipelineResources()

std::optional< Error > ne::LightingShaderResourceManager::bindDescriptorsToRecreatedPipelineResources ( )

Updates descriptors in all graphics pipelines to make descriptors reference the underlying buffers.

Remarks
Does nothing if DirectX renderer is used.
Returns
Error if something went wrong.

◆ copyDataToGpu()

void ne::LightingShaderResourceManager::copyDataToGpu ( size_t  iCurrentFrameResourceIndex)
private

Copies data from mtxGpuData to the GPU resource of the current frame resource.

Parameters
iCurrentFrameResourceIndexIndex of the frame resource that will be used to submit the next frame.

◆ create()

std::unique_ptr< LightingShaderResourceManager > ne::LightingShaderResourceManager::create ( Renderer pRenderer)
staticprivate

Creates a new manager.

Parameters
pRendererUsed renderer.
Returns
Created manager.

◆ getDirectionalLightDataArray()

ShaderLightArray * ne::LightingShaderResourceManager::getDirectionalLightDataArray ( ) const

Returns a non-owning reference to an array that stores data of all spawned directional lights.

Warning
Do not delete (free) returned pointer.
Returns
Shader array.

◆ getDirectionalLightsShaderResourceName()

std::string ne::LightingShaderResourceManager::getDirectionalLightsShaderResourceName ( )
static

Return name of the shader resource that stores array of directional lights (name from shader code).

Returns
Name of the shader resource.

◆ getGeneralLightingDataShaderResourceName()

std::string ne::LightingShaderResourceManager::getGeneralLightingDataShaderResourceName ( )
static

Return name of the shader resource that stores general lighting data (name from shader code).

Returns
Name of the shader resource.

◆ getInternalResources()

std::pair< std::recursive_mutex, LightingShaderResourceManager::GpuData > * ne::LightingShaderResourceManager::getInternalResources ( )

Returns manager's internal resources.

Remarks
Generally used for tests (read-only), you should not modify them.
Returns
Internal resources.

◆ getPointLightDataArray()

ShaderLightArray * ne::LightingShaderResourceManager::getPointLightDataArray ( ) const

Returns a non-owning reference to an array that stores data of all spawned point lights.

Warning
Do not delete (free) returned pointer.
Returns
Shader array.

◆ getPointLightsInCameraFrustumIndicesShaderResourceName()

std::string ne::LightingShaderResourceManager::getPointLightsInCameraFrustumIndicesShaderResourceName ( )
static

Return name of the shader resource that stores indices of point lights in camera's frustum (name from shader code).

Returns
Name of the shader resource.

◆ getPointLightsShaderResourceName()

std::string ne::LightingShaderResourceManager::getPointLightsShaderResourceName ( )
static

Return name of the shader resource that stores array of point lights (name from shader code).

Returns
Name of the shader resource.

◆ getPointLightWorldLocationsShaderResourceName()

static std::string ne::LightingShaderResourceManager::getPointLightWorldLocationsShaderResourceName ( )
static

Returns name of the shader resource that stores array of world positions for all point lights (used for shadow mapping).

Returns
Name of the shader resource.

◆ getShadowPassLightInfoArray()

ShaderLightArray * ne::LightingShaderResourceManager::getShadowPassLightInfoArray ( ) const

Returns a non-owning reference to an array that stores info for shadow pass of spawned lights.

Warning
Do not delete (free) returned pointer.
Returns
Shader array.

◆ getShadowPassLightInfoArrayShaderResourceName()

std::string ne::LightingShaderResourceManager::getShadowPassLightInfoArrayShaderResourceName ( )
static

Returns name of the shader resource that stores array of viewProjectionMatrix for all light sources (used for shadow mapping).

Returns
Name of the shader resource.

◆ getSpotlightDataArray()

ShaderLightArray * ne::LightingShaderResourceManager::getSpotlightDataArray ( ) const

Returns a non-owning reference to an array that stores data of all spawned spotlights.

Warning
Do not delete (free) returned pointer.
Returns
Shader array.

◆ getSpotlightsInCameraFrustumIndicesShaderResourceName()

std::string ne::LightingShaderResourceManager::getSpotlightsInCameraFrustumIndicesShaderResourceName ( )
static

Return name of the shader resource that stores indices of spotlights in camera's frustum (name from shader code).

Returns
Name of the shader resource.

◆ getSpotlightsShaderResourceName()

std::string ne::LightingShaderResourceManager::getSpotlightsShaderResourceName ( )
static

Return name of the shader resource that stores array of spotlights (name from shader code).

Returns
Name of the shader resource.

◆ onDirectionalLightArraySizeChanged()

void ne::LightingShaderResourceManager::onDirectionalLightArraySizeChanged ( size_t  iNewSize)
private

Called after array of directional light sources changed its size.

Parameters
iNewSizeNew size of the array that stores GPU data for spawned directional lights.

◆ onEngineShadersCompiled()

void ne::LightingShaderResourceManager::onEngineShadersCompiled ( )
private

Called by renderer to notify that all engine shaders were compiled.

Remarks
Just changes internal boolean and nothing else. Expects you to call recalculateLightTileFrustums afterwards to do some actual calculations.

◆ onPointLightArraySizeChanged()

void ne::LightingShaderResourceManager::onPointLightArraySizeChanged ( size_t  iNewSize)
private

Called after array of point light sources changed its size.

Parameters
iNewSizeNew size of the array that stores GPU data for spawned point lights.

◆ onPointLightsInFrustumCulled()

void ne::LightingShaderResourceManager::onPointLightsInFrustumCulled ( size_t  iCurrentFrameResourceIndex)
private

Called after array of indices to point lights in frustum was changed (indices changed).

Parameters
iCurrentFrameResourceIndexIndex of the frame resource that will be used to submit the next frame.

◆ onSpotlightArraySizeChanged()

void ne::LightingShaderResourceManager::onSpotlightArraySizeChanged ( size_t  iNewSize)
private

Called after array of spotlights changed its size.

Parameters
iNewSizeNew size of the array that stores GPU data for spawned spotlights.

◆ onSpotlightsInFrustumCulled()

void ne::LightingShaderResourceManager::onSpotlightsInFrustumCulled ( size_t  iCurrentFrameResourceIndex)
private

Called after array of indices to spotlights in frustum was changed (indices changed).

Parameters
iCurrentFrameResourceIndexIndex of the frame resource that will be used to submit the next frame.

◆ rebindBufferResourceToPipeline()

std::optional< Error > ne::LightingShaderResourceManager::rebindBufferResourceToPipeline ( VulkanPipeline pVulkanPipeline,
VkDevice  pLogicalDevice,
const std::string &  sShaderResourceName,
VkDeviceSize  iResourceSize,
VkDescriptorType  descriptorType,
std::array< VkBuffer, FrameResourcesManager::getFrameResourcesCount()>  vBuffersToBind 
)
staticprivate

Looks if the pipeline uses the specified shader resource and binds the specified buffers to pipeline's descriptors.

Parameters
pVulkanPipelinePipeline which descriptors to update.
pLogicalDeviceRenderer's logical device.
sShaderResourceNameName of the shader resource to look in the pipeline.
iResourceSizeSize of one (buffer) shader resource.
descriptorTypeType of descriptor to bind.
vBuffersToBindBuffers to bind (one per frame resource).
Returns
Error if something went wrong.

◆ rebindGpuDataToAllPipelines()

std::optional< Error > ne::LightingShaderResourceManager::rebindGpuDataToAllPipelines ( )
private

Updates descriptors in all graphics pipelines to make descriptors reference the underlying buffers from mtxGpuData.

Remarks
Does nothing if DirectX renderer is used.
Returns
Error if something went wrong.

◆ rebindGpuDataToPipeline()

std::optional< Error > ne::LightingShaderResourceManager::rebindGpuDataToPipeline ( Pipeline pPipeline)
private

Updates descriptors in the specified graphics pipeline to make descriptors reference the underlying buffers from mtxGpuData.

Remarks
Does nothing if DirectX renderer is used.
Parameters
pPipelinePipeline to get descriptors from.
Returns
Error if something went wrong.

◆ rebindImageResourceToPipeline()

std::optional< Error > ne::LightingShaderResourceManager::rebindImageResourceToPipeline ( VulkanPipeline pVulkanPipeline,
VkDevice  pLogicalDevice,
const std::string &  sShaderResourceName,
VkDescriptorType  descriptorType,
VkImageLayout  imageLayout,
VkSampler  pSampler,
std::array< VkImageView, FrameResourcesManager::getFrameResourcesCount()>  vImagesToBind 
)
staticprivate

Looks if the pipeline uses the specified shader resource and binds the specified buffers to pipeline's descriptors.

Parameters
pVulkanPipelinePipeline which descriptors to update.
pLogicalDeviceRenderer's logical device.
sShaderResourceNameName of the shader resource to look in the pipeline.
descriptorTypeType of descriptor to bind.
imageLayoutImage layout.
pSamplerImage sampler.
vImagesToBindImages to bind (one per frame resource).
Returns
Error if something went wrong.

◆ recalculateLightTileFrustums()

std::optional< Error > ne::LightingShaderResourceManager::recalculateLightTileFrustums ( const std::pair< unsigned int, unsigned int > &  renderTargetSize,
const glm::mat4 &  inverseProjectionMatrix 
)
private

Called by renderer when render resolution or projection matrix changes to queue a compute shader that will recalculate grid of frustums used during light culling.

Parameters
renderTargetSizeNew render of the underlying render image in pixels.
inverseProjectionMatrixInverse projection matrix of the currently active camera.
Returns
Error if something went wrong.

◆ setAmbientLight()

void ne::LightingShaderResourceManager::setAmbientLight ( const glm::vec3 &  ambientLight)
private

Sets light color intensity of ambient lighting.

Remarks
New lighting settings will be copied to the GPU next time updateResources is called.
Parameters
ambientLightColor in RGB format.

◆ updateDescriptorsForPipelineResource()

std::optional< Error > ne::LightingShaderResourceManager::updateDescriptorsForPipelineResource ( Pipeline pPipeline)

Updates descriptors in the specified graphics pipeline to make descriptors reference the underlying buffers.

Remarks
Does nothing if DirectX renderer is used.
Parameters
pPipelinePipeline to get descriptors from.
Returns
Error if something went wrong.

◆ updateResources()

void ne::LightingShaderResourceManager::updateResources ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex 
)
private

Updates all light source resources marked as "needs update" and copies new (updated) data to the GPU resource of the specified frame resource.

Warning
Expected to be called somewhere inside of the drawNextFrame function so that renderer's depth texture without multisampling pointer will not change.
Remarks
Also copies data from mtxGpuData.
Parameters
pCurrentFrameResourceCurrent frame resource that will be used to submit the next frame.
iCurrentFrameResourceIndexIndex of the frame resource that will be used to submit the next frame.

Member Data Documentation

◆ bEngineShadersCompiled

bool ne::LightingShaderResourceManager::bEngineShadersCompiled = false
private

true if the renderer has finished compiling engine shaders, false otherwise.

◆ frustumGridComputeShaderData

ComputeShaderData::FrustumGridComputeShader::ComputeShader ne::LightingShaderResourceManager::frustumGridComputeShaderData
private

Calculates frustum grid for light culling.

◆ generalLightingDataDescriptorType

constexpr auto ne::LightingShaderResourceManager::generalLightingDataDescriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
staticconstexprprivate

Type of the descriptor used to store data from mtxGpuData.

◆ lightArrays

LightArrays ne::LightingShaderResourceManager::lightArrays
private

Groups GPU resources that store arrays of light sources.

◆ lightCullingComputeShaderData

ComputeShaderData::LightCullingComputeShader::ComputeShader ne::LightingShaderResourceManager::lightCullingComputeShaderData
private

Does light culling.

◆ mtxGpuData

std::pair<std::recursive_mutex, GpuData> ne::LightingShaderResourceManager::mtxGpuData
private

Groups GPU related data.

◆ pPrepareLightCullingComputeInterface

std::unique_ptr<ComputeShaderInterface> ne::LightingShaderResourceManager::pPrepareLightCullingComputeInterface
private

Compute interface that runs before light culling shader to reset global variables.

◆ pRenderer

Renderer* ne::LightingShaderResourceManager::pRenderer = nullptr
private

Used renderer.

◆ sDirectionalLightsShaderResourceName

const std::string ne::LightingShaderResourceManager::sDirectionalLightsShaderResourceName = "directionalLights"
inlinestaticprivate

Name of the resource that stores array of directional lights.

◆ sGeneralLightingDataShaderResourceName

const std::string ne::LightingShaderResourceManager::sGeneralLightingDataShaderResourceName = "generalLightingData"
inlinestaticprivate

Name of the resource that stores data from mtxGpuData (name from shader code).

◆ sPointLightsInCameraFrustumIndicesShaderResourceName

const std::string ne::LightingShaderResourceManager::sPointLightsInCameraFrustumIndicesShaderResourceName
inlinestaticprivate
Initial value:
=
"pointLightsInCameraFrustumIndices"

Name of the resources that stores indices of point lights in camera's frustum.

◆ sPointLightsShaderResourceName

const std::string ne::LightingShaderResourceManager::sPointLightsShaderResourceName = "pointLights"
inlinestaticprivate

Name of the resource that stores array of point lights.

◆ sShadowPassLightInfoShaderResourceName

const std::string ne::LightingShaderResourceManager::sShadowPassLightInfoShaderResourceName = "shadowPassLightInfo"
inlinestaticprivate

Name of the resource that stores array light infos for all spawned lights (used in shadow pass).

◆ sSpotlightsInCameraFrustumIndicesShaderResourceName

const std::string ne::LightingShaderResourceManager::sSpotlightsInCameraFrustumIndicesShaderResourceName
inlinestaticprivate
Initial value:
=
"spotlightsInCameraFrustumIndices"

Name of the resources that stores indices of spotlights in camera's frustum.

◆ sSpotlightsShaderResourceName

const std::string ne::LightingShaderResourceManager::sSpotlightsShaderResourceName = "spotlights"
inlinestaticprivate

Name of the resource that stores array of spotlights.


The documentation for this class was generated from the following files: