Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
LightPool.cpp
Go to the documentation of this file.
1
2
3#include "Headers/LightPool.h"
4
15
18
19namespace Divide
20{
21 Handle<Texture> LightPool::s_lightIconsTexture = INVALID_HANDLE<Texture>;
22 Handle<ShaderProgram> LightPool::s_lightImpostorShader = INVALID_HANDLE<ShaderProgram>;
23 ShaderBuffer_uptr LightPool::s_lightBuffer = nullptr;
24 ShaderBuffer_uptr LightPool::s_sceneBuffer = nullptr;
25 ShaderBuffer_uptr LightPool::s_shadowBuffer = nullptr;
27 {{
28 4, //SINGLE
29 5, //LAYERED
30 6 //CUBE
31 } };
32
33 namespace
34 {
35 FORCE_INLINE I32 GetMaxLights( const LightType type ) noexcept
36 {
37 switch ( type )
38 {
42 case LightType::COUNT: break;
43 }
44
45 return 0;
46 }
47 }
48
49 bool LightPool::IsLightInViewFrustum( const Frustum& frustum, const Light* const light ) noexcept
50 {
51 I8 frustumPlaneCache = -1;
52 return frustum.ContainsSphere( light->boundingVolume(), frustumPlaneCache ) != FrustumCollision::FRUSTUM_OUT;
53 }
54
56 {
57 ShaderBufferDescriptor bufferDescriptor = {};
58 bufferDescriptor._ringBufferLength = Config::MAX_FRAMES_IN_FLIGHT + 1u;
62
63 {
64 bufferDescriptor._name = "LIGHT_DATA";
66 bufferDescriptor._bufferParams._elementSize = sizeof( LightProperties );
67 // Holds general info about the currently active lights: position, colour, etc.
68 s_lightBuffer = context.gfx().newSB( bufferDescriptor );
69 }
70 {
71 // Holds info about the currently active shadow casting lights:
72 // ViewProjection Matrices, View Space Position, etc
73 bufferDescriptor._name = "LIGHT_SHADOW";
74 bufferDescriptor._bufferParams._elementCount = 1;
75 bufferDescriptor._bufferParams._elementSize = sizeof( ShadowProperties );
76 s_shadowBuffer = context.gfx().newSB( bufferDescriptor );
77 }
78 {
79 bufferDescriptor._name = "LIGHT_SCENE";
81 bufferDescriptor._bufferParams._elementCount = to_base( RenderStage::COUNT ) - 1;
82 bufferDescriptor._bufferParams._elementSize = sizeof( SceneData );
83 // Holds general info about the currently active scene: light count, ambient colour, etc.
84 s_sceneBuffer = context.gfx().newSB( bufferDescriptor );
85 }
86 ShaderModuleDescriptor vertModule = {};
88 vertModule._sourceFile = "lightImpostorShader.glsl";
89
90 ShaderModuleDescriptor geomModule = {};
92 geomModule._sourceFile = "lightImpostorShader.glsl";
93
94 ShaderModuleDescriptor fragModule = {};
96 fragModule._sourceFile = "lightImpostorShader.glsl";
97
98 ShaderProgramDescriptor shaderDescriptor = {};
99 shaderDescriptor._modules.push_back( vertModule );
100 shaderDescriptor._modules.push_back( geomModule );
101 shaderDescriptor._modules.push_back( fragModule );
102
103 std::atomic_uint loadingTasks = 0u;
104 ResourceDescriptor<ShaderProgram> lightImpostorShader( "lightImpostorShader", shaderDescriptor );
105 lightImpostorShader.waitForReady( false );
106 s_lightImpostorShader = CreateResource( lightImpostorShader, loadingTasks );
107
108 ResourceDescriptor<Texture> iconImage( "LightIconTexture" );
109 iconImage.assetLocation( Paths::g_imagesLocation );
110 iconImage.assetName( "lightIcons.png" );
111 iconImage.waitForReady( false );
112 TextureDescriptor& iconDescriptor = iconImage._propertyDescriptor;
115
116 s_lightIconsTexture = CreateResource( iconImage, loadingTasks );
117
118 WAIT_FOR_CONDITION( loadingTasks.load() == 0u );
119 }
120
122 {
125
126 s_lightBuffer.reset();
127 s_shadowBuffer.reset();
128 s_sceneBuffer.reset();
129 }
130
132 : FrameListener( "LightPool", context.kernel().frameListenerMgr(), 231 )
133 , SceneComponent( parentScene )
134 , PlatformContextComponent( context )
135 , _shadowPassTimer( Time::ADD_TIMER( "Shadow Pass Timer" ) )
136 {
137 for ( U8 i = 0u; i < to_U8( RenderStage::COUNT ); ++i )
138 {
139 _activeLightCount[i].fill( 0 );
141 }
142
143 _lightTypeState.fill( true );
144 }
145
147 {
149
150 const SharedLock<SharedMutex> r_lock( _lightLock );
151 for ( const LightList& lightList : _lights )
152 {
153 if ( !lightList.empty() )
154 {
155 Console::errorfn( LOCALE_STR( "ERROR_LIGHT_POOL_LIGHT_LEAKED" ) );
156 }
157 }
158 }
159
160
161 bool LightPool::clear() noexcept
162 {
163 return _lights.empty();
164 }
165
166 bool LightPool::frameStarted( [[maybe_unused]] const FrameEvent& evt )
167 {
169
170 return true;
171 }
172
173 bool LightPool::frameEnded( [[maybe_unused]] const FrameEvent& evt )
174 {
176
179 return true;
180 }
181
183 {
184 const LightType type = light.getLightType();
185 const U32 lightTypeIdx = to_base( type );
186
188 if ( findLightLocked( light.getGUID(), type ) != end( _lights[lightTypeIdx] ) )
189 {
190
191 Console::errorfn( LOCALE_STR( "ERROR_LIGHT_POOL_DUPLICATE" ),
192 light.getGUID() );
193 return false;
194 }
195
196 _lights[lightTypeIdx].emplace_back( &light );
197 _totalLightCount += 1u;
198
199 return true;
200 }
201
202 // try to remove any leftover lights
203 bool LightPool::removeLight( const Light& light )
204 {
206 const LightList::const_iterator it = findLightLocked( light.getGUID(), light.getLightType() );
207
208 if ( it == end( _lights[to_U32( light.getLightType() )] ) )
209 {
210 Console::errorfn( LOCALE_STR( "ERROR_LIGHT_POOL_REMOVE_LIGHT" ),
211 light.getGUID() );
212 return false;
213 }
214
215 _lights[to_U32( light.getLightType() )].erase( it ); // remove it from the map
216 _totalLightCount -= 1u;
217 return true;
218 }
219
220 void LightPool::onVolumeMoved( const BoundingSphere& volume, const bool staticSource )
221 {
223
225 _movedSceneVolumes.push_back( { volume , staticSource } );
226 }
227
228 //ToDo: Generate shadow maps in parallel - Ionut
229 void LightPool::generateShadowMaps( const Camera& playerCamera, GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut )
230 {
232
234
235 std::array<I32, to_base( LightType::COUNT )> indexCounter{};
236 std::array<bool, to_base( LightType::COUNT )> shadowsGenerated{};
237
239
240 const Frustum& camFrustum = playerCamera.getFrustum();
241
242 U32 totalShadowLightCount = 0u;
243
244 constexpr U8 stageIndex = to_U8( RenderStage::SHADOW );
245 LightList& sortedLights = _sortedLights[stageIndex];
246
247 GFX::ComputeMipMapsCommand computeMipMapsCommand = {};
248 for ( Light* light : sortedLights )
249 {
250 const LightType lType = light->getLightType();
252 computeMipMapsCommand._usage = ImageUsage::SHADER_READ;
253
254 // Skip non-shadow casting lights (and free up resources if any are used by it)
255 if ( !light->enabled() || !light->castsShadows() )
256 {
257 const U16 crtShadowIOffset = light->getShadowArrayOffset();
258 if ( crtShadowIOffset != U16_MAX )
259 {
260 if ( !ShadowMap::freeShadowMapOffset( *light ) )
261 {
263 }
264 light->setShadowArrayOffset( U16_MAX );
265 }
266 continue;
267 }
268
269 // We have a global shadow casting budget that we need to consider
270 if ( ++totalShadowLightCount >= Config::Lighting::MAX_SHADOW_CASTING_LIGHTS )
271 {
272 break;
273 }
274
275 // Make sure we do not go over our shadow casting budget and only consider visible and cache invalidated lights
276 I32& counter = indexCounter[to_base( lType )];
277 if ( counter == GetMaxLights( lType ) || !IsLightInViewFrustum( camFrustum, light ) )
278 {
279 continue;
280 }
281
282 if ( !isShadowCacheInvalidated( playerCamera.snapshot()._eye, light ) && ShadowMap::markShadowMapsUsed( *light ) )
283 {
284 continue;
285 }
286
287 // We have a valid shadow map update request at this point. Register our properties slot ...
288 const I32 shadowIndex = counter++;
289 light->shadowPropertyIndex( shadowIndex );
290
291 // ... and update the shadow map
292 if ( !ShadowMap::generateShadowMaps( playerCamera, *light, bufferInOut, memCmdInOut ) )
293 {
294 continue;
295 }
296
297 const Light::ShadowProperties& propsSource = light->getShadowProperties();
298 SubRange& layerRange = computeMipMapsCommand._layerRange;
299 layerRange._offset = std::min( layerRange._offset, light->getShadowArrayOffset() );
300
301 switch ( lType )
302 {
303 case LightType::POINT:
304 {
305 PointShadowProperties& propsTarget = _shadowBufferData._pointLights[shadowIndex];
306 propsTarget._details = propsSource._lightDetails;
307 propsTarget._position = propsSource._lightPosition[0];
308 layerRange._count = std::max( layerRange._count, to_U16( light->getShadowArrayOffset() + 1u ) );
309 }break;
310 case LightType::SPOT:
311 {
312 SpotShadowProperties& propsTarget = _shadowBufferData._spotLights[shadowIndex];
313 propsTarget._details = propsSource._lightDetails;
314 propsTarget._vpMatrix = propsSource._lightVP[0];
315 propsTarget._position = propsSource._lightPosition[0];
316 layerRange._count = std::max( layerRange._count, to_U16( light->getShadowArrayOffset() + 1u ) );
317 }break;
319 {
320 CSMShadowProperties& propsTarget = _shadowBufferData._dirLights[shadowIndex];
321 propsTarget._details = propsSource._lightDetails;
322
323 for ( U8 i = 0u; i < Config::Lighting::MAX_CSM_SPLITS_PER_LIGHT; ++i)
324 {
325 std::memcpy( propsTarget._position[i]._v, propsSource._lightPosition[0]._v, sizeof(F32) * 4u);
326 }
327
328 for ( U8 i = 0u; i < Config::Lighting::MAX_CSM_SPLITS_PER_LIGHT; ++i)
329 {
330 std::memcpy( propsTarget._vpMatrix[i].m, propsSource._lightVP[i].m, sizeof(F32) * 16u );
331 }
332
333 layerRange._count = std::max( layerRange._count, to_U16( light->getShadowArrayOffset() + static_cast<DirectionalLightComponent*>(light)->csmSplitCount() ) );
334 }break;
335 case LightType::COUNT:
337 break;
338 }
339 light->cleanShadowProperties();
340
341 shadowsGenerated[to_base( lType )] = true;
342
343 GFX::EnqueueCommand( bufferInOut, computeMipMapsCommand );
344 }
345
346 ShadowMap::generateWorldAO( playerCamera, bufferInOut, memCmdInOut );
347
348 memCmdInOut._bufferLocks.push_back( s_shadowBuffer->writeData( _shadowBufferData.data() ) );
349
350 _shadowBufferDirty = true;
351
352 ShadowMap::bindShadowMaps( bufferInOut );
353 }
354
356 {
357 _debugLight = light;
358 ShadowMap::setDebugViewLight( context().gfx(), _debugLight );
359 }
360
361 Light* LightPool::getLight( const I64 lightGUID, const LightType type ) const
362 {
364
365 const LightList::const_iterator it = findLight( lightGUID, type );
366 if ( it != eastl::end( _lights[to_U32( type )] ) )
367 {
368 return *it;
369 }
370
372 return nullptr;
373 }
374
375 U32 LightPool::uploadLightList( const RenderStage stage, const LightList& lights, const mat4<F32>& viewMatrix )
376 {
377 const U8 stageIndex = to_U8( stage );
378 U32 ret = 0u;
379
380 auto& lightCount = _activeLightCount[stageIndex];
381 LightData& crtData = _sortedLightProperties[stageIndex];
382
383 SpotLightComponent* spot = nullptr;
384
385 lightCount.fill( 0 );
386 vec3<F32> tempColour;
387 for ( Light* light : lights )
388 {
389 const LightType type = light->getLightType();
390 const U32 typeIndex = to_U32( type );
391
392 if ( _lightTypeState[typeIndex] && light->enabled() && light->range() > 0.f )
393 {
395 {
396 break;
397 }
398
399 const bool isDir = type == LightType::DIRECTIONAL;
400 const bool isOmni = type == LightType::POINT;
401 const bool isSpot = type == LightType::SPOT;
402 if ( isSpot )
403 {
404 spot = static_cast<SpotLightComponent*>(light);
405 }
406
407 LightProperties& temp = crtData[ret - 1];
408 light->getDiffuseColour( tempColour );
409 temp._diffuse.set( tempColour * light->intensity(), isSpot ? std::cos( Angle::DegreesToRadians( spot->outerConeCutoffAngle() ) ) : 0.f );
410 // Omni and spot lights have a position. Directional lights have this set to (0,0,0)
411 temp._position.set( isDir ? VECTOR3_ZERO : (viewMatrix * vec4<F32>( light->positionCache(), 1.0f )).xyz, light->range() );
412 temp._direction.set( isOmni ? VECTOR3_ZERO : (viewMatrix * vec4<F32>( light->directionCache(), 0.0f )).xyz, isSpot ? std::cos( Angle::DegreesToRadians( spot->coneCutoffAngle() ) ) : 0.f );
413 temp._options.xyz = { typeIndex, light->shadowPropertyIndex(), isSpot ? to_I32( spot->coneSlantHeight() ) : 0 };
414
415 ++lightCount[typeIndex];
416 }
417 }
418
419 return ret;
420 }
421
422 // This should be called in a separate thread for each RenderStage
423 void LightPool::sortLightData( const RenderStage stage, const CameraSnapshot& cameraSnapshot )
424 {
426
427 const U8 stageIndex = to_U8( stage );
428
429 LightList& sortedLights = _sortedLights[stageIndex];
430 sortedLights.resize( 0 );
431 {
433 sortedLights.reserve( _totalLightCount );
434 for ( U8 i = 1; i < to_base( LightType::COUNT ); ++i )
435 {
436 sortedLights.insert( cend( sortedLights ), cbegin( _lights[i] ), cend( _lights[i] ) );
437 }
438 }
439
440 const vec3<F32>& eyePos = cameraSnapshot._eye;
441 const auto lightSortCbk = [&eyePos]( Light* a, Light* b ) noexcept
442 {
443 return a->getLightType() < b->getLightType() ||
444 (a->getLightType() == b->getLightType() &&
445 a->distanceSquared( eyePos ) < b->distanceSquared( eyePos ));
446 };
447
448 PROFILE_SCOPE( "LightPool::SortLights", Profiler::Category::Scene );
449 if ( sortedLights.size() > LightList::kMaxSize )
450 {
451 std::sort( std::execution::par_unseq, begin( sortedLights ), end( sortedLights ), lightSortCbk );
452 }
453 else
454 {
455 eastl::sort( begin( sortedLights ), end( sortedLights ), lightSortCbk );
456 }
457 {
459 const LightList& dirLights = _lights[to_base( LightType::DIRECTIONAL )];
460 sortedLights.insert( begin( sortedLights ), cbegin( dirLights ), cend( dirLights ) );
461 }
462
463 }
464
465 void LightPool::uploadLightData( const RenderStage stage, const CameraSnapshot& cameraSnapshot, GFX::MemoryBarrierCommand& memCmdInOut )
466 {
468
469 const size_t stageIndex = to_size( stage );
470 LightList& sortedLights = _sortedLights[stageIndex];
471
472 U32& totalLightCount = _sortedLightPropertiesCount[stageIndex];
473 totalLightCount = uploadLightList( stage, sortedLights, cameraSnapshot._viewMatrix );
474
475 SceneData& crtData = _sortedSceneProperties[stageIndex];
476 crtData._globalData.set(
480 0u );
481
482 if ( !sortedLights.empty() )
483 {
484 crtData._ambientColour.rgb = { 0.05f * sortedLights.front()->getDiffuseColour() };
485 }
486 else
487 {
489 }
490
491 {
492 PROFILE_SCOPE( "LightPool::UploadLightDataToGPU", Profiler::Category::Graphics );
493 memCmdInOut._bufferLocks.push_back(s_lightBuffer->writeData( { stageIndex * Config::Lighting::MAX_ACTIVE_LIGHTS_PER_FRAME, totalLightCount }, &_sortedLightProperties[stageIndex] ) );
494 }
495
496 {
497 PROFILE_SCOPE( "LightPool::UploadSceneDataToGPU", Profiler::Category::Graphics );
498 memCmdInOut._bufferLocks.push_back(s_sceneBuffer->writeData( { stageIndex, 1 }, &crtData ) );
499 }
500 }
501
502 [[nodiscard]] bool LightPool::isShadowCacheInvalidated( [[maybe_unused]] const vec3<F32>& cameraPosition, Light* const light )
503 {
504 {
506 if ( _movedSceneVolumes.empty() )
507 {
508 return light->staticShadowsDirty() || light->dynamicShadowsDirty();
509 }
510 }
511
512 const BoundingSphere& lightBounds = light->boundingVolume();
513 {
515 for ( const MovingVolume& volume : _movedSceneVolumes )
516 {
517 if ( volume._volume.collision( lightBounds ) )
518 {
519 if ( volume._staticSource )
520 {
521 light->staticShadowsDirty( true );
522 }
523 else
524 {
525 light->dynamicShadowsDirty( true );
526 }
527 if ( light->staticShadowsDirty() && light->dynamicShadowsDirty() )
528 {
529 return true;
530 }
531 }
532 }
533 }
534 return light->staticShadowsDirty() || light->dynamicShadowsDirty();
535 }
536
537 void LightPool::preRenderAllPasses( const Camera* playerCamera )
538 {
540
541 constexpr U16 k_parallelSortThreshold = 16u;
542
543 const auto lightUpdateFunc = [playerCamera]( const LightList& lightList )
544 {
545 for ( Light* light : lightList )
546 {
547 light->updateBoundingVolume( playerCamera );
548 }
549 };
550
552 if ( _lights.size() > k_parallelSortThreshold )
553 {
554 std::for_each( std::execution::par_unseq, std::cbegin( _lights ), std::cend( _lights ), lightUpdateFunc );
555 }
556 else
557 {
558 for ( const LightList& list : _lights )
559 {
560 lightUpdateFunc(list);
561 }
562 }
563
564 if ( _shadowBufferDirty )
565 {
566 s_shadowBuffer->incQueue();
567 _shadowBufferDirty = false;
568 }
569
570 s_lightBuffer->incQueue();
571 s_sceneBuffer->incQueue();
572 }
573
575 {
576 if ( !lightImpostorsEnabled() )
577 {
578 return;
579 }
580
581 static const SamplerDescriptor iconSampler = {
583 ._wrapU = TextureWrap::REPEAT,
584 ._wrapV = TextureWrap::REPEAT,
585 ._wrapW = TextureWrap::REPEAT,
586 ._anisotropyLevel = 0u
587 };
588
589 const U32 totalLightCount = _sortedLightPropertiesCount[to_U8( RenderStage::DISPLAY )];
590 if ( totalLightCount > 0u )
591 {
592 PipelineDescriptor pipelineDescriptor{};
593 pipelineDescriptor._shaderProgramHandle = s_lightImpostorShader;
594 pipelineDescriptor._primitiveTopology = PrimitiveTopology::POINTS;
595
596 GFX::EnqueueCommand<GFX::BindPipelineCommand>( bufferInOut )->_pipeline = _context.gfx().newPipeline( pipelineDescriptor );
597 {
598 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>( bufferInOut );
599 cmd->_usage = DescriptorSetUsage::PER_DRAW;
600
602 Set( binding._data, s_lightIconsTexture, iconSampler );
603 }
604
605 GFX::EnqueueCommand<GFX::DrawCommand>( bufferInOut )->_drawCommands.back()._drawCount = to_U16( totalLightCount );
606 }
607 }
608
609}
#define WAIT_FOR_CONDITION(...)
#define LOCALE_STR(X)
Definition: Localization.h:91
#define DIVIDE_UNEXPECTED_CALL()
#define FORCE_INLINE
#define PROFILE_SCOPE_AUTO(CATEGORY)
Definition: Profiler.h:87
#define PROFILE_SCOPE(NAME, CATEGORY)
Definition: Profiler.h:86
const Frustum & getFrustum() const noexcept
Returns the most recent/up-to-date frustum.
Definition: Camera.inl:202
const CameraSnapshot & snapshot() const noexcept
Returns the internal camera snapshot data (eye, orientation, etc)
Definition: Camera.inl:43
ShaderBuffer_uptr newSB(const ShaderBufferDescriptor &descriptor)
Definition: GFXDevice.inl:214
Pipeline * newPipeline(const PipelineDescriptor &descriptor)
Create and return a new graphics pipeline. This is only used for caching and doesn't use the object a...
Definition: GFXDevice.cpp:3074
FORCE_INLINE I64 getGUID() const noexcept
Definition: GUIDWrapper.h:51
A light object placed in the scene at a certain position.
Definition: Light.h:58
F32 distanceSquared(const vec3< F32 > &pos) const noexcept
Get the distance squared from this light to the specified position.
Definition: Light.inl:48
const LightType & getLightType() const noexcept
Get the light type. (see LightType enum)
Definition: Light.inl:46
void debugLight(Light *light)
nullptr = disabled
Definition: LightPool.cpp:355
std::array< LightData, to_base(RenderStage::COUNT)> _sortedLightProperties
Definition: LightPool.h:221
SharedMutex _movedSceneVolumesLock
Definition: LightPool.h:229
U32 uploadLightList(RenderStage stage, const LightList &lights, const mat4< F32 > &viewMatrix)
Definition: LightPool.cpp:375
void drawLightImpostors(GFX::CommandBuffer &bufferInOut) const
Definition: LightPool.cpp:574
Light * getLight(I64 lightGUID, LightType type) const
Definition: LightPool.cpp:361
void uploadLightData(RenderStage stage, const CameraSnapshot &cameraSnapshot, GFX::MemoryBarrierCommand &memCmdInOut)
Definition: LightPool.cpp:465
void preRenderAllPasses(const Camera *playerCamera)
Definition: LightPool.cpp:537
static Handle< ShaderProgram > s_lightImpostorShader
Definition: LightPool.h:239
void generateShadowMaps(const Camera &playerCamera, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
Definition: LightPool.cpp:229
static ShaderBuffer_uptr s_lightBuffer
Definition: LightPool.h:240
std::array< LightProperties, Config::Lighting::MAX_ACTIVE_LIGHTS_PER_FRAME > LightData
Definition: LightPool.h:215
static bool IsLightInViewFrustum(const Frustum &frustum, const Light *light) noexcept
Definition: LightPool.cpp:49
void sortLightData(RenderStage stage, const CameraSnapshot &cameraSnapshot)
Definition: LightPool.cpp:423
std::array< SceneData, to_base(RenderStage::COUNT)> _sortedSceneProperties
Definition: LightPool.h:223
LightList::const_iterator findLight(const I64 GUID, const LightType type) const
Definition: LightPool.h:174
ShadowProperties _shadowBufferData
Definition: LightPool.h:227
void onVolumeMoved(const BoundingSphere &volume, bool staticSource)
Definition: LightPool.cpp:220
std::array< LightList, to_base(LightType::COUNT)> _lights
Definition: LightPool.h:225
LightPool(Scene &parentScene, PlatformContext &context)
Definition: LightPool.cpp:131
bool frameEnded(const FrameEvent &evt) override
frameEnded is called after the buffers have been swapped
Definition: LightPool.cpp:173
Time::ProfileTimer & _shadowPassTimer
Definition: LightPool.h:233
bool clear() noexcept
Definition: LightPool.cpp:161
bool removeLight(const Light &light)
remove a light from the manager
Definition: LightPool.cpp:203
bool isShadowCacheInvalidated(const vec3< F32 > &cameraPosition, Light *light)
Definition: LightPool.cpp:502
bool _shadowBufferDirty
Definition: LightPool.h:235
static ShaderBuffer_uptr s_shadowBuffer
Definition: LightPool.h:242
static ShaderBuffer_uptr s_sceneBuffer
Definition: LightPool.h:241
eastl::fixed_vector< Light *, 32u, true > LightList
Definition: LightPool.h:115
static void DestroyStaticData()
Definition: LightPool.cpp:121
std::array< bool, to_base(LightType::COUNT)> _lightTypeState
Definition: LightPool.h:226
static void InitStaticData(PlatformContext &context)
Definition: LightPool.cpp:55
static std::array< U8, to_base(ShadowType::COUNT)> s_shadowLocation
Definition: LightPool.h:237
std::array< LightList, to_base(RenderStage::COUNT)> _sortedLights
Definition: LightPool.h:220
bool addLight(Light &light)
Add a new light to the manager.
Definition: LightPool.cpp:182
static Handle< Texture > s_lightIconsTexture
Definition: LightPool.h:238
std::array< U32, to_base(RenderStage::COUNT)> _sortedLightPropertiesCount
Definition: LightPool.h:222
~LightPool() override
Definition: LightPool.cpp:146
std::array< LightCountPerType, to_base(RenderStage::COUNT)> _activeLightCount
Definition: LightPool.h:219
SharedMutex _lightLock
Definition: LightPool.h:232
bool frameStarted(const FrameEvent &evt) override
Definition: LightPool.cpp:166
LightList::const_iterator findLightLocked(const I64 GUID, const LightType type) const
Definition: LightPool.h:179
eastl::fixed_vector< MovingVolume, Config::MAX_VISIBLE_NODES, true > _movedSceneVolumes
Definition: LightPool.h:230
PlatformContext & context() noexcept
GFXDevice & gfx() noexcept
Handle< Texture > texture() const
RTAttachment * getAttachment(RTAttachmentType type, RTColourAttachmentSlot slot=RTColourAttachmentSlot::SLOT_0) const
static void setDebugViewLight(GFXDevice &context, Light *light)
Definition: ShadowMap.cpp:522
static bool freeShadowMapOffset(const Light &light)
Definition: ShadowMap.cpp:329
static bool generateShadowMaps(const Camera &playerCamera, Light &light, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
Definition: ShadowMap.cpp:468
static const RenderTargetHandle & getShadowMap(LightType type)
Definition: ShadowMap.cpp:495
static void reset()
Definition: ShadowMap.cpp:273
static void resetShadowMaps()
Definition: ShadowMap.cpp:286
static void generateWorldAO(const Camera &playerCamera, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
Definition: ShadowMap.cpp:490
static bool markShadowMapsUsed(Light &light)
Definition: ShadowMap.cpp:455
static void bindShadowMaps(GFX::CommandBuffer &bufferInOut)
Definition: ShadowMap.cpp:305
void set(const T *v) noexcept
set the 4 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:1241
vec3< T > rgb
Definition: MathVectors.h:1378
vec3< T > xyz
Definition: MathVectors.h:1374
constexpr T DegreesToRadians(T angleDegrees) noexcept
Return the radian equivalent of the given degree value.
Definition: MathHelper.inl:429
constexpr U8 MAX_SHADOW_CASTING_POINT_LIGHTS
Definition: config.h:152
constexpr U8 MAX_SHADOW_CASTING_SPOT_LIGHTS
Definition: config.h:153
constexpr U16 MAX_ACTIVE_LIGHTS_PER_FRAME
Maximum number of lights we process per frame. We need this upper bound for pre-allocating arrays and...
Definition: config.h:162
constexpr U8 MAX_SHADOW_CASTING_LIGHTS
Maximum number of shadow casting lights processed per frame.
Definition: config.h:156
constexpr U8 MAX_CSM_SPLITS_PER_LIGHT
Used for CSM or PSSM to determine the maximum number of frustum splits.
Definition: config.h:159
constexpr U8 MAX_SHADOW_CASTING_DIRECTIONAL_LIGHTS
How many lights (in order as passed to the shader for the node) should cast shadows.
Definition: config.h:151
constexpr U8 MAX_FRAMES_IN_FLIGHT
Maximum number of active frames until we start waiting on a fence/sync.
Definition: config.h:100
FORCE_INLINE T * EnqueueCommand(CommandBuffer &buffer)
constexpr Optick::Category::Type Scene
Definition: Profiler.h:66
constexpr Optick::Category::Type Graphics
Definition: Profiler.h:60
FORCE_INLINE I32 GetMaxLights(const LightType type) noexcept
Definition: LightPool.cpp:35
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::lock_guard< mutex > LockGuard
Definition: SharedMutex.h:55
constexpr U32 to_U32(const T value)
FORCE_INLINE void DestroyResource(Handle< T > &handle, const bool immediate=false)
constexpr U16 to_U16(const T value)
int32_t I32
uint8_t U8
DirectionalLightComponent(SceneGraphNode *sgn, PlatformContext &context)
std::shared_lock< mutex > SharedLock
Definition: SharedMutex.h:49
constexpr U16 U16_MAX
uint16_t U16
void Set(DescriptorSetBindingData &dataInOut, ShaderBuffer *buffer, const BufferRange range) noexcept
DescriptorSetBinding & AddBinding(DescriptorSet &setInOut, U8 slot, U16 stageVisibilityMask)
FORCE_INLINE Handle< T > CreateResource(const ResourceDescriptor< T > &descriptor, bool &wasInCache, std::atomic_uint &taskCounter)
LightType
The different types of lights supported.
void efficient_clear(eastl::fixed_vector< T, nodeCount, bEnableOverflow, OverflowAllocator > &fixed_vector)
Definition: Vector.h:52
constexpr U8 to_U8(const T value)
constexpr size_t to_size(const T value)
constexpr I32 to_I32(const T value)
static const vec3< F32 > VECTOR3_ZERO
Definition: MathVectors.h:1434
int64_t I64
uint32_t U32
constexpr auto to_base(const Type value) -> Type
BufferUpdateUsage _updateUsage
Definition: BufferParams.h:40
BufferUsageType _usageType
Definition: BufferParams.h:41
BufferUpdateFrequency _updateFrequency
Definition: BufferParams.h:39
size_t _elementSize
Buffer primitive size in bytes.
Definition: BufferParams.h:50
BufferFlags _flags
Definition: BufferParams.h:48
static NO_INLINE void errorfn(const char *format, T &&... args)
DescriptorSetBindingData _data
std::array< vec4< F32 >, 6 > _lightPosition
light's position in world space. w - csm split distances (or whatever else might be needed)
Definition: Light.h:67
std::array< mat4< F32 >, 6 > _lightVP
light viewProjection matrices
Definition: Light.h:69
std::array< vec4< F32 >, Config::Lighting::MAX_CSM_SPLITS_PER_LIGHT > _position
Definition: LightPool.h:93
std::array< mat4< F32 >, Config::Lighting::MAX_CSM_SPLITS_PER_LIGHT > _vpMatrix
Definition: LightPool.h:94
std::array< PointShadowProperties, Config::Lighting::MAX_SHADOW_CASTING_POINT_LIGHTS > _pointLights
Definition: LightPool.h:97
std::array< SpotShadowProperties, Config::Lighting::MAX_SHADOW_CASTING_SPOT_LIGHTS > _spotLights
Definition: LightPool.h:98
std::array< CSMShadowProperties, Config::Lighting::MAX_SHADOW_CASTING_DIRECTIONAL_LIGHTS > _dirLights
Definition: LightPool.h:99
bufferPtr data() const noexcept
Definition: LightPool.h:101
Handle< ShaderProgram > _shaderProgramHandle
Definition: Pipeline.h:47
vector< ShaderModuleDescriptor > _modules
PropertyDescriptor< T > _propertyDescriptor
Definition: Resource.h:151
TextureMipSampling _mipSampling