Files
Seele/src/Engine/Scene/LightEnvironment.cpp
T

72 lines
3.2 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#include "LightEnvironment.h"
#include "Graphics/Graphics.h"
using namespace Seele;
2024-06-09 12:20:04 +02:00
LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) : graphics(graphics) {
2024-04-19 18:23:36 +02:00
layout = graphics->createDescriptorLayout("pLightEnv");
2024-06-09 12:20:04 +02:00
layout->addDescriptorBinding(Gfx::DescriptorBinding{
2025-02-28 16:56:51 +09:00
.name = "directionalLights",
2024-06-09 12:20:04 +02:00
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
2025-02-28 16:56:51 +09:00
.name = "numDirectionalLights",
.uniformLength = sizeof(uint)
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = "pointLights",
2024-06-09 12:20:04 +02:00
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
2025-02-28 16:56:51 +09:00
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = "numPointLights",
.uniformLength = sizeof(uint)
});
2023-10-31 16:16:23 +01:00
layout->create();
2025-02-28 16:56:51 +09:00
2023-10-31 16:16:23 +01:00
directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
2024-10-01 11:15:38 +02:00
.name = "DirectionalLights",
2023-10-31 16:16:23 +01:00
});
pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
2024-10-01 11:15:38 +02:00
.name = "PointLights",
2023-10-31 16:16:23 +01:00
});
2023-10-26 18:37:29 +02:00
}
2024-06-09 12:20:04 +02:00
LightEnvironment::~LightEnvironment() {}
2023-10-26 18:37:29 +02:00
2024-06-09 12:20:04 +02:00
void LightEnvironment::reset() {
2023-10-31 16:16:23 +01:00
layout->reset();
set = layout->allocateDescriptorSet();
dirs.clear();
points.clear();
2023-10-26 18:37:29 +02:00
}
2024-06-09 12:20:04 +02:00
void LightEnvironment::addDirectionalLight(Component::DirectionalLight dirLight) { dirs.add(dirLight); }
2023-10-26 18:37:29 +02:00
2024-06-09 12:20:04 +02:00
void LightEnvironment::addPointLight(Component::PointLight pointLight) { points.add(pointLight); }
2023-10-26 18:37:29 +02:00
2024-06-09 12:20:04 +02:00
void LightEnvironment::commit() {
2024-05-15 15:27:13 +02:00
directionalLights->rotateBuffer(sizeof(Component::DirectionalLight) * dirs.size());
directionalLights->updateContents(0, sizeof(Component::DirectionalLight) * dirs.size(), dirs.data());
2024-07-15 08:32:50 +02:00
directionalLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
2024-07-16 15:32:51 +02:00
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
2024-10-14 18:14:08 +02:00
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
2024-05-15 15:27:13 +02:00
pointLights->rotateBuffer(sizeof(Component::PointLight) * points.size());
pointLights->updateContents(0, sizeof(Component::PointLight) * points.size(), points.data());
2024-07-16 15:32:51 +02:00
pointLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
2024-10-14 18:14:08 +02:00
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
2025-02-28 16:56:51 +09:00
uint32 numPointLights = points.size();
uint32 numDirectionalLights = dirs.size();
set->updateConstants("numPointLights", 0, &numPointLights);
set->updateBuffer("pointLights", 0, pointLights);
set->updateConstants("numDirectionalLights", 0, &numDirectionalLights);
set->updateBuffer("directionalLights", 0, directionalLights);
2023-11-08 23:27:21 +01:00
set->writeChanges();
2023-10-26 18:37:29 +02:00
}
2023-11-05 10:36:01 +01:00
2024-06-09 12:20:04 +02:00
const Gfx::PDescriptorLayout LightEnvironment::getDescriptorLayout() const { return layout; }
2023-11-05 10:36:01 +01:00
2024-06-09 12:20:04 +02:00
Gfx::PDescriptorSet LightEnvironment::getDescriptorSet() { return set; }