From d457cf45d5694c40c9ef47d421a13618b315eabe Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Sat, 4 Aug 2018 16:51:05 +0200 Subject: [PATCH] Fixed bug with NaN shadow anti frustum leading to disappearing shadows on some occasions --- libraries/render-utils/src/RenderShadowTask.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 4d8b949063..b073037e32 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -99,12 +99,14 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende // CPU jobs: finer grained culling const auto cullInputs = CullShadowBounds::Inputs(sortedShapes, shadowFilter, antiFrustum).asVarying(); - const auto culledShadowItemsAndBounds = task.addJob("CullShadowCascade", cullInputs, shadowCullFunctor); + sprintf(jobName, "CullShadowCascade%d", i); + const auto culledShadowItemsAndBounds = task.addJob(jobName, cullInputs, shadowCullFunctor); // GPU jobs: Render to shadow map sprintf(jobName, "RenderShadowMap%d", i); task.addJob(jobName, culledShadowItemsAndBounds, shapePlumber, i); - task.addJob("ShadowCascadeTeardown", shadowFilter); + sprintf(jobName, "ShadowCascadeTeardown%d", i); + task.addJob(jobName, shadowFilter); cascadeSceneBBoxes[i] = culledShadowItemsAndBounds.getN(1); } @@ -181,6 +183,9 @@ static void adjustNearFar(const AABox& inShapeBounds, ViewFrustum& shadowFrustum computeNearFar(sceneBoundVertices, shadowClipPlanes, near, far); // Limit the far range to the one used originally. far = glm::min(far, shadowFrustum.getFarClip()); + if (near > far) { + near = far; + } const auto depthEpsilon = 0.1f; auto projMatrix = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, near - depthEpsilon, far + depthEpsilon);