nannou-org / nannou

A Creative Coding Framework for Rust.
https://nannou.cc/
6.04k stars 305 forks source link

Mid-Level Rendering w/ `ShaderModel` #980

Closed tychedelia closed 6 days ago

tychedelia commented 1 month ago

ShaderModel based rendering

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

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:

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.