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

Add mat4.perspectiveZO, mat4.orthoZO for WebGPU #413

Merged
merged 3 commits into from
Jan 13, 2021
Merged

Conversation

toji
Copy link
Owner

@toji toji commented Jan 12, 2021

Putting this up as a pull request in case there's any feedback.

The upcoming WebGPU API uses Normalized Device Coordinates with a [0, 1] Z range, which differs from WebGL's [-1, 1] range. To get the best precision out of WebGPU pages will need to create perspective matrices a bit differently.

This change introduces the mat4.perspectiveZO(), which is identical in functionality to the previous mat4.perspective() method except it maps to the [0, -1] range. For consistency the previous method has been renamed to mat4.perspectiveNO() with an alias of mat4.perspective(). This could later allow users to configure the library to use one projection method or the other by default. Naming convention borrowed from the native glm library because I can't think of anything better that doesn't end up with 50 character long method names.

@toji toji requested a review from stefnotch January 12, 2021 01:12
Copy link

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

Is something similar needed for ortho() and perspectiveFromFieldOfView()?

@toji
Copy link
Owner Author

toji commented Jan 12, 2021

perspectiveFieldOfView is planned to be deprecated and removed. You're right that ortho will need the same thing, though.

@toji
Copy link
Owner Author

toji commented Jan 12, 2021

Added the ortho version.

@toji toji changed the title Add mat4.perspectiveZO, for WebGPU Add mat4.perspectiveZO, mat4.orthoZO for WebGPU Jan 12, 2021
Copy link

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

Should I review the math in detail? Otherwise, LGTM

src/mat4.js Outdated Show resolved Hide resolved
@toji toji merged commit 21b745f into master Jan 13, 2021
@toji toji deleted the webgpu-projection branch January 13, 2021 04:23
@magcius
Copy link

magcius commented Mar 1, 2021

You missed frustumZO, and I thought we were going to take a flag approach as detailed in #369 (comment) so we could also handle reverse depth at the same time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants