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

74 lines
3.6 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{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
2023-10-31 16:16:23 +01:00
layout->create();
lightEnvBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
2023-11-05 10:36:01 +01:00
.dynamic = true,
2023-10-31 16:16:23 +01:00
});
directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
2023-11-05 10:36:01 +01:00
.dynamic = true,
2023-10-31 16:16:23 +01:00
});
pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
2023-11-05 10:36:01 +01:00
.dynamic = true,
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() {
2023-10-31 16:16:23 +01:00
lightEnv.numDirectionalLights = dirs.size();
lightEnv.numPointLights = points.size();
lightEnvBuffer->updateContents(0, sizeof(LightEnv), &lightEnv);
2024-07-16 15:32:51 +02:00
lightEnvBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
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 |
Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | 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 |
Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
2024-09-27 15:57:37 +02:00
set->updateBuffer(0, 0, lightEnvBuffer);
set->updateBuffer(1, 0, directionalLights);
set->updateBuffer(2, 0, pointLights);
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; }