44#include " Lux/Renderer/Camera.h"
55#include " Lux/Renderer/RenderCommandBuffer.h"
66#include " Lux/Renderer/RenderPass.h"
7+ #include " Lux/Renderer/ComputePass.h"
78#include " Lux/Renderer/Pipeline.h"
9+ #include " Lux/Renderer/PipelineCompute.h"
810#include " Lux/Renderer/Framebuffer.h"
911#include " Lux/Renderer/Material.h"
1012#include " Lux/Renderer/Mesh.h"
@@ -138,6 +140,9 @@ namespace Lux {
138140 class SceneRenderer : public RefCounted
139141 {
140142 public:
143+ static constexpr uint32_t MaxSpotShadows = 16 ;
144+ static constexpr uint32_t LightCullingTileSize = 16 ;
145+ static constexpr uint32_t MaxVisibleLightsPerTile = 256 ;
141146 struct Statistics
142147 {
143148 uint32_t DrawCalls = 0 ;
@@ -279,19 +284,23 @@ namespace Lux {
279284 void FlushDrawList ();
280285
281286 void ShadowMapPass ();
287+ void SpotShadowMapPass ();
282288 void PreDepthPass ();
289+ void LightCullingPass ();
283290 void SkyboxPass ();
284291 void GeometryPass ();
285292 void CompositePass ();
286293 void GridPass ();
287294
288295 void UpdateStatistics ();
296+ void ResizeLightCullingResources ();
289297
290298 // Render-thread draw helper (must be called inside Renderer::Submit).
291299 void RT_DrawStaticMesh (Ref<RenderCommandBuffer> cmd,
292300 const StaticDrawCommand& dc,
293301 const TransformMapData& tmd,
294- bool bindMaterial);
302+ bool bindMaterial,
303+ uint32_t lightIndex = 0 );
295304
296305 // ── Uniform buffer GPU structs ────────────────────────────────────────
297306
@@ -332,10 +341,10 @@ namespace Lux {
332341
333342 struct UBSpotShadow
334343 {
335- glm::mat4 ViewProjection[16 ];
344+ glm::mat4 ViewProjection[MaxSpotShadows ];
336345 uint32_t Count = 0 ;
337346 glm::vec3 Padding{};
338- };
347+ } m_SpotShadowUB ;
339348
340349 struct UBRendererData
341350 {
@@ -355,6 +364,14 @@ namespace Lux {
355364 char Pad3[3 ] = { 0 , 0 , 0 };
356365 } m_RendererDataUB;
357366
367+ struct UBScreenData
368+ {
369+ glm::vec2 InvFullResolution = { 1 .0f , 1 .0f };
370+ glm::vec2 FullResolution = { 1 .0f , 1 .0f };
371+ glm::vec2 InvHalfResolution = { 1 .0f , 1 .0f };
372+ glm::vec2 HalfResolution = { 1 .0f , 1 .0f };
373+ } m_ScreenDataUB;
374+
358375 struct UBPointLights
359376 {
360377 uint32_t Count = 0 ;
@@ -397,24 +414,40 @@ namespace Lux {
397414 Ref<UniformBufferSet> m_UBSShadow;
398415 Ref<UniformBufferSet> m_UBSSpotShadow;
399416 Ref<UniformBufferSet> m_UBSRendererData;
417+ Ref<UniformBufferSet> m_UBSScreenData;
400418 Ref<UniformBufferSet> m_UBSPointLights;
401419 Ref<UniformBufferSet> m_UBSSpotLights;
402420
403421 Ref<StorageBufferSet> m_SBSInstanceTransforms; // TransformVertexData[]
404422 Ref<StorageBufferSet> m_SBSObjectIndexes; // uint32_t[] – maps draw → transform
405423 Ref<StorageBufferSet> m_SBSVisiblePointLightIndices;
406424 Ref<StorageBufferSet> m_SBSVisibleSpotLightIndices;
425+ uint32_t m_LightTilesCountX = 1 ;
426+ uint32_t m_LightTilesCountY = 1 ;
427+ uint32_t m_VisibleLightIndexBufferSize = 0 ;
407428
408429 // ── Shadow map (single ortho cascade) ────────────────────────────────
409430 Ref<Image2D> m_ShadowMapImage;
410431 Ref<RenderPass> m_ShadowMapPass;
411432 Ref<Material> m_ShadowPassMaterial;
412433
434+ // ── Spot shadow atlas ───────────────────────────────────────────────
435+ Ref<Image2D> m_SpotShadowMapImage;
436+ Ref<RenderPass> m_SpotShadowMapPass;
437+ Ref<Material> m_SpotShadowPassMaterial;
438+ uint32_t m_SpotShadowMapSize = 2048 ;
439+ uint32_t m_SpotShadowAtlasGridSize = 1 ;
440+ uint32_t m_SpotShadowTileSize = 2048 ;
441+ uint32_t m_SpotShadowCount = 0 ;
442+
413443 // ── Pre-depth pass ────────────────────────────────────────────────────
414444 Ref<Pipeline> m_PreDepthPipeline;
415445 Ref<Material> m_PreDepthMaterial;
416446 Ref<RenderPass> m_PreDepthPass;
417447
448+ // ── Tiled light culling ──────────────────────────────────────────────
449+ Ref<ComputePass> m_LightCullingPass;
450+
418451 // ── Geometry pass ─────────────────────────────────────────────────────
419452 Ref<Framebuffer> m_GeometryPassFramebuffer; // owns the attachments
420453 Ref<Pipeline> m_GeometryPipeline; // opaque PBR
0 commit comments