Skip to content

Fix voxel rendering with orthographic camera #12629

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

Merged
merged 4 commits into from
May 29, 2025
Merged

Fix voxel rendering with orthographic camera #12629

merged 4 commits into from
May 29, 2025

Conversation

Image for: Conversation
Copy link
Contributor

jjhembd commented May 21, 2025

Description

This PR corrects the calculation of the starting view ray in VoxelFS.glsl to account for orthographic cameras.

In the usual perspective camera, the view rays all originate from the camera position and emanate in a direction that depends on the screen pixel. The camera in this case is perhaps best understood as an eye, with the screen pixels corresponding to different angular directions from a focal point.

In an orthographic camera, all view rays are exactly parallel, with the different pixels corresponding to different ray origins.

Along with the new logic in VoxelFS, code changes include:

  • New uniform cameraDirectionUv in VoxelPrimitive.
  • Removed the (unused, undocumented) viewDirWorld property from the fsInput.voxel struct, to facilitate pulling the ray calculation out into a helper function.

Issue number and link

Image for: Issue number and link

Resolves #11013

Testing plan

Image for: Testing plan

Load the "Voxels" Sandcastle, and use the projection picker to switch between perspective and orthographic cameras. The voxel should render correctly in both projections, with the globe partially visible through the semi-transparent voxels. The orthographic effect may be most obvious with the "Box" examples.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code
Copy link

Thank you for the pull request, @jjhembd!

✅ We can confirm we have a CLA on file for you.

jjhembd marked this pull request as ready for review May 21, 2025 20:52
Copy link
Contributor

ggetz commented May 27, 2025

Thanks @jjhembd! This PR is in a great state. Code here is looking great and the functionality is working exactly as expected. I also doubled checked the voxel picking example in orthographic as well.

Is it possible to add any kind of unit test to verify?

Copy link
Contributor

ggetz commented May 29, 2025

@jjhembd I'm seeing the following error when I run the e2e example:

That seems to happen for any voxel example, even before this PR. I'm unable to duplicate in Sandcastle. I'm thinking it may have to do with chrome headless.

Copy link
Contributor Author

jjhembd commented May 29, 2025

@ggetz, on my machine, this line in playwright.config.js was the issue:

        launchOptions: {
          // this forces chrome to use the gpu for webgl which greatly speeds up tests
          args: ["--use-angle=gl"],
        },

If I change the args to

          args: ["--use-angle=vulkan"],

the screenshots are generated normally.

I got the tip from microsoft/playwright#11627. The same thread said that --use-gl=egl worked on a Mac.

I didn't immediately see a way to setup fallbacks, so the same playwright.config.js could work on all platforms. Maybe @jjspace understands this config better?

Copy link
Contributor

ggetz commented May 29, 2025

Thanks @jjhembd. If everything is working on your machine with e2e, let's move forward. Everything is looking good otherwise, and I was having the same issue here as I was in main.

FWIW, the other tests are all working for me without tweaking the playwright config. It's specifically the voxel examples, including the existing sandcastles, which aren't compiling the shader correctly in headless when running test-e2e.

ggetz added this pull request to the merge queue May 29, 2025
Merged via the queue into main with commit ae07bb0 May 29, 2025
9 checks passed
ggetz deleted the voxel-orthographic branch May 29, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment