mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +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();
|
||||
|
||||
// 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) {
|
||||
|
|
|
@ -94,6 +94,8 @@ public:
|
|||
};
|
||||
UniformBufferView _schemaBuffer = nullptr;
|
||||
|
||||
void setupCascades();
|
||||
|
||||
friend class Light;
|
||||
};
|
||||
using ShadowPointer = std::shared_ptr<Shadow>;
|
||||
|
|
|
@ -215,7 +215,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende
|
|||
initZPassPipelines(*shapePlumber, state);
|
||||
}
|
||||
|
||||
const auto cachedMode = task.addJob<RenderShadowSetup>("ShadowSetup");
|
||||
const auto cachedMode = task.addJob<RenderShadowSetup>("ShadowSetup", 0);
|
||||
|
||||
// CPU jobs:
|
||||
// Fetch and cull the items from the scene
|
||||
|
@ -249,13 +249,24 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, O
|
|||
RenderArgs* args = renderContext->args;
|
||||
output = args->_renderMode;
|
||||
|
||||
auto nearClip = args->getViewFrustum().getNearClip();
|
||||
float nearDepth = -args->_boomOffset.z;
|
||||
const float SHADOW_MAX_DISTANCE = 20.0f;
|
||||
globalShadow->setKeylightFrustum(0, args->getViewFrustum(), nearDepth, nearClip + SHADOW_MAX_DISTANCE, SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR);
|
||||
const auto nearClip = args->getViewFrustum().getNearClip();
|
||||
const auto farClip = args->getViewFrustum().getFarClip();
|
||||
const auto nearDepth = -args->_boomOffset.z;
|
||||
|
||||
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
|
||||
args->pushViewFrustum(*(globalShadow->getCascade(0).getFrustum()));
|
||||
args->pushViewFrustum(*(globalShadow->getCascade(_cascadeIndex).getFrustum()));
|
||||
args->_renderMode = RenderArgs::SHADOW_RENDER_MODE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,13 @@ class RenderShadowSetup {
|
|||
public:
|
||||
using Output = RenderArgs::RenderMode;
|
||||
using JobModel = render::Job::ModelO<RenderShadowSetup, Output>;
|
||||
|
||||
RenderShadowSetup(unsigned int cascadeIndex) : _cascadeIndex{ cascadeIndex } {}
|
||||
void run(const render::RenderContextPointer& renderContext, Output& output);
|
||||
|
||||
private:
|
||||
|
||||
unsigned int _cascadeIndex;
|
||||
};
|
||||
|
||||
class RenderShadowTeardown {
|
||||
|
|
|
@ -13,7 +13,9 @@ struct ShadowTransform {
|
|||
MAT4 reprojection;
|
||||
|
||||
float bias;
|
||||
vec3 _padding;
|
||||
float minDistance;
|
||||
float maxDistance;
|
||||
float _padding;
|
||||
};
|
||||
|
||||
struct ShadowParameters {
|
||||
|
|
Loading…
Reference in a new issue