Skip to content

Commit

Permalink
IndirectLighting: Implemented Reflective Shadow Maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonJoker committed May 2, 2024
1 parent 072e604 commit 859cb82
Show file tree
Hide file tree
Showing 42 changed files with 2,585 additions and 80 deletions.
2 changes: 1 addition & 1 deletion doc/Castor3D/Castor3D Scene.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace castor3d
: uint32_t
{
eNone = 0,
// Reflective shadow maps.
eRsm = 1,
// Voxel Cone Tracing.
eVoxelConeTracing = 2,
eVoxelConeTracing = 1,
// Reflective shadow maps.
eRsm = 2,
// Light Propagation Volumes without geometry injection.
eLpv = 3,
// Light Propagation Volumes with geometry injection.
Expand Down Expand Up @@ -86,6 +86,7 @@ namespace castor3d
LpvGridConfigUbo const * lpvConfigUbo{};
LayeredLpvGridConfigUbo const * llpvConfigUbo{};
VoxelizerUbo const * vctConfigUbo{};
Texture const * rsmResult{};
LightVolumePassResult const * lpvResult{};
LightVolumePassResultArray const * llpvResult{};
Texture const * vctFirstBounce{};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
See LICENSE file in root folder
*/
#ifndef ___C3D_ReflectiveShadowMapping_HPP___
#define ___C3D_ReflectiveShadowMapping_HPP___

#include "ReflectiveShadowMapsModule.hpp"
#include "Castor3D/Shader/Ubos/UbosModule.hpp"

#include "Castor3D/Shader/Shaders/GlslLight.hpp"

#include <ShaderWriter/CompositeTypes/ArrayStorageBuffer.hpp>

namespace castor3d
{
class ReflectiveShadowMapping
{
public:
C3D_API ReflectiveShadowMapping( sdw::ShaderWriter & writer
, sdw::ArrayStorageBufferT< sdw::Vec4 > & rsmSamples );
C3D_API sdw::Vec3 directional( shader::DirectionalShadowData const & shadowData
, sdw::Vec3 const & viewPosition
, sdw::Vec3 const & worldPosition
, sdw::Vec3 const & worldNormal
, shader::RsmConfigData const & rsmData );
C3D_API sdw::Vec3 point( shader::PointShadowData const & shadowData
, sdw::Vec3 const & lightPosition
, sdw::Vec3 const & worldPosition
, sdw::Vec3 const & worldNormal
, shader::RsmConfigData const & rsmData );
C3D_API sdw::Vec3 spot( shader::SpotShadowData const & shadowData
, sdw::Vec3 const & worldPosition
, sdw::Vec3 const & worldNormal
, shader::RsmConfigData const & rsmData );

private:
sdw::ShaderWriter & m_writer;
sdw::ArrayStorageBufferT< sdw::Vec4 > & m_rsmSamples;
sdw::Function< sdw::Vec3
, shader::InDirectionalShadowData
, sdw::InVec3
, sdw::InVec3
, sdw::InVec3
, shader::InRsmConfigData > m_directional;
sdw::Function< sdw::Vec3
, shader::InPointShadowData
, sdw::InVec3
, sdw::InVec3
, sdw::InVec3
, shader::InRsmConfigData > m_point;
sdw::Function< sdw::Vec3
, shader::InSpotShadowData
, sdw::InVec3
, sdw::InVec3
, shader::InRsmConfigData > m_spot;
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
See LICENSE file in root folder
*/
#ifndef ___C3D_ReflectiveShadowMaps_H___
#define ___C3D_ReflectiveShadowMaps_H___

#include "ReflectiveShadowMapsModule.hpp"

#include "Castor3D/Cache/CacheModule.hpp"
#include "Castor3D/Miscellaneous/MiscellaneousModule.hpp"
#include "Castor3D/Render/ShadowMap/ShadowMapModule.hpp"

#include <CastorUtils/Design/Named.hpp>

#include <RenderGraph/FrameGraph.hpp>
#include <RenderGraph/RunnableGraph.hpp>

namespace castor3d
{
class ReflectiveShadowMaps
: public castor::Named
{
public:
C3D_API ReflectiveShadowMaps( crg::ResourceHandler & handler
, Scene const & scene
, RenderDevice const & device
, CameraUbo const & cameraUbo
, ShadowBuffer const & shadowBuffer
, crg::ImageViewId const & depthObj
, crg::ImageViewId const & nmlOcc
, ShadowMapResult const & directionalSmResult
, ShadowMapResult const & pointSmResult
, ShadowMapResult const & spotSmResult
, Texture const & result );
C3D_API ~ReflectiveShadowMaps()noexcept;

public:
C3D_API void initialise();
C3D_API void cleanup();
C3D_API void registerLight( Light * light );
C3D_API void update( CpuUpdater & updater );
C3D_API crg::SemaphoreWaitArray render( crg::SemaphoreWaitArray const & toWait
, ashes::Queue const & queue );
C3D_API void accept( ConfigurationVisitorBase & visitor );

private:
crg::FramePass & doCreateClearPass();

private:
Scene const & m_scene;
RenderDevice const & m_device;
CameraUbo const & m_cameraUbo;
ShadowBuffer const & m_shadowBuffer;
crg::ImageViewId const & m_depthObj;
crg::ImageViewId const & m_nmlOcc;
ShadowMapResult const & m_directionalSmResult;
ShadowMapResult const & m_pointSmResult;
ShadowMapResult const & m_spotSmResult;
crg::FrameGraph m_graph;
bool m_initialised{ false };
TextureArray m_intermediate;
Texture const & m_result;
struct LightRsm
{
LightRsm( crg::FrameGraph & graph
, crg::FramePassArray previousPasses
, RenderDevice const & device
, LightCache const & lightCache
, LightType lightType
, ShadowBuffer const & shadowBuffer
, CameraUbo const & cameraUbo
, crg::ImageViewId const & depthObj
, crg::ImageViewId const & nmlOcc
, ShadowMapResult const & smResult
, TextureArray const & intermediate
, Texture const & result );
void update( CpuUpdater & updater );

LightCache const & lightCache;
RsmGIPassUPtr giPass;
RsmInterpolatePassUPtr interpolatePass;
crg::FramePass const * lastPass{};
};
using LightRsmPtr = std::unique_ptr< LightRsm >;

crg::FramePass const & m_clearPass;
crg::FramePass const * m_lastPass;
std::unordered_map< Light *, LightRsmPtr > m_lightRsms;
crg::RunnableGraphPtr m_runnable;
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
See LICENSE file in root folder
*/
#ifndef ___C3D_ReflectiveShadowMapsModule_H___
#define ___C3D_ReflectiveShadowMapsModule_H___

#include "Castor3D/Cache/CacheModule.hpp"
#include "Castor3D/Render/Opaque/OpaqueModule.hpp"
#include "Castor3D/Render/ShadowMap/ShadowMapModule.hpp"
#include "Castor3D/Scene/Light/LightModule.hpp"

namespace castor3d
{
/**@name Render */
//@{
/**@name Global Illumination */
//@{
/**@name Reflective Shadow Maps */
//@{

/**
*\~english
*\brief
* Reflective Shadow Map shader helpers.
*\~french
*\brief
* classe d'aide pour les shaders de Reflective Shadow Map.
*/
class ReflectiveShadowMapping;
/**
*\~english
*\brief
* Reflective Shadow Maps configuration values.
*\~french
*\brief
* Valeurs de configuration des Reflective Shadow Maps.
*/
struct RsmConfig;
/**
*\~english
*\brief
* SSGI pass based on Reflective Shadow Maps.
*\~french
*\brief
* Passe de SSGI basée sur les Reflective Shadow Maps.
*/
class RsmGIPass;
/**
*\~english
*\brief
* RSM GI interpolation pass, used to optimise the algorithm.
*\~french
*\brief
* Passe d'interpolation du RSM GI, pour optimiser l'algorithme.
*/
class RsmInterpolatePass;
/**
*\~english
*\brief
* RSM full pass.
*\~french
*\brief
* Passe de RSM.
*/
class ReflectiveShadowMaps;

CU_DeclareSmartPtr( castor3d, RsmGIPass, C3D_API );
CU_DeclareSmartPtr( castor3d, RsmInterpolatePass, C3D_API );
CU_DeclareSmartPtr( castor3d, ReflectiveShadowMaps, C3D_API );

//@}
//@}
//@}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
See LICENSE file in root folder
*/
#ifndef ___C3D_RsmConfig_H___
#define ___C3D_RsmConfig_H___

#include "ReflectiveShadowMapsModule.hpp"

#include "Castor3D/Limits.hpp"

#include "Castor3D/Miscellaneous/MiscellaneousModule.hpp"

#include <CastorUtils/Data/TextWriter.hpp>
#include <CastorUtils/Design/ChangeTracked.hpp>
#include <CastorUtils/Math/RangedValue.hpp>

namespace castor3d
{
struct RsmConfig
{
C3D_API void accept( ConfigurationVisitorBase & visitor );
C3D_API static void addParsers( castor::AttributeParsers & result );

castor::ChangeTracked< float > intensity;
castor::ChangeTracked< float > maxRadius;
castor::ChangeTracked< castor::RangedValue< uint32_t > > sampleCount{ castor::makeRangedValue( 100u, 20u, MaxRsmRange ) };
};

inline bool operator==( RsmConfig const & lhs, RsmConfig const & rhs )noexcept
{
return lhs.intensity == rhs.intensity
&& lhs.maxRadius == rhs.maxRadius
&& lhs.sampleCount == rhs.sampleCount;
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
See LICENSE file in root folder
*/
#ifndef ___C3D_RsmGIPass_HPP___
#define ___C3D_RsmGIPass_HPP___

#include "ReflectiveShadowMapsModule.hpp"
#include "Castor3D/Cache/CacheModule.hpp"

#include "Castor3D/Buffer/GpuBufferOffset.hpp"
#include "Castor3D/Material/Texture/TextureUnit.hpp"
#include "Castor3D/Miscellaneous/MiscellaneousModule.hpp"
#include "Castor3D/Render/ShadowMap/ShadowMapModule.hpp"
#include "Castor3D/Render/Opaque/OpaqueModule.hpp"
#include "Castor3D/Render/Passes/RenderQuad.hpp"
#include "Castor3D/Scene/Light/LightModule.hpp"
#include "Castor3D/Shader/Ubos/RsmConfigUbo.hpp"

#include <ShaderAST/Shader.hpp>

namespace castor3d
{
class RsmGIPass
: public castor::Named
{
public:
/**
*\~english
*\brief Constructor.
*\param[in] pass The parent frame pass.
*\param[in] context The rendering context.
*\param[in] graph The runnable graph.
*\param[in] device The GPU device.
*\param[in] lightType The light source type.
*\param[in] size The render area dimensions.
*\param[in] gpInfo The GBuffer configuration UBO.
*\param[in] gpResult The GBuffer.
*\param[in] smResult The shadow map.
*\param[in] downscaleResult The downscaled result.
*\~french
*\brief Constructeur.
*\param[in] pass La frame pass parente.
*\param[in] context Le contexte de rendu.
*\param[in] graph Le runnable graph.
*\param[in] device Le device GPU.
*\param[in] size Les dimensions de la zone de rendu.
*\param[in] gpInfo L'UBO de configuration du GBuffer.
*\param[in] gpResult Le GBuffer.
*\param[in] smResult La shadow map.
*\param[in] downscaleResult Le résultat downscaled.
*/
C3D_API RsmGIPass( crg::FrameGraph & graph
, crg::FramePassArray const & previousPasses
, RenderDevice const & device
, LightType lightType
, ShadowBuffer const & shadowBuffer
, VkExtent3D const & size
, CameraUbo const & cameraUbo
, crg::ImageViewId const & depthObj
, crg::ImageViewId const & nmlOcc
, ShadowMapResult const & smResult
, TextureArray const & result );
/**
*\copydoc castor3d::RenderTechniquePass::accept
*/
C3D_API void accept( ConfigurationVisitorBase & visitor );
C3D_API void update( Light const & light );

RsmConfigUbo const & getConfigUbo()const
{
return m_rsmConfigUbo;
}

GpuBufferOffsetT< castor::Point4f > const & getSamplesSsbo()const
{
return m_rsmSamplesSsbo;
}

crg::FramePass const & getPass()const
{
return *m_pass;
}

protected:
C3D_API void doSubInitialise();
C3D_API void doSubRecordInto( crg::RecordContext & context
, VkCommandBuffer commandBuffer
, uint32_t index );

private:
RsmConfigUbo m_rsmConfigUbo;
GpuBufferOffsetT< castor::Point4f > m_rsmSamplesSsbo;
ShaderModule m_vertexShader;
ShaderModule m_pixelShader;
ashes::PipelineShaderStageCreateInfoArray m_stages;
crg::FramePass const * m_pass;
};
}

#endif
Loading

0 comments on commit 859cb82

Please sign in to comment.