mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 22:44:15 +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::Shadow::Schema::Schema() :
|
||||
bias{ 0.005f },
|
||||
scale{ 1.0f / MAP_SIZE } {
|
||||
|
||||
LightStage::Shadow::Schema::Schema() {
|
||||
ShadowTransform defaultTransform;
|
||||
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>() } {
|
||||
|
@ -97,7 +98,7 @@ void LightStage::Shadow::setKeylightFrustum(const ViewFrustum& viewFrustum,
|
|||
_frustum->calculate();
|
||||
|
||||
// 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) {
|
||||
|
@ -106,7 +107,7 @@ void LightStage::Shadow::setFrustum(const ViewFrustum& shadowFrustum) {
|
|||
|
||||
*_frustum = shadowFrustum;
|
||||
// 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 {
|
||||
|
|
|
@ -68,15 +68,13 @@ public:
|
|||
model::LightPointer _light;
|
||||
std::shared_ptr<ViewFrustum> _frustum;
|
||||
|
||||
class Schema {
|
||||
#include "Shadows_shared.slh"
|
||||
|
||||
class Schema : public ShadowParameters {
|
||||
public:
|
||||
|
||||
Schema();
|
||||
|
||||
glm::mat4 reprojection;
|
||||
|
||||
glm::float32 bias;
|
||||
glm::float32 scale;
|
||||
};
|
||||
UniformBufferView _schemaBuffer = nullptr;
|
||||
|
||||
|
|
|
@ -14,27 +14,22 @@
|
|||
// the shadow texture
|
||||
uniform sampler2DShadow shadowMap;
|
||||
|
||||
struct ShadowTransform {
|
||||
mat4 reprojection;
|
||||
|
||||
float bias;
|
||||
float scale;
|
||||
};
|
||||
<@include Shadows_shared.slh@>
|
||||
|
||||
uniform shadowTransformBuffer {
|
||||
ShadowTransform _shadowTransform;
|
||||
ShadowParameters shadow;
|
||||
};
|
||||
|
||||
mat4 getShadowReprojection() {
|
||||
return _shadowTransform.reprojection;
|
||||
return shadow.cascades[0].reprojection;
|
||||
}
|
||||
|
||||
float getShadowScale() {
|
||||
return _shadowTransform.scale;
|
||||
return shadow.invMapSize;
|
||||
}
|
||||
|
||||
float getShadowBias() {
|
||||
return _shadowTransform.bias;
|
||||
return shadow.cascades[0].bias;
|
||||
}
|
||||
|
||||
// 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