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
This commit is contained in:
committed by
Romain Guy
parent
26d0aa76f8
commit
bd8c3e9181
@@ -22,6 +22,7 @@
|
||||
#include "details/Engine.h"
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Panic.h>
|
||||
|
||||
#include <math/scalar.h>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user