Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@panxinmiao
Copy link
Contributor

This PR implements a simple ray tracer and tests it on the well-known Cornell Box scene. This is an experimental demonstration of ray tracing with compute shaders in pygfx.

Ray tracing is a rendering technique distinct from rasterization. By simulating the physical behavior of light in a scene, it produces visuals that are closer to real-world lighting, with natural support for soft shadows and global illumination. This makes it particularly well-suited for offline rendering scenarios that demand high visual fidelity, such as film-quality rendering.

Below are the rendering results of the Cornell Box scene at different sample-per-pixel (spp) levels:

1000 spp:
image

10,000 spp:
2025-04-08_175253

100,000 spp:
image

Replacing the small cube in the scene with a transparent glass and applying a mirror-like surface to the front of the big rectangular box, we can get the following rendering result (around 30,000 spp):
image

I think this example serves as an exploratory starting point for implementing ray tracing with Pygfx. Perhaps in the future, we can have a powerful offline renderer using ray tracing technology in Pygfx :)

@panxinmiao panxinmiao requested a review from Korijn as a code owner April 8, 2025 11:08
@Vipitis
Copy link

Vipitis commented Apr 8, 2025

Cool stuff, worth noting that we will eventually get access to hardware raytracing (on supported hardware) in wgpu: gfx-rs/wgpu#6762

@panxinmiao
Copy link
Contributor Author

Cool stuff, worth noting that we will eventually get access to hardware raytracing (on supported hardware) in wgpu: gfx-rs/wgpu#6762

Thank you for the information. I'm also keeping an eye on this :)

Copy link
Member

@almarklein almarklein left a comment

Choose a reason for hiding this comment

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

I had missed that this was ready. Since this is fully self-contained, I'm happy to add this as an example.

@Korijn Korijn enabled auto-merge (squash) June 5, 2025 14:10
@Korijn Korijn merged commit 2844b1e into pygfx:main Jun 5, 2025
13 checks passed
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.

4 participants