Skip to content
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

Mid-Level Rendering w/ ShaderModel #980

Merged
merged 9 commits into from
Nov 16, 2024

Conversation

tychedelia
Copy link
Collaborator

ShaderModel based rendering

The fourth major refactor of how we're approaching rendering with bevy. To recap:

  • First, we simply ran nannou's existing pipeline in a bevy render node. This represented minimal changes but was barely integrated with bevy.
  • Second, we attempted to use bevy's mid level render APIs in order to use Bevy's meshes, but manage our own shader lifecycle.
  • Third (and the current state of bevy-refactor, we used bevy mesh-material API to avoid needing much custom rendering code.

While the material approach was great, it introduced a few problems, namely that it leaked a lot of details of the bevy pbr pipeline into nannou. While this was cool in some cases (emissives!), it also was potentially confusing to users. Additionally, it prevented us from having a simple way to implement additional render commands, i.e. explicit instancing or indirect draw, as bevy's material system doesn't support these.

This PR returns to a solution that is largely based around the mid-level APIs. The intention here is to decouple nannou from bevy's material system, while still using a similar kind of pattern.

As such, we want to lean on the ShaderModel trait, and use that as the core "material" for our rendering, and avoid exposing users to any details about bevy's pbr shaders.

Implementation

Much of the new rendering code is similar to code found in bevy's material pipeline, with a few primary differences:

  • When queueing materials, we are generic over the bevy "draw function", which allows us to implement different draw strategies for things like instancing and indirect draw. These are triggered by spawning a mesh with a different market component, e.g. InstancedMesh, as managed by our draw render commands.
  • Nannou meshes now only run in the transparent phase, which forces them to be sorted according to their draw order.
  • We are using a default shader that is similar to nannou's roots, but takes a lot of inspiration from the bevy 2d shader.
  • Nannous "default" shader model is now just a simple model that provides a base color and texture field.

How to review

The bulk of the changes are located in bevy_nannou_draw, but likely require familiarity with bevy's mid-level. Pay attention to the ways in which indirect and instanced drawing are implemented now.

@tychedelia tychedelia merged commit ac306b4 into nannou-org:bevy-refactor Nov 16, 2024
14 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.

1 participant