nannou-org / nannou

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

Introduce ShaderModel. #977

Closed tychedelia closed 2 months ago

tychedelia commented 2 months ago

Introduces the nannou specific trait ShaderModel, as well as a convenient attribute macro #[shader_model] that can be used to generate the bevy boilerplate derives needed for implementing Material.

Although Material is used to drive much of the bevy ecosystem, including it in our public api and examples couples us too tightly to the bevy pbr pipeline. It's also confusing, because while we ask users to implement things from the trait like fragment and vertex shaders, there's a ton of additional features included in this trait that they would not want to touch.

As such, the nannou trait ShaderModel is a simple trait that specifies which shaders to use, as well as adding all the required bounds to make everything work. Users can implement this themselves, but can also use the macro as such:

// This struct defines the data that will be passed to your shader
#[shader_model(fragment = "draw_custom_material.wgsl")]
struct ShaderModel {
    #[uniform(0)]
    color: LinearRgba,
}

Additionally, this will help future extensions, like supporting indirect drawing in compute shaders, where we do not want to depend directly on T: Material but instead T: AsBindGroup.

Other changes: