mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-19 08:18:05 +02:00
Add uniform buffer to LightStage
This commit is contained in:
parent
5c1c1e3a3b
commit
fad38c0bfb
2 changed files with 32 additions and 7 deletions
|
@ -16,6 +16,8 @@
|
|||
LightStage::Shadow::Shadow(model::LightPointer light) : _light{ light}, _frustum{ std::make_shared<ViewFrustum>() } {
|
||||
framebuffer = gpu::FramebufferPointer(gpu::Framebuffer::createShadowmap(MAP_SIZE));
|
||||
map = framebuffer->getDepthStencilBuffer();
|
||||
Schema schema{glm::mat4(), glm::mat4(), 0, MAP_SIZE};
|
||||
_schemaBuffer = std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema);
|
||||
}
|
||||
|
||||
void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float nearDepth, float farDepth) {
|
||||
|
@ -36,8 +38,8 @@ void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float near
|
|||
// Position the keylight frustum
|
||||
_frustum->setPosition(viewFrustum->getPosition() - (nearDepth + farDepth)*direction);
|
||||
|
||||
_view = _frustum->getView();
|
||||
const Transform viewInverse{ _view.getInverseMatrix() };
|
||||
const Transform view{ _frustum->getView()};
|
||||
const Transform viewInverse{ view.getInverseMatrix() };
|
||||
|
||||
viewFrustum->calculate();
|
||||
auto nearCorners = viewFrustum->getCorners(nearDepth);
|
||||
|
@ -67,7 +69,18 @@ void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float near
|
|||
|
||||
glm::mat4 ortho = glm::ortho<float>(min.x, max.x, min.y, max.y, -max.z, -min.z);
|
||||
_frustum->setProjection(ortho);
|
||||
_projection = ortho;
|
||||
|
||||
// Update the buffer
|
||||
_schemaBuffer.edit<Schema>().projection = ortho;
|
||||
_schemaBuffer.edit<Schema>().view = view.getMatrix();
|
||||
}
|
||||
|
||||
const glm::mat4& LightStage::Shadow::getView() const {
|
||||
return _frustum->getView();
|
||||
}
|
||||
|
||||
const glm::mat4& LightStage::Shadow::getProjection() const {
|
||||
return _frustum->getProjection();
|
||||
}
|
||||
|
||||
const LightStage::LightPointer LightStage::addLight(model::LightPointer light) {
|
||||
|
|
|
@ -23,6 +23,7 @@ class LightStage {
|
|||
public:
|
||||
class Shadow {
|
||||
public:
|
||||
using UniformBufferView = gpu::BufferView;
|
||||
const int MAP_SIZE = 2048;
|
||||
|
||||
Shadow(model::LightPointer light);
|
||||
|
@ -30,16 +31,27 @@ public:
|
|||
void setKeylightFrustum(ViewFrustum* viewFrustum, float nearDepth, float farDepth);
|
||||
|
||||
const std::shared_ptr<ViewFrustum> getFrustum() const { return _frustum; }
|
||||
const glm::mat4& getProjection() const { return _projection; }
|
||||
const Transform& getView() const { return _view; }
|
||||
|
||||
const glm::mat4& getView() const;
|
||||
const glm::mat4& getProjection() const;
|
||||
|
||||
const UniformBufferView& getBuffer() const { return _schemaBuffer; }
|
||||
|
||||
gpu::FramebufferPointer framebuffer;
|
||||
gpu::TexturePointer map;
|
||||
protected:
|
||||
model::LightPointer _light;
|
||||
std::shared_ptr<ViewFrustum> _frustum;
|
||||
glm::mat4 _projection;
|
||||
Transform _view;
|
||||
|
||||
class Schema {
|
||||
public:
|
||||
glm::mat4 projection;
|
||||
glm::mat4 view;
|
||||
|
||||
glm::float32 bias;
|
||||
glm::float32 scale;
|
||||
};
|
||||
UniformBufferView _schemaBuffer = nullptr;
|
||||
};
|
||||
using ShadowPointer = std::shared_ptr<Shadow>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue