Skip to content

WebGPURenderer: Unable to render with orthographic camera. #20276

@Mugen87

Description

@Mugen87

The WebGPU sandbox uses the following perspective camera setup:

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );

The rendered result seems as expected. However if I switch to an orthographic camera like so...

const frustumSize = 10;
const aspect = window.innerWidth / window.innerHeight;

camera = new THREE.OrthographicCamera( 0.5 * frustumSize * aspect / - 2, 0.5 * frustumSize * aspect / 2, frustumSize / 2, frustumSize / - 2, 0, 10 );

...nothing is rendered anymore.

As far as I understand, this is caused by the fact that WebGPU has different coordinate system definitions than WebGL. So in WebGPU, the z coordinate in NDC space lies in the range [0,1] whereas in WebGL it is [-1,1].

That means the current projection matrices for both perspective and orthographic cameras are not computed correctly in Matrix4 in context of WebGPU. It seems these formulas are correct: https://metashapes.com/blog/opengl-metal-projection-matrix-problem/

@mrdoob I have no idea so far how to hide this complexity from the user. When creating a camera, the projection matrix is computed right away from the parameters. In order to provide a "correct" matrix, the camera would have to know in which context (WebGL, WebGPU) it is going to be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions