Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support infinite far planes #547

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 22 additions & 4 deletions src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl<S: BaseFloat> From<PerspectiveFov<S>> for Matrix4<S> {
persp.near
);

let one: S = cast(1).unwrap();
let two: S = cast(2).unwrap();
let f = Rad::cot(persp.fovy / two);

Expand All @@ -155,12 +156,20 @@ impl<S: BaseFloat> From<PerspectiveFov<S>> for Matrix4<S> {

let c2r0 = S::zero();
let c2r1 = S::zero();
let c2r2 = (persp.far + persp.near) / (persp.near - persp.far);
let c2r2 = if persp.far.is_finite() {
(persp.far + persp.near) / (persp.near - persp.far)
} else {
-one
};
let c2r3 = -S::one();

let c3r0 = S::zero();
let c3r1 = S::zero();
let c3r2 = (two * persp.far * persp.near) / (persp.near - persp.far);
let c3r2 = if persp.far.is_finite() {
(two * persp.far * persp.near) / (persp.near - persp.far)
} else {
-two * persp.near
};
let c3r3 = S::zero();

#[cfg_attr(rustfmt, rustfmt_skip)]
Expand Down Expand Up @@ -206,6 +215,7 @@ impl<S: BaseFloat> From<Perspective<S>> for Matrix4<S> {
persp.far
);

let one: S = cast(1i8).unwrap();
let two: S = cast(2i8).unwrap();

let c0r0 = (two * persp.near) / (persp.right - persp.left);
Expand All @@ -220,12 +230,20 @@ impl<S: BaseFloat> From<Perspective<S>> for Matrix4<S> {

let c2r0 = (persp.right + persp.left) / (persp.right - persp.left);
let c2r1 = (persp.top + persp.bottom) / (persp.top - persp.bottom);
let c2r2 = -(persp.far + persp.near) / (persp.far - persp.near);
let c2r2 = if persp.far.is_finite() {
(persp.far + persp.near) / (persp.near - persp.far)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be negative?

} else {
-one
};
let c2r3 = -S::one();

let c3r0 = S::zero();
let c3r1 = S::zero();
let c3r2 = -(two * persp.far * persp.near) / (persp.far - persp.near);
let c3r2 = if persp.far.is_finite() {
(two * persp.far * persp.near) / (persp.near - persp.far)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be negative?

} else {
-two * persp.near
};
let c3r3 = S::zero();

#[cfg_attr(rustfmt, rustfmt_skip)]
Expand Down