Skip to content

Initial raytraced lighting progress (bevy_solari)#19058

Merged
cart merged 93 commits intobevyengine:mainfrom
JMS55:solari6
Jun 12, 2025
Merged

Initial raytraced lighting progress (bevy_solari)#19058
cart merged 93 commits intobevyengine:mainfrom
JMS55:solari6

Conversation

@JMS55
Copy link
Contributor

@JMS55 JMS55 commented May 4, 2025

Bevy Solari

Preface

  • See release notes.
  • Please talk to me in #rendering-dev on discord or open a github discussion if you have questions about the long term plan, and keep discussion in this PR limited to the contents of the PR :)

Connections

This PR

After nearly two years, I've revived the raytraced lighting effort I first started in #10000.

Unlike that PR, which has realtime techniques, I've limited this PR to:

  • RaytracingScenePlugin - BLAS and TLAS building, geometry and texture binding, sampling functions.
  • PathtracingPlugin - A non-realtime path tracer intended to serve as a testbed and reference.

What's implemented?

image

  • BLAS building on mesh load
  • Emissive lights
  • Directional lights with soft shadows
  • Diffuse (lambert, not Bevy's diffuse BRDF) and emissive materials
  • A reference path tracer with:
    • Antialiasing
    • Direct light sampling (next event estimation) with 0/1 MIS weights
    • Importance-sampled BRDF bounces
    • Russian roulette

What's not implemented?

  • Anything realtime, including a real-time denoiser
  • Integration with Bevy's rasterized gbuffer
  • Specular materials
  • Non-opaque geometry
  • Any sort of CPU or GPU optimizations
    • BLAS compaction, proper bindless, and further RT APIs are things that we need wgpu to add
  • PointLights, SpotLights, or skyboxes / environment lighting
  • Support for materials other than StandardMaterial (and only a subset of properties are supported)
  • Skinned/morphed or otherwise animating/deformed meshes
  • Mipmaps
  • Adaptive self-intersection ray bias
  • A good way for developers to detect whether the user's GPU supports RT or not, and fallback to baked lighting.
  • Documentation and actual finalized APIs (literally everything is subject to change)

End-user Usage

  • Have a GPU that supports RT with inline ray queries
  • Add SolariPlugin to your app
  • Ensure any Mesh asset you want to use for raytracing has enable_raytracing: true (defaults to true), and that it uses the standard uncompressed position/normal/uv_0/tangent vertex attribute set, triangle list topology, and 32-bit indices.
    • If you don't want to build a BLAS and use the mesh for RT, set enable_raytracing to false.
  • Add the RaytracingMesh3d component to your entity (separate from Mesh3d or MeshletMesh3d).

Testing

  • Did you test these changes? If so, how?
    • Ran the solari example.
  • Are there any parts that need more testing?
    • Other test scenes probably. Normal mapping would be good to test.
  • How can other people (reviewers) test your changes? Is there anything specific they need to know?
    • See the solari.rs example for how to setup raytracing.
  • If relevant, what platforms did you test these changes on, and are there any important ones you can't test?
    • Windows 11, NVIDIA RTX 3080.

Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

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

This is exciting! The initial simplicity is appreciated.

if let Ok(mesh) = mesh.get(descendant) {
commands
.entity(descendant)
.insert(RaytracingMesh3d(mesh.0.clone()))
Copy link
Member

Choose a reason for hiding this comment

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

This seems fine for demo purposes. I'd prefer it if ultimately raytracing could reuse the existing Mesh3d by default (as the component-swapping UX isn't great). Solvable problem / Im pretty sure I understand why you went for this in the short term (removing Mesh3d opts out of the normal rendering flow).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you read the docs on RaytracingMesh3d? It was an intentional choice to allow using lower-resolution proxy meshes for RT (and to allow using proxy meshes for MeshletMeshes).

We could make reusing Mesh3d the default I suppose, and RaytracingMesh3d opt-in, but I'm not sure how I feel about that. I'll give it some more thought, it's not a bad idea.

Copy link
Member

Choose a reason for hiding this comment

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

Yup! An opt-in override component makes way more sense to me from a UX perspective.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also yes removing Mesh3d here for the pathtracer is to opt-out of the normal rendering path.

The realtime stuff won't do that.

@JMS55
Copy link
Contributor Author

JMS55 commented Jun 11, 2025

The initial simplicity is appreciated.

It's going to get so much more complicated soon :)

Still simpler than virtual geometry though, by a long shot.

@JMS55 JMS55 requested a review from cart June 11, 2025 23:43
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged S-Waiting-on-SME This is currently waiting for an SME to resolve something controversial labels Jun 12, 2025
@cart cart added this pull request to the merge queue Jun 12, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 12, 2025
@cart cart enabled auto-merge June 12, 2025 21:09
@cart cart added this pull request to the merge queue Jun 12, 2025
Merged via the queue into bevyengine:main with commit bab31e3 Jun 12, 2025
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible D-Complex Quite challenging from either a design or technical perspective. Ask for help! M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

10 participants