mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 03:04:33 +02:00
Optimized shadow shader evaluation by computing concatenated shadow reprojection matrix on CPU
This commit is contained in:
parent
6cd4da877e
commit
cbd2877524
3 changed files with 15 additions and 20 deletions
|
@ -14,6 +14,11 @@
|
|||
#include "LightStage.h"
|
||||
|
||||
std::string LightStage::_stageName { "LIGHT_STAGE"};
|
||||
const glm::mat4 LightStage::Shadow::_biasMatrix{
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 0.5, 0.0,
|
||||
0.5, 0.5, 0.5, 1.0 };
|
||||
|
||||
LightStage::LightStage() {
|
||||
}
|
||||
|
@ -92,8 +97,7 @@ void LightStage::Shadow::setKeylightFrustum(const ViewFrustum& viewFrustum,
|
|||
_frustum->calculate();
|
||||
|
||||
// Update the buffer
|
||||
_schemaBuffer.edit<Schema>().projection = ortho;
|
||||
_schemaBuffer.edit<Schema>().viewInverse = viewInverse.getMatrix();
|
||||
_schemaBuffer.edit<Schema>().reprojection = _biasMatrix * ortho * viewInverse.getMatrix();
|
||||
}
|
||||
|
||||
void LightStage::Shadow::setFrustum(const ViewFrustum& shadowFrustum) {
|
||||
|
@ -102,8 +106,7 @@ void LightStage::Shadow::setFrustum(const ViewFrustum& shadowFrustum) {
|
|||
|
||||
*_frustum = shadowFrustum;
|
||||
// Update the buffer
|
||||
_schemaBuffer.edit<Schema>().projection = shadowFrustum.getProjection();
|
||||
_schemaBuffer.edit<Schema>().viewInverse = viewInverse.getMatrix();
|
||||
_schemaBuffer.edit<Schema>().reprojection = _biasMatrix * shadowFrustum.getProjection() * viewInverse.getMatrix();
|
||||
}
|
||||
|
||||
const glm::mat4& LightStage::Shadow::getView() const {
|
||||
|
|
|
@ -62,6 +62,9 @@ public:
|
|||
gpu::TexturePointer map;
|
||||
|
||||
protected:
|
||||
|
||||
static const glm::mat4 _biasMatrix;
|
||||
|
||||
model::LightPointer _light;
|
||||
std::shared_ptr<ViewFrustum> _frustum;
|
||||
|
||||
|
@ -70,8 +73,7 @@ public:
|
|||
|
||||
Schema();
|
||||
|
||||
glm::mat4 projection;
|
||||
glm::mat4 viewInverse;
|
||||
glm::mat4 reprojection;
|
||||
|
||||
glm::float32 bias;
|
||||
glm::float32 scale;
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
uniform sampler2DShadow shadowMap;
|
||||
|
||||
struct ShadowTransform {
|
||||
mat4 projection;
|
||||
mat4 viewInverse;
|
||||
mat4 reprojection;
|
||||
|
||||
float bias;
|
||||
float scale;
|
||||
|
@ -26,12 +25,8 @@ uniform shadowTransformBuffer {
|
|||
ShadowTransform _shadowTransform;
|
||||
};
|
||||
|
||||
mat4 getShadowViewInverse() {
|
||||
return _shadowTransform.viewInverse;
|
||||
}
|
||||
|
||||
mat4 getShadowProjection() {
|
||||
return _shadowTransform.projection;
|
||||
mat4 getShadowReprojection() {
|
||||
return _shadowTransform.reprojection;
|
||||
}
|
||||
|
||||
float getShadowScale() {
|
||||
|
@ -44,14 +39,9 @@ float getShadowBias() {
|
|||
|
||||
// Compute the texture coordinates from world coordinates
|
||||
vec4 evalShadowTexcoord(vec4 position) {
|
||||
mat4 biasMatrix = mat4(
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 0.5, 0.0,
|
||||
0.5, 0.5, 0.5, 1.0);
|
||||
float bias = -getShadowBias();
|
||||
|
||||
vec4 shadowCoord = biasMatrix * getShadowProjection() * getShadowViewInverse() * position;
|
||||
vec4 shadowCoord = getShadowReprojection() * position;
|
||||
return vec4(shadowCoord.xy, shadowCoord.z + bias, 1.0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue