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

Projection matrices differ between WebGL and WebGPU #894

Open
magcius opened this issue Oct 25, 2019 · 4 comments
Open

Projection matrices differ between WebGL and WebGPU #894

magcius opened this issue Oct 25, 2019 · 4 comments
Milestone

Comments

@magcius
Copy link

magcius commented Oct 25, 2019

See gpuweb/gpuweb#416 for context.

Currently, the spec does not define much about how the projection matrix is created, nor which clip space it is mapping to. Note that two different clip spaces are in common use: OpenGL (and thus WebGL) specify a clip space with a Z range of -1...1. Most other graphics APIs, like Direct3D, Metal, and Vulkan (and WebGPU) specify a clip space with a Z range of 0...1.

As such, projection matrices are dependent on the clip space they need to map to. This means that we cannot simply use a single projection matrix between WebGL and WebGPU.

Two solutions:

  1. WebXR documentation should provide additional guidance for handling this clip space transform . See e.g. https://github.com/magcius/noclip.website/blob/master/src/gfx/helpers/ProjectionHelpers.ts for one such method.
  2. WebXR should allow configuring the clip space that projection matrices are mapping to, either the -1...1 Z range, or the 0...1 Z range.

Regardless, the specification should mention which clip space the current projection matrices are currently mapping to.

@toji
Copy link
Member

toji commented Oct 25, 2019

Thanks for the heads up on this issue!

Given that we don't support WebGPU-based layers (yet) resolving how the projections matrices will work with them isn't of immediate concern. We should definitely strive to be more precise about how the projection matrices are derived, though. (Due to hardware compat issue we can't give a precise algorithm for constructing them, but we can at least indicate the Z range.)

When we do get to the point of integrating with WebGPU either of the options you mention sound reasonable. My preference would be to make the Z range configurable (maybe via XRRenderState) but documenting the transform needed is valuable too, especially since it's so simple.

@toji
Copy link
Member

toji commented Oct 25, 2019

Also, FWIW, we do talk about the Z range indirectly in the description of the ignoreDepthValues attribute.

Depth values stored in the buffer are expected to be between 0.0 and 1.0, with 0.0 representing the distance of depthNear and 1.0 representing the distance of depthFar, with intermediate values interpolated linearly. This is the default behavior of WebGL.

We'd obviously want something much more clearly linked to the projection matrix computation in the spec, though.

@magcius
Copy link
Author

magcius commented Oct 25, 2019

That quote appears to be talking about what's configured by glDepthRange, which is talking about the output range in viewport space. Viewport space is the same for both WebGL and WebGPU. What's different is the transform from clip space to viewport space, or, in other words, the definition of clip space. This article has some of the details of what changed between the two specs.

It's confusing given that there are so many options and spaces, though.

@toji
Copy link
Member

toji commented Oct 25, 2019

Ah, you are correct.

It's confusing given that there are so many options and spaces, though.

Here at the Immersive Web Working Group, juggling confusing spaces is our specialty. 😜

@magcius magcius changed the title Projection matrices differences between WebGL and WebGPU Projection matrices differ between WebGL and WebGPU Oct 26, 2019
@toji toji added this to the Future milestone Oct 28, 2019
@toji toji added the TPAC label Oct 12, 2021
@Yonet Yonet removed the TPAC label Jun 7, 2022
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

No branches or pull requests

3 participants