Removing limit for point lights

This commit is contained in:
Dynamitos
2024-02-01 17:08:13 +01:00
parent f9a89f6592
commit 36aec0fa06
8 changed files with 76 additions and 16 deletions
@@ -8,6 +8,12 @@ DirectionalLightActor::DirectionalLightActor(PScene scene)
attachComponent<Component::DirectionalLight>();
}
DirectionalLightActor::DirectionalLightActor(PScene scene, Vector color, Vector direction)
: Actor(scene)
{
attachComponent<Component::DirectionalLight>(Vector4(color, 0), Vector4(direction, 0));
}
DirectionalLightActor::~DirectionalLightActor()
{
+1
View File
@@ -8,6 +8,7 @@ class DirectionalLightActor : public Actor
{
public:
DirectionalLightActor(PScene scene);
DirectionalLightActor(PScene scene, Vector color, Vector direction);
virtual ~DirectionalLightActor();
Component::DirectionalLight& getDirectionalLightComponent();
const Component::DirectionalLight& getDirectionalLightComponent() const;
+6
View File
@@ -8,6 +8,12 @@ PointLightActor::PointLightActor(PScene scene)
attachComponent<Component::PointLight>();
}
PointLightActor::PointLightActor(PScene scene, Vector position, Vector color, float attenuation)
: Actor(scene)
{
attachComponent<Component::PointLight>(Vector4(position, 1), Vector4(color, attenuation));
}
PointLightActor::~PointLightActor()
{
+1
View File
@@ -8,6 +8,7 @@ class PointLightActor : public Actor
{
public:
PointLightActor(PScene scene);
PointLightActor(PScene scene, Vector position, Vector color, float attenuation);
virtual ~PointLightActor();
Component::PointLight& getPointLightComponent();
const Component::PointLight& getPointLightComponent() const;
+38 -10
View File
@@ -20,18 +20,18 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
});
directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
.size = sizeof(Component::DirectionalLight) * INIT_DIRECTIONAL_LIGHTS,
.data = nullptr,
},
.numElements = MAX_DIRECTIONAL_LIGHTS,
.numElements = INIT_DIRECTIONAL_LIGHTS,
.dynamic = true,
});
pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(Component::PointLight) * MAX_POINT_LIGHTS,
.size = sizeof(Component::PointLight) * INIT_POINT_LIGHTS,
.data = nullptr,
},
.numElements = MAX_POINT_LIGHTS,
.numElements = INIT_POINT_LIGHTS,
.dynamic = true,
});
}
@@ -66,14 +66,42 @@ void LightEnvironment::commit()
.size = sizeof(LightEnv),
.data = (uint8*) & lightEnv,
});
directionalLights->updateContents(DataSource{
.size = sizeof(Component::DirectionalLight) * dirs.size(),
.data = (uint8*)dirs.data(),
if(directionalLights->getNumElements() < dirs.size())
{
directionalLights = graphics->createShaderBuffer({
.sourceData = {
.size = sizeof(Component::DirectionalLight) * dirs.size(),
.data = (uint8*)dirs.data(),
},
.numElements = dirs.size(),
.dynamic = true,
});
pointLights->updateContents(DataSource{
.size = sizeof(Component::PointLight) * points.size(),
.data = (uint8*)points.data(),
}
else
{
directionalLights->updateContents(DataSource{
.size = sizeof(Component::DirectionalLight) * dirs.size(),
.data = (uint8*)dirs.data(),
});
}
if(pointLights->getNumElements() < points.size())
{
pointLights = graphics->createShaderBuffer({
.sourceData = {
.size = sizeof(Component::PointLight) * points.size(),
.data = (uint8*)points.data()
},
.numElements = points.size(),
.dynamic = true
});
}
else
{
pointLights->updateContents(DataSource{
.size = sizeof(Component::PointLight) * points.size(),
.data = (uint8*)points.data(),
});
}
set->updateBuffer(0, lightEnvBuffer);
set->updateBuffer(1, directionalLights);
set->updateBuffer(2, pointLights);
+2 -2
View File
@@ -18,8 +18,8 @@ public:
const Gfx::PDescriptorLayout getDescriptorLayout() const;
Gfx::PDescriptorSet getDescriptorSet();
private:
#define MAX_DIRECTIONAL_LIGHTS 4
#define MAX_POINT_LIGHTS 256
#define INIT_DIRECTIONAL_LIGHTS 4
#define INIT_POINT_LIGHTS 256
struct LightEnv
{
uint32 numDirectionalLights;