42 : _context( context ),
80 for (
U32 i = 0; i < cameraCount; ++i )
154 desc._name = isCSM ?
"CSM_ShadowMap" :
"Single_ShadowMap";
166 desc._name = isCSM ?
"CSM_ShadowMap_StaticCache" :
"Single_ShadowMap_StaticCache";
202 depthDescriptor._layerCount = colourMapDescriptor._layerCount;
209 desc.
_name =
"Cube_ShadowMap";
227 desc.
_name =
"Cube_ShadowMap_StaticCache";
258 handle._rt =
nullptr;
267 handle._rt =
nullptr;
278 for (
auto& mast : lifetimeMask )
281 mast._lightGUID = -1;
299 ++lifetime._lifetime;
307 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>( bufferInOut );
313 if ( sm.
_rt ==
nullptr )
347 for (
U32 i = layerOffset; i < layerOffset + layerRequirement; ++i )
350 lifetimeMask[i]._lightGUID = -1;
359 if ( layerCount == 0u ) [[unlikely]]
370 if ( crtArrayOffset !=
U16_MAX ) [[likely]]
373 for (
U16 i = 0u; i < layerCount; ++i )
375 if ( lifetimeMask[crtArrayOffset + i]._lightGUID == light.
getGUID() )
377 lifetimeMask[crtArrayOffset + i]._lifetime = 0u;
385 if ( valid ) [[likely]]
396 if ( layerCount == 1u )
398 for (
U16 i = 0u; i < lifetimeMask.size(); ++i )
402 lifetimeMask[i]._lifetime = 0u;
403 lifetimeMask[i]._lightGUID = light.
getGUID();
412 const U16 availableLayers =
to_U16( lifetimeMask.size() );
414 for (
U16 i = 0u; i < availableLayers - layerCount; ++i )
416 for (
U16 j = i; j < i + layerCount; ++j )
428 for (
U16 j = i; j < i + layerCount; ++j )
430 lifetimeMask[j]._lifetime = 0u;
431 lifetimeMask[j]._lightGUID = light.
getGUID();
542 if ( light !=
nullptr && light->castsShadows() )
547 vertModule.
_variant =
"FullScreenQuad";
558 fragModule.
_variant =
"Layered.LinearDepth";
561 shaderDescriptor.
_modules.push_back( vertModule );
562 shaderDescriptor.
_modules.push_back( fragModule );
565 shadowPreviewShader.waitForReady(
true );
569 constexpr I16 Base = 2;
570 for (
U8 i = 0; i < splitCount; ++i )
572 DebugView_ptr shadow = std::make_shared<DebugView>(
to_I16(
I16_MAX - 1 - splitCount + i ) );
575 shadow->_shader = previewShader;
577 shadow->_groupID = Base +
to_I16( light->shadowPropertyIndex() );
578 shadow->_enabled =
true;
585 constexpr I16 Base = 22;
586 fragModule.
_variant =
"Layered.LinearDepth";
589 shaderDescriptor.
_modules.push_back( vertModule );
590 shaderDescriptor.
_modules.push_back( fragModule );
593 shadowPreviewShader.waitForReady(
true );
595 DebugView_ptr shadow = std::make_shared<DebugView>(
to_I16(
I16_MAX - 1 ) );
600 shadow->_enabled =
true;
601 shadow->_groupID = Base +
to_I16( light->shadowPropertyIndex() );
607 constexpr I16 Base = 222;
608 fragModule.
_variant =
"Cube.Shadow";
611 shaderDescriptor.
_modules.push_back( vertModule );
612 shaderDescriptor.
_modules.back()._defines.emplace_back(
"SPLAT_R_CHANNEL" );
613 shaderDescriptor.
_modules.push_back( fragModule );
616 shadowPreviewShader.waitForReady(
true );
619 for (
U8 i = 0u; i < 6u; ++i )
621 DebugView_ptr shadow = std::make_shared<DebugView>(
to_I16(
I16_MAX - 1 - 6 + i ) );
624 shadow->_shader = previewShader;
627 shadow->_groupID = Base +
to_I16( light->shadowPropertyIndex() );
628 shadow->_enabled =
true;
#define PROFILE_SCOPE_AUTO(CATEGORY)
static Camera * CreateCamera(const Str< 256 > &cameraName, Mode cameraMode)
static bool DestroyCamera(Camera *&camera)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
GFXRTPool & renderTargetPool() noexcept
bool removeDebugView(DebugView *view)
DebugView * addDebugView(const std::shared_ptr< DebugView > &view)
RenderTargetHandle allocateRT(const RenderTargetDescriptor &descriptor)
bool deallocateRT(RenderTargetHandle &handle)
FORCE_INLINE I64 getGUID() const noexcept
A light object placed in the scene at a certain position.
const LightType & getLightType() const noexcept
Get the light type. (see LightType enum)
void setShadowArrayOffset(const U16 offset) noexcept
U16 getShadowArrayOffset() const noexcept
static U8 GetShadowBindSlotOffset(const ShadowType type) noexcept
Get the appropriate shadow bind slot for every light's shadow.
static ShaderBuffer * ShadowBuffer()
PlatformContext & context() noexcept
Configuration & config() noexcept
Handle< Texture > texture() const
RTAttachmentDescriptor _descriptor
RTAttachment * getAttachment(RTAttachmentType type, RTColourAttachmentSlot slot=RTColourAttachmentSlot::SLOT_0) const
ShadowMapGenerator(GFXDevice &context, ShadowType type) noexcept
static void setDebugViewLight(GFXDevice &context, Light *light)
static bool freeShadowMapOffset(const Light &light)
static bool generateShadowMaps(const Camera &playerCamera, Light &light, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
static Light * s_shadowPreviewLight
static constexpr U8 MAX_SHADOW_FRAME_LIFETIME
static std::array< RenderTargetHandle, to_base(ShadowType::COUNT)> s_shadowMapCaches
static vector< DebugView_ptr > s_debugViews
static void setMSAASampleCount(ShadowType type, U8 sampleCount)
static std::array< RenderTargetHandle, to_base(ShadowType::COUNT)> s_shadowMaps
static const RenderTargetHandle & getShadowMapCache(LightType type)
static std::array< ShadowCameraPool, to_base(ShadowType::COUNT)> s_shadowCameras
static vector< std::unique_ptr< ShadowMapGenerator > > s_shadowMapGenerators
static ShadowType getShadowTypeForLightType(LightType type) noexcept
static bool freeShadowMapOffsetLocked(const Light &light)
static bool commitLayerRange(Light &light)
static const RenderTargetHandle & getShadowMap(LightType type)
vector< Camera * > ShadowCameraPool
vector< ShadowLayerData > LayerLifetimeMask
static void initShadowMaps(GFXDevice &context)
static void resetShadowMaps()
static void destroyShadowMaps(GFXDevice &context)
static void generateWorldAO(const Camera &playerCamera, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
static Mutex s_shadowMapUsageLock
static U32 getLightLayerRequirements(const Light &light)
static bool markShadowMapsUsed(Light &light)
static std::array< U16, to_base(ShadowType::COUNT)> s_shadowPassIndex
static LightType getLightTypeForShadowType(ShadowType type) noexcept
static void bindShadowMaps(GFX::CommandBuffer &bufferInOut)
static std::array< LayerLifetimeMask, to_base(ShadowType::COUNT)> s_shadowMapLifetime
void set(const T *v) noexcept
set the 2 components of the vector manually using a source pointer to a (large enough) array
constexpr U8 MAX_SHADOW_CASTING_POINT_LIGHTS
constexpr U8 MAX_SHADOW_CASTING_SPOT_LIGHTS
constexpr U8 MAX_CSM_SPLITS_PER_LIGHT
Used for CSM or PSSM to determine the maximum number of frustum splits.
constexpr U8 MAX_SHADOW_CASTING_DIRECTIONAL_LIGHTS
How many lights (in order as passed to the shader for the node) should cast shadows.
static const char * shadowType[]
constexpr Optick::Category::Type Graphics
Str StringFormat(const char *fmt, Args &&...args)
Handle console commands that start with a forward slash.
std::lock_guard< mutex > LockGuard
constexpr U32 nextPOW2(U32 n) noexcept
constexpr U32 to_U32(const T value)
constexpr U16 to_U16(const T value)
DirectionalLightComponent(SceneGraphNode *sgn, PlatformContext &context)
void Set(DescriptorSetBindingData &dataInOut, ShaderBuffer *buffer, const BufferRange range) noexcept
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
DescriptorSetBinding & AddBinding(DescriptorSet &setInOut, U8 slot, U16 stageVisibilityMask)
FORCE_INLINE Handle< T > CreateResource(const ResourceDescriptor< T > &descriptor, bool &wasInCache, std::atomic_uint &taskCounter)
constexpr bool isPowerOfTwo(const T x) noexcept
LightType
The different types of lights supported.
constexpr U8 to_U8(const T value)
constexpr I16 to_I16(const T value)
constexpr auto to_base(const Type value) -> Type
Divide::Configuration::Rendering::ShadowMapping::CSMSettings csm
struct Divide::Configuration::Rendering::ShadowMapping shadowMapping
U8 maxAnisotropicFilteringLevel
struct Divide::Configuration::Rendering rendering
DescriptorSetBindingData _data
vector< ShaderModuleDescriptor > _modules
MipMappingState _mipMappingState
SamplerDescriptor _sampler
InternalRTAttachmentDescriptors _attachments
TextureFilter _minFilter
Texture filtering mode.
TextureWrap _wrapU
Texture wrap mode (Or S-R-T)
U8 _anisotropyLevel
The value must be in the range [0...255] and is automatically clamped by the max HW supported level.
TextureMipSampling _mipSampling