mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 15:00:36 +02:00
Min / Max cascade distance computation
This commit is contained in:
parent
8f84e5fbed
commit
08b06281f4
5 changed files with 32 additions and 8 deletions
|
@ -115,7 +115,10 @@ void LightStage::Shadow::setKeylightFrustum(unsigned int cascadeIndex, const Vie
|
||||||
cascade._frustum->calculate();
|
cascade._frustum->calculate();
|
||||||
|
|
||||||
// Update the buffer
|
// Update the buffer
|
||||||
_schemaBuffer.edit<Schema>().cascades[cascadeIndex].reprojection = _biasMatrix * ortho * viewInverse.getMatrix();
|
auto& schemaCascade = _schemaBuffer.edit<Schema>().cascades[cascadeIndex];
|
||||||
|
schemaCascade.reprojection = _biasMatrix * ortho * viewInverse.getMatrix();
|
||||||
|
schemaCascade.minDistance = viewMinShadowDistance;
|
||||||
|
schemaCascade.maxDistance = viewMaxShadowDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightStage::Shadow::setFrustum(unsigned int cascadeIndex, const ViewFrustum& shadowFrustum) {
|
void LightStage::Shadow::setFrustum(unsigned int cascadeIndex, const ViewFrustum& shadowFrustum) {
|
||||||
|
|
|
@ -94,6 +94,8 @@ public:
|
||||||
};
|
};
|
||||||
UniformBufferView _schemaBuffer = nullptr;
|
UniformBufferView _schemaBuffer = nullptr;
|
||||||
|
|
||||||
|
void setupCascades();
|
||||||
|
|
||||||
friend class Light;
|
friend class Light;
|
||||||
};
|
};
|
||||||
using ShadowPointer = std::shared_ptr<Shadow>;
|
using ShadowPointer = std::shared_ptr<Shadow>;
|
||||||
|
|
|
@ -215,7 +215,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende
|
||||||
initZPassPipelines(*shapePlumber, state);
|
initZPassPipelines(*shapePlumber, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto cachedMode = task.addJob<RenderShadowSetup>("ShadowSetup");
|
const auto cachedMode = task.addJob<RenderShadowSetup>("ShadowSetup", 0);
|
||||||
|
|
||||||
// CPU jobs:
|
// CPU jobs:
|
||||||
// Fetch and cull the items from the scene
|
// Fetch and cull the items from the scene
|
||||||
|
@ -249,13 +249,24 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, O
|
||||||
RenderArgs* args = renderContext->args;
|
RenderArgs* args = renderContext->args;
|
||||||
output = args->_renderMode;
|
output = args->_renderMode;
|
||||||
|
|
||||||
auto nearClip = args->getViewFrustum().getNearClip();
|
const auto nearClip = args->getViewFrustum().getNearClip();
|
||||||
float nearDepth = -args->_boomOffset.z;
|
const auto farClip = args->getViewFrustum().getFarClip();
|
||||||
const float SHADOW_MAX_DISTANCE = 20.0f;
|
const auto nearDepth = -args->_boomOffset.z;
|
||||||
globalShadow->setKeylightFrustum(0, args->getViewFrustum(), nearDepth, nearClip + SHADOW_MAX_DISTANCE, SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR);
|
|
||||||
|
static const float SHADOW_MAX_DISTANCE = 25.0f;
|
||||||
|
static const float SHADOW_OVERLAP_DISTANCE = 1.0f;
|
||||||
|
float maxCascadeDistance = SHADOW_MAX_DISTANCE / powf(2.0f, globalShadow->getCascadeCount() - 1 - _cascadeIndex);
|
||||||
|
float minCascadeDistance = maxCascadeDistance / 2.0f - SHADOW_OVERLAP_DISTANCE;
|
||||||
|
|
||||||
|
if (_cascadeIndex == 0) {
|
||||||
|
minCascadeDistance = nearDepth;
|
||||||
|
}
|
||||||
|
minCascadeDistance = std::max(minCascadeDistance, nearDepth);
|
||||||
|
maxCascadeDistance = std::min(maxCascadeDistance, farClip);
|
||||||
|
globalShadow->setKeylightFrustum(_cascadeIndex, args->getViewFrustum(), minCascadeDistance, maxCascadeDistance, SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR);
|
||||||
|
|
||||||
// Set the keylight render args
|
// Set the keylight render args
|
||||||
args->pushViewFrustum(*(globalShadow->getCascade(0).getFrustum()));
|
args->pushViewFrustum(*(globalShadow->getCascade(_cascadeIndex).getFrustum()));
|
||||||
args->_renderMode = RenderArgs::SHADOW_RENDER_MODE;
|
args->_renderMode = RenderArgs::SHADOW_RENDER_MODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,13 @@ class RenderShadowSetup {
|
||||||
public:
|
public:
|
||||||
using Output = RenderArgs::RenderMode;
|
using Output = RenderArgs::RenderMode;
|
||||||
using JobModel = render::Job::ModelO<RenderShadowSetup, Output>;
|
using JobModel = render::Job::ModelO<RenderShadowSetup, Output>;
|
||||||
|
|
||||||
|
RenderShadowSetup(unsigned int cascadeIndex) : _cascadeIndex{ cascadeIndex } {}
|
||||||
void run(const render::RenderContextPointer& renderContext, Output& output);
|
void run(const render::RenderContextPointer& renderContext, Output& output);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
unsigned int _cascadeIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RenderShadowTeardown {
|
class RenderShadowTeardown {
|
||||||
|
|
|
@ -13,7 +13,9 @@ struct ShadowTransform {
|
||||||
MAT4 reprojection;
|
MAT4 reprojection;
|
||||||
|
|
||||||
float bias;
|
float bias;
|
||||||
vec3 _padding;
|
float minDistance;
|
||||||
|
float maxDistance;
|
||||||
|
float _padding;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ShadowParameters {
|
struct ShadowParameters {
|
||||||
|
|
Loading…
Reference in a new issue