Pre bindless
This commit is contained in:
@@ -55,12 +55,41 @@ void LightEnvironment::reset() {
|
||||
layout->reset();
|
||||
set = layout->allocateDescriptorSet();
|
||||
dirs.clear();
|
||||
directionalTransforms.clear();
|
||||
points.clear();
|
||||
}
|
||||
|
||||
void LightEnvironment::addDirectionalLight(Component::DirectionalLight dirLight) { dirs.add(dirLight); }
|
||||
void LightEnvironment::addDirectionalLight(const Component::DirectionalLight& dirLight, const Component::Transform& transform) {
|
||||
dirs.add(ShaderDirectionalLight{
|
||||
.color = Vector4(dirLight.color, dirLight.intensity),
|
||||
.direction = Vector4(transform.getForward(), 0),
|
||||
.lightSpaceMatrix = transform.toMatrix(),
|
||||
});
|
||||
directionalTransforms.add(transform);
|
||||
if (shadowMaps.size() < dirs.size()) {
|
||||
shadowMaps.add(graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
||||
.width = 2048,
|
||||
.height = 2048,
|
||||
.elements = (uint32)dirs.size(),
|
||||
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_SAMPLED_BIT,
|
||||
.name = "ShadowMap",
|
||||
}));
|
||||
shadowSamplers.add(graphics->createSampler(SamplerCreateInfo{
|
||||
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
.name = "ShadowSampler",
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
void LightEnvironment::addPointLight(Component::PointLight pointLight) { points.add(pointLight); }
|
||||
void LightEnvironment::addPointLight(const Component::PointLight& pointLight, const Component::Transform& transform) {
|
||||
points.add(ShaderPointLight{
|
||||
.position_WS = Vector4(transform.getPosition(), pointLight.intensity),
|
||||
.colorRange = Vector4(pointLight.color, pointLight.attenuation),
|
||||
});
|
||||
}
|
||||
|
||||
void LightEnvironment::commit() {
|
||||
directionalLights->rotateBuffer(sizeof(Component::DirectionalLight) * dirs.size());
|
||||
@@ -84,17 +113,6 @@ void LightEnvironment::commit() {
|
||||
set->updateTexture("irradianceMap", 0, environment->getIrradianceMap());
|
||||
set->updateSampler("irradianceSampler", 0, environmentSampler);
|
||||
set->writeChanges();
|
||||
|
||||
while (shadowMapArray.size() < dirs.size()) {
|
||||
shadowMapArray.add(graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
||||
.width = 2048,
|
||||
.height = 2048,
|
||||
.elements = (uint32)dirs.size(),
|
||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_SAMPLED_BIT,
|
||||
.name = "ShadowMap",
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
const Gfx::PDescriptorLayout LightEnvironment::getDescriptorLayout() const { return layout; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "Component/DirectionalLight.h"
|
||||
#include "Component/PointLight.h"
|
||||
#include "Component/Transform.h"
|
||||
#include "Graphics/Buffer.h"
|
||||
#include "Graphics/Descriptor.h"
|
||||
|
||||
@@ -8,25 +9,37 @@ namespace Seele {
|
||||
DECLARE_REF(EnvironmentMapAsset)
|
||||
class LightEnvironment {
|
||||
public:
|
||||
struct ShaderDirectionalLight {
|
||||
Vector4 color;
|
||||
Vector4 direction;
|
||||
Matrix4 lightSpaceMatrix;
|
||||
};
|
||||
struct ShaderPointLight {
|
||||
Vector4 position_WS;
|
||||
Vector4 colorRange;
|
||||
};
|
||||
LightEnvironment(Gfx::PGraphics graphics);
|
||||
~LightEnvironment();
|
||||
void reset();
|
||||
void addDirectionalLight(Component::DirectionalLight dirLight);
|
||||
void addPointLight(Component::PointLight pointLight);
|
||||
void addDirectionalLight(const Component::DirectionalLight& dirLight, const Component::Transform& transform);
|
||||
void addPointLight(const Component::PointLight& pointLight, const Component::Transform& transform);
|
||||
void commit();
|
||||
const Gfx::PDescriptorLayout getDescriptorLayout() const;
|
||||
const Component::DirectionalLight& getDirectionalLight(uint32 lightIndex) const { return dirs[lightIndex]; }
|
||||
const ShaderDirectionalLight& getDirectionalLight(uint32 lightIndex) const { return dirs[lightIndex]; }
|
||||
const Component::Transform& getDirectionalTransform(uint32 lightIndex) const { return directionalTransforms[lightIndex]; }
|
||||
Gfx::PDescriptorSet getDescriptorSet();
|
||||
PEnvironmentMapAsset getEnvironmentMap() { return environment; }
|
||||
uint64 getNumDirectionalLights() const { return dirs.size(); }
|
||||
const Array<Gfx::OTexture2D>& getShadowMaps() const { return shadowMapArray; }
|
||||
const Array<Gfx::OTexture2D>& getShadowMaps() const { return shadowMaps; }
|
||||
|
||||
private:
|
||||
Gfx::OShaderBuffer directionalLights;
|
||||
Array<Gfx::OTexture2D> shadowMapArray;
|
||||
Array<Gfx::OTexture2D> shadowMaps;
|
||||
Array<Gfx::OSampler> shadowSamplers;
|
||||
Gfx::OShaderBuffer pointLights;
|
||||
Array<Component::DirectionalLight> dirs;
|
||||
Array<Component::PointLight> points;
|
||||
Array<ShaderDirectionalLight> dirs;
|
||||
Array<Component::Transform> directionalTransforms;
|
||||
Array<ShaderPointLight> points;
|
||||
PEnvironmentMapAsset environment;
|
||||
Gfx::OSampler environmentSampler;
|
||||
Gfx::ODescriptorLayout layout;
|
||||
|
||||
Reference in New Issue
Block a user