2023-10-26 18:37:29 +02:00
|
|
|
#include "LightEnvironment.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
|
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
|
|
|
|
LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
|
|
|
|
|
: graphics(graphics)
|
|
|
|
|
{
|
|
|
|
|
layout = graphics->createDescriptorLayout("LightEnvironment");
|
2023-10-31 16:16:23 +01:00
|
|
|
layout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
2023-10-26 18:37:29 +02:00
|
|
|
layout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
|
|
|
layout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
2023-10-31 16:16:23 +01:00
|
|
|
layout->create();
|
|
|
|
|
lightEnvBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
|
2023-11-01 23:12:30 +01:00
|
|
|
.sourceData = {
|
2023-10-31 16:16:23 +01:00
|
|
|
.size = sizeof(LightEnv),
|
|
|
|
|
.data = (uint8*) &lightEnv,
|
|
|
|
|
},
|
|
|
|
|
.bDynamic = true,
|
|
|
|
|
});
|
|
|
|
|
directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
2023-11-01 23:12:30 +01:00
|
|
|
.sourceData = {
|
2023-10-31 16:16:23 +01:00
|
|
|
.size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
|
|
|
|
|
.data = (uint8*)dirs.data(),
|
|
|
|
|
},
|
|
|
|
|
.stride = sizeof(Component::DirectionalLight),
|
|
|
|
|
.bDynamic = true,
|
|
|
|
|
});
|
|
|
|
|
pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
2023-11-01 23:12:30 +01:00
|
|
|
.sourceData = {
|
2023-10-31 16:16:23 +01:00
|
|
|
.size = sizeof(Component::PointLight) * MAX_POINT_LIGHTS,
|
|
|
|
|
.data = (uint8*)dirs.data(),
|
|
|
|
|
},
|
|
|
|
|
.stride = sizeof(Component::PointLight),
|
|
|
|
|
.bDynamic = true,
|
|
|
|
|
});
|
2023-10-26 18:37:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LightEnvironment::~LightEnvironment()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LightEnvironment::addDirectionalLight(Component::DirectionalLight dirLight)
|
|
|
|
|
{
|
2023-10-31 16:16:23 +01:00
|
|
|
dirs.add(dirLight);
|
2023-10-26 18:37:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LightEnvironment::addPointLight(Component::PointLight pointLight)
|
|
|
|
|
{
|
2023-10-31 16:16:23 +01:00
|
|
|
points.add(pointLight);
|
2023-10-26 18:37:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LightEnvironment::commit()
|
|
|
|
|
{
|
2023-10-31 16:16:23 +01:00
|
|
|
lightEnv.numDirectionalLights = dirs.size();
|
|
|
|
|
lightEnv.numPointLights = points.size();
|
2023-11-01 23:12:30 +01:00
|
|
|
lightEnvBuffer->updateContents(DataSource{
|
2023-10-31 16:16:23 +01:00
|
|
|
.size = sizeof(LightEnv),
|
|
|
|
|
.data = (uint8*) & lightEnv,
|
|
|
|
|
});
|
2023-11-01 23:12:30 +01:00
|
|
|
directionalLights->updateContents(DataSource{
|
2023-10-31 16:16:23 +01:00
|
|
|
.size = sizeof(Component::DirectionalLight) * dirs.size(),
|
|
|
|
|
.data = (uint8*)dirs.data(),
|
|
|
|
|
});
|
2023-11-01 23:12:30 +01:00
|
|
|
pointLights->updateContents(DataSource{
|
2023-10-31 16:16:23 +01:00
|
|
|
.size = sizeof(Component::PointLight) * points.size(),
|
|
|
|
|
.data = (uint8*)points.data(),
|
|
|
|
|
});
|
|
|
|
|
set->updateBuffer(0, lightEnvBuffer);
|
|
|
|
|
set->updateBuffer(1, directionalLights);
|
|
|
|
|
set->updateBuffer(2, pointLights);
|
2023-10-26 18:37:29 +02:00
|
|
|
}
|