project-aster/samples/04_scenes/light_manager.h

92 lines
2.7 KiB
C++

// =============================================
// Aster: light_manager.h
// Copyright (c) 2020-2024 Anish Bhobe
// =============================================
#pragma once
#include "global.h"
// TODO: Separate files so you only import handles.
#include "render_resource_manager.h"
struct Environment;
struct DirectionalLight
{
vec3 m_Direction;
u32 m_UnusedPadding0_;
u32 m_Color_; // LSB is used for flags. (R G B Flags)
f32 m_Intensity;
};
struct PointLight
{
vec3 m_Position;
f32 m_Range;
u32 m_Color_; // LSB is used for flags. (R G B Flags)
f32 m_Intensity;
};
struct LightHandle
{
u8 m_Type;
u8 m_Generation;
u16 m_Index;
};
struct Light;
struct LightManager
{
constexpr static u16 MAX_LIGHTS = MaxValue<u16>;
struct LightMetaInfo
{
TextureHandle m_Skybox; // 04 04
TextureHandle m_Diffuse; // 04 08
TextureHandle m_Prefilter; // 04 12
TextureHandle m_BrdfLut; // 04 16
// The number of directional lights is relatively low (1 - 2) and will almost never change in a scene.
// We can use that with Offset = 0, and point light at further offsets.
// This way we don't need to move point lights often.
BufferHandle m_LightBuffer; // 04 20
u16 m_PointLightMaxCount; // 02 22
u16 m_PointLightOffset; // 02 24
u16 m_DirectionalLightMaxCount; // 02 26
u16 m_UnusedPadding0 = 0; // 02 28
u32 m_UnusedPadding1 = 0; // 04 32
};
RenderResourceManager *m_ResourceManager;
eastl::vector<Light> m_Lights;
// We don't need a Directional Light free list. We will just brute force iterate.
u16 m_DirectionalLightCount;
// TODO: A point light free list. We will brute force until we have a lot (100+) of point lights.
u16 m_PointLightCount;
LightMetaInfo m_MetaInfo;
// Using lower bit for flags. Use CAPACITY_MASK for value.
u16 m_GpuBufferCapacity_;
// Using lower bit. Capacity can be directly a multiple of 2
// Thus, range is up to MaxValue<u16>
constexpr static u16 UPDATE_REQUIRED_BIT = 1;
constexpr static u16 CAPACITY_MASK = ~(UPDATE_REQUIRED_BIT);
LightHandle AddDirectional(const vec3 &direction, const vec3 &color, f32 intensity);
LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius, f32 intensity);
void Update();
void RemoveLight(LightHandle handle);
void SetEnvironment(Environment *environment);
explicit LightManager(RenderResourceManager *resourceManager);
~LightManager();
LightManager(LightManager &&other) noexcept;
LightManager &operator=(LightManager &&other) noexcept;
DISALLOW_COPY_AND_ASSIGN(LightManager);
};