Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions devices/gl/src/VisGLCameraOrthographicObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "math_util.h"
#include <math.h>

#include <cfloat>
#include <cstdlib>
#include <cstring>

Expand All @@ -59,15 +60,48 @@ void Object<CameraOrthographic>::commit()
current.height.get(ANARI_FLOAT32, &height);

normalize3(direction);

// clip distances, same rule as VisRTX : unset means no clipping, invalid
// values are ignored
nearClip = 0.0f;
farClip = FLT_MAX;
float nearValue = nearClip;
float farValue = farClip;
const bool hasNear = current.near.get(ANARI_FLOAT32, &nearValue);
const bool hasFar = current.far.get(ANARI_FLOAT32, &farValue);
if (hasNear || hasFar) {
if ((hasNear && !(nearValue >= 0.0f)) || !(nearValue < farValue)) {
anariReportStatus(device,
handle,
ANARI_CAMERA,
ANARI_SEVERITY_WARNING,
ANARI_STATUS_INVALID_ARGUMENT,
"camera 'near' (%f) and 'far' (%f) must satisfy 0 <= near < far; "
"ignoring both",
nearValue,
farValue);
} else {
nearClip = nearValue;
farClip = farValue;
}
}
}

void Object<CameraOrthographic>::updateAt(size_t index, float *bounds) const
{
float range[2];
projectBoundingBox(range, bounds, position, direction);
float depth = range[1]-range[0];
float far = range[1] + 0.001f*depth;
float near = fast_maxf(0.0f, range[0] - 0.001f*depth);
// clip range enclosing the world, narrowed to the camera near and far when
// they are set
float far = fast_minf(farClip, range[1] + 0.001f * depth);
float near = fast_maxf(nearClip, range[0] - 0.001f * depth);
if (!(far > near) && (nearClip > 0.0f || farClip < FLT_MAX)) {
// the world is outside the camera clip range, nothing is visible : use that
// range itself
near = nearClip;
far = farClip < FLT_MAX ? farClip : near + 1.0f;
}

float width = height * aspect;

Expand Down
3 changes: 3 additions & 0 deletions devices/gl/src/VisGLCameraOrthographicObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class Object<CameraOrthographic>
float region[4];
float aspect;
float height;
// "near" and "far" parameters, 0 and FLT_MAX when not set
float nearClip;
float farClip;

void calculateMatrices(float near, float far);

Expand Down
37 changes: 35 additions & 2 deletions devices/gl/src/VisGLCameraPerspectiveObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "math_util.h"
#include <math.h>

#include <cfloat>
#include <cstdlib>
#include <cstring>

Expand All @@ -59,14 +60,46 @@ void Object<CameraPerspective>::commit()
current.aspect.get(ANARI_FLOAT32, &aspect);

normalize3(direction);

// clip distances, same rule as VisRTX : unset means no clipping, invalid values are ignored
nearClip = 0.0f;
farClip = FLT_MAX;
float nearValue = nearClip;
float farValue = farClip;
const bool hasNear = current.near.get(ANARI_FLOAT32, &nearValue);
const bool hasFar = current.far.get(ANARI_FLOAT32, &farValue);
if (hasNear || hasFar) {
if ((hasNear && !(nearValue > 0.0f)) || !(nearValue < farValue)) {
anariReportStatus(device,
handle,
ANARI_CAMERA,
ANARI_SEVERITY_WARNING,
ANARI_STATUS_INVALID_ARGUMENT,
"camera 'near' (%f) and 'far' (%f) must satisfy 0 < near < far; ignoring both",
nearValue,
farValue);
} else {
nearClip = nearValue;
farClip = farValue;
}
}
}

void Object<CameraPerspective>::updateAt(size_t index, float *bounds) const
{
float range[2];
projectBoundingBox(range, bounds, position, direction);
float far = range[1] * 1.0001f;
float near = fast_maxf(far * 1.0e-3, range[0] * 0.9999f);
// clip range enclosing the world, narrowed to the camera near and far when they are set.
// Without a near distance, the near plane is pushed to far/1000 to keep the depth precision :
// it clips the foreground when the world is much larger than the view (a globe seen from low altitude).
float far = fast_minf(farClip, range[1] * 1.0001f);
float near = nearClip > 0.0f ? fast_maxf(nearClip, range[0] * 0.9999f)
: fast_maxf(far * 1.0e-3f, range[0] * 0.9999f);
if (!(far > near) && (nearClip > 0.0f || farClip < FLT_MAX)) {
// the world is outside the camera clip range, nothing is visible : use that range itself
near = nearClip > 0.0f ? nearClip : farClip * 1.0e-3f;
far = farClip < FLT_MAX ? farClip : 2.0f * near;
}

float height = near * tanf(fovy * 0.5f);
float width = height * aspect;
Expand Down
3 changes: 3 additions & 0 deletions devices/gl/src/VisGLCameraPerspectiveObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Object<CameraPerspective>
float region[4];
float fovy;
float aspect;
// "near" and "far" parameters, 0 and FLT_MAX when not set
float nearClip;
float farClip;

void calculateMatrices(float near, float far);

Expand Down
Loading