From bd8c3e91814e5ca61aa90cf184caac45f727bd90 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 15 Oct 2019 17:22:38 -0700 Subject: [PATCH] don't limit the near plane to ~1mm (#1778) We were not checking Camera's preconditions properly -- we assumed that near < 1/1024 meant "near == 0". Now we check preconditions properly and revert to the same hardcoded default if they're not met -- doesn't matter what the default is, it's there only to avoid NaNs and Infs elsewhere -- rendering will be bogus eitherway. Fixes #1766 --- filament/src/Camera.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/filament/src/Camera.cpp b/filament/src/Camera.cpp index 900af0ec4d..6ba5e7f261 100644 --- a/filament/src/Camera.cpp +++ b/filament/src/Camera.cpp @@ -22,6 +22,7 @@ #include "details/Engine.h" #include +#include #include @@ -80,25 +81,19 @@ void UTILS_NOINLINE FCamera::setProjection(Camera::Projection projection, double bottom, double top, double near, double far) noexcept { - // we silently make sure our preconditions are verified - // this is to avoid potential inconsistent state in the renderer later. - - if (UTILS_UNLIKELY(left == right)) { - left -= 1; - right += 1; - } - - if (UTILS_UNLIKELY(bottom == top)) { - bottom -= 1; - top += 1; - } - - if (UTILS_UNLIKELY(projection == Projection::PERSPECTIVE && near < 1.0 / 1024.0)) { - near = 1.0 / 1024.0; // about 1mm - } - - if (UTILS_UNLIKELY(near == far)) { - far += 1; + // we make sure our preconditions are verified, using default values, + // to avoid inconsistent states in the renderer later. + if (UTILS_UNLIKELY(left == right || + bottom == top || + (projection == Projection::PERSPECTIVE && (near <= 0 || far <= near)) || + (projection == Projection::ORTHO && (near == far)))) { + PANIC_LOG("Camera preconditions not met. Using default projection."); + left = -0.1; + right = 0.1; + bottom = -0.1; + top = 0.1; + near = 0.1; + far = 100.0; } mat4 p;