question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebGPURenderer: Unable to render with orthographic camera.

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Kangzcommented, Sep 7, 2020

Premultiplying the matrix would work.

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’s correct. When you’ll do render-to-texture there will be another difference that means that you’ll need to flip-Y to keep the same rendering results as the WebGL path. (for rendering directly to the canvas there are two flips compared to WebGL that cancel out).

1reaction
WestLangleycommented, Sep 6, 2020

Maybe just premultiply the projection matrix by the appropriate transform matrix, as described in the link above, if webGPU is enabled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shape Geometry with Orthographic camera in threejs not ...
I'm trying to display shapes in three.js. Unfortunately nothing is displayed and I can't really figure out what I am missing.
Read more >
Bug: Orthographic camera is rendering Default layer content
I think I've found a Lens bug that manifests itself only on-device (not in Lens Studio): the orthographic camera, which is set to...
Read more >
Orthographic Camera Render broken 4.0.2
Chaging the Camera to orthographic turns the preview window white and play the game doesnt show and game art. just a checkerboard background....
Read more >
Deferred lightning impossible on Orthographic Camera?
Because orthographic is just a different projection amtrix, so it shouldn't mess up neither with shadow map nor deferred rendering, no?
Read more >
Orthographic Cam with HDRI in background
There is this airbus a400m plane scene, which I'm trying to film it like mission impossible fallout. The view of the plane is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found