ADD: multi light system
This commit is contained in:
@@ -70,6 +70,13 @@ struct AllocatedBuffer {
|
||||
VmaAllocationInfo info;
|
||||
};
|
||||
|
||||
struct GPUPunctualLight {
|
||||
glm::vec4 position_radius;
|
||||
glm::vec4 color_intensity;
|
||||
};
|
||||
|
||||
static constexpr uint32_t kMaxPunctualLights = 64;
|
||||
|
||||
struct GPUSceneData {
|
||||
glm::mat4 view;
|
||||
glm::mat4 proj;
|
||||
@@ -84,6 +91,9 @@ struct GPUSceneData {
|
||||
// Hybrid ray-query options (match shaders/input_structures.glsl)
|
||||
glm::uvec4 rtOptions; // x: enabled (1/0), y: cascade mask, z,w: reserved
|
||||
glm::vec4 rtParams; // x: N·L threshold, yzw: reserved
|
||||
|
||||
GPUPunctualLight punctualLights[kMaxPunctualLights];
|
||||
glm::uvec4 lightCounts;
|
||||
};
|
||||
|
||||
enum class MaterialPass :uint8_t {
|
||||
|
||||
@@ -27,6 +27,16 @@ SceneManager::~SceneManager()
|
||||
pendingGLTFRelease.size());
|
||||
}
|
||||
|
||||
void SceneManager::addPointLight(const PointLight &light)
|
||||
{
|
||||
pointLights.push_back(light);
|
||||
}
|
||||
|
||||
void SceneManager::clearPointLights()
|
||||
{
|
||||
pointLights.clear();
|
||||
}
|
||||
|
||||
void SceneManager::init(EngineContext *context)
|
||||
{
|
||||
_context = context;
|
||||
@@ -39,6 +49,21 @@ void SceneManager::init(EngineContext *context)
|
||||
sceneData.ambientColor = glm::vec4(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
sceneData.sunlightDirection = glm::vec4(-0.2f, -1.0f, -0.3f, 1.0f);
|
||||
sceneData.sunlightColor = glm::vec4(1.0f, 1.0f, 1.0f, 3.0f);
|
||||
|
||||
// Seed a couple of default point lights for quick testing.
|
||||
PointLight warmKey{};
|
||||
warmKey.position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
warmKey.radius = 25.0f;
|
||||
warmKey.color = glm::vec3(1.0f, 0.95f, 0.8f);
|
||||
warmKey.intensity = 15.0f;
|
||||
addPointLight(warmKey);
|
||||
|
||||
PointLight coolFill{};
|
||||
coolFill.position = glm::vec3(-10.0f, 4.0f, 10.0f);
|
||||
coolFill.radius = 20.0f;
|
||||
coolFill.color = glm::vec3(0.6f, 0.7f, 1.0f);
|
||||
coolFill.intensity = 10.0f;
|
||||
addPointLight(coolFill);
|
||||
}
|
||||
|
||||
void SceneManager::update_scene()
|
||||
@@ -290,6 +315,21 @@ void SceneManager::update_scene()
|
||||
sceneData.rtParams = glm::vec4(ss.hybridRayNoLThreshold, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
// Fill punctual lights into GPUSceneData
|
||||
const uint32_t lightCount = static_cast<uint32_t>(std::min(pointLights.size(), static_cast<size_t>(kMaxPunctualLights)));
|
||||
for (uint32_t i = 0; i < lightCount; ++i)
|
||||
{
|
||||
const PointLight &pl = pointLights[i];
|
||||
sceneData.punctualLights[i].position_radius = glm::vec4(pl.position, pl.radius);
|
||||
sceneData.punctualLights[i].color_intensity = glm::vec4(pl.color, pl.intensity);
|
||||
}
|
||||
for (uint32_t i = lightCount; i < kMaxPunctualLights; ++i)
|
||||
{
|
||||
sceneData.punctualLights[i].position_radius = glm::vec4(0.0f);
|
||||
sceneData.punctualLights[i].color_intensity = glm::vec4(0.0f);
|
||||
}
|
||||
sceneData.lightCounts = glm::uvec4(lightCount, 0u, 0u, 0u);
|
||||
|
||||
auto end = std::chrono::system_clock::now();
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||
stats.scene_update_time = elapsed.count() / 1000.f;
|
||||
|
||||
@@ -126,6 +126,18 @@ public:
|
||||
bool setGLTFInstanceAnimation(const std::string &instanceName, const std::string &animationName, bool resetTime = true);
|
||||
bool setGLTFInstanceAnimationLoop(const std::string &instanceName, bool loop);
|
||||
|
||||
struct PointLight
|
||||
{
|
||||
glm::vec3 position;
|
||||
float radius;
|
||||
glm::vec3 color;
|
||||
float intensity;
|
||||
};
|
||||
|
||||
void addPointLight(const PointLight &light);
|
||||
void clearPointLights();
|
||||
const std::vector<PointLight> &getPointLights() const { return pointLights; }
|
||||
|
||||
struct SceneStats
|
||||
{
|
||||
float scene_update_time = 0.f;
|
||||
@@ -148,6 +160,7 @@ private:
|
||||
Camera mainCamera = {};
|
||||
GPUSceneData sceneData = {};
|
||||
DrawContext mainDrawContext;
|
||||
std::vector<PointLight> pointLights;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<LoadedGLTF> > loadedScenes;
|
||||
std::unordered_map<std::string, std::shared_ptr<Node> > loadedNodes;
|
||||
|
||||
Reference in New Issue
Block a user