mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
Added cascades in schema buffer but still only first used
This commit is contained in:
parent
cbd2877524
commit
7fd03bed7e
4 changed files with 45 additions and 21 deletions
|
@ -23,10 +23,11 @@ const glm::mat4 LightStage::Shadow::_biasMatrix{
|
||||||
LightStage::LightStage() {
|
LightStage::LightStage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
LightStage::Shadow::Schema::Schema() :
|
LightStage::Shadow::Schema::Schema() {
|
||||||
bias{ 0.005f },
|
ShadowTransform defaultTransform;
|
||||||
scale{ 1.0f / MAP_SIZE } {
|
defaultTransform.bias = 0.005f;
|
||||||
|
std::fill(cascades, cascades + SHADOW_CASCADE_MAX_COUNT, defaultTransform);
|
||||||
|
invMapSize = 1.0f / MAP_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
LightStage::Shadow::Shadow(model::LightPointer light) : _light{ light}, _frustum{ std::make_shared<ViewFrustum>() } {
|
LightStage::Shadow::Shadow(model::LightPointer light) : _light{ light}, _frustum{ std::make_shared<ViewFrustum>() } {
|
||||||
|
@ -97,7 +98,7 @@ void LightStage::Shadow::setKeylightFrustum(const ViewFrustum& viewFrustum,
|
||||||
_frustum->calculate();
|
_frustum->calculate();
|
||||||
|
|
||||||
// Update the buffer
|
// Update the buffer
|
||||||
_schemaBuffer.edit<Schema>().reprojection = _biasMatrix * ortho * viewInverse.getMatrix();
|
_schemaBuffer.edit<Schema>().cascades[0].reprojection = _biasMatrix * ortho * viewInverse.getMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightStage::Shadow::setFrustum(const ViewFrustum& shadowFrustum) {
|
void LightStage::Shadow::setFrustum(const ViewFrustum& shadowFrustum) {
|
||||||
|
@ -106,7 +107,7 @@ void LightStage::Shadow::setFrustum(const ViewFrustum& shadowFrustum) {
|
||||||
|
|
||||||
*_frustum = shadowFrustum;
|
*_frustum = shadowFrustum;
|
||||||
// Update the buffer
|
// Update the buffer
|
||||||
_schemaBuffer.edit<Schema>().reprojection = _biasMatrix * shadowFrustum.getProjection() * viewInverse.getMatrix();
|
_schemaBuffer.edit<Schema>().cascades[0].reprojection = _biasMatrix * shadowFrustum.getProjection() * viewInverse.getMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::mat4& LightStage::Shadow::getView() const {
|
const glm::mat4& LightStage::Shadow::getView() const {
|
||||||
|
|
|
@ -68,15 +68,13 @@ public:
|
||||||
model::LightPointer _light;
|
model::LightPointer _light;
|
||||||
std::shared_ptr<ViewFrustum> _frustum;
|
std::shared_ptr<ViewFrustum> _frustum;
|
||||||
|
|
||||||
class Schema {
|
#include "Shadows_shared.slh"
|
||||||
|
|
||||||
|
class Schema : public ShadowParameters {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Schema();
|
Schema();
|
||||||
|
|
||||||
glm::mat4 reprojection;
|
|
||||||
|
|
||||||
glm::float32 bias;
|
|
||||||
glm::float32 scale;
|
|
||||||
};
|
};
|
||||||
UniformBufferView _schemaBuffer = nullptr;
|
UniformBufferView _schemaBuffer = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -14,27 +14,22 @@
|
||||||
// the shadow texture
|
// the shadow texture
|
||||||
uniform sampler2DShadow shadowMap;
|
uniform sampler2DShadow shadowMap;
|
||||||
|
|
||||||
struct ShadowTransform {
|
<@include Shadows_shared.slh@>
|
||||||
mat4 reprojection;
|
|
||||||
|
|
||||||
float bias;
|
|
||||||
float scale;
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform shadowTransformBuffer {
|
uniform shadowTransformBuffer {
|
||||||
ShadowTransform _shadowTransform;
|
ShadowParameters shadow;
|
||||||
};
|
};
|
||||||
|
|
||||||
mat4 getShadowReprojection() {
|
mat4 getShadowReprojection() {
|
||||||
return _shadowTransform.reprojection;
|
return shadow.cascades[0].reprojection;
|
||||||
}
|
}
|
||||||
|
|
||||||
float getShadowScale() {
|
float getShadowScale() {
|
||||||
return _shadowTransform.scale;
|
return shadow.invMapSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
float getShadowBias() {
|
float getShadowBias() {
|
||||||
return _shadowTransform.bias;
|
return shadow.cascades[0].bias;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the texture coordinates from world coordinates
|
// Compute the texture coordinates from world coordinates
|
||||||
|
|
30
libraries/render-utils/src/Shadows_shared.slh
Normal file
30
libraries/render-utils/src/Shadows_shared.slh
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// glsl / C++ compatible source as interface for Shadows
|
||||||
|
#ifdef __cplusplus
|
||||||
|
# define MAT4 glm::mat4
|
||||||
|
# define VEC3 glm::vec3
|
||||||
|
#else
|
||||||
|
# define MAT4 mat4
|
||||||
|
# define VEC3 ve3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SHADOW_CASCADE_MAX_COUNT 4
|
||||||
|
|
||||||
|
struct ShadowTransform {
|
||||||
|
MAT4 reprojection;
|
||||||
|
|
||||||
|
float bias;
|
||||||
|
vec3 _padding;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ShadowParameters {
|
||||||
|
int cascadeCount;
|
||||||
|
float invMapSize;
|
||||||
|
float _padding1;
|
||||||
|
float _padding2;
|
||||||
|
ShadowTransform cascades[SHADOW_CASCADE_MAX_COUNT];
|
||||||
|
};
|
||||||
|
|
||||||
|
// <@if 1@>
|
||||||
|
// Trigger Scribe include
|
||||||
|
// <@endif@> <!def that !>
|
||||||
|
//
|
Loading…
Reference in a new issue