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

Open
wants to merge 9 commits into
base: bevy-refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions bevy_nannou_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ pub fn shader_model(attr: TokenStream, item: TokenStream) -> TokenStream {
#fragment_shader_impl
}
}

impl #impl_generics ::nannou::prelude::Material for #name #ty_generics #where_clause {
fn vertex_shader() -> ::nannou::prelude::ShaderRef {
<Self as ::nannou::prelude::render::ShaderModel>::vertex_shader()
}

fn fragment_shader() -> ::nannou::prelude::ShaderRef {
<Self as ::nannou::prelude::render::ShaderModel>::fragment_shader()
}
}
};

TokenStream::from(expanded)
Expand Down
27 changes: 15 additions & 12 deletions bevy_nannou_derive/tests/shader_model_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,61 @@ use bevy_nannou_derive::shader_model;
use bevy_nannou_draw::render::ShaderModel;

#[shader_model]
struct TestMaterial {}
struct TestShaderModel {}

#[test]
fn test_default_shaders() {
assert!(matches!(TestMaterial::vertex_shader(), ShaderRef::Default));
assert!(matches!(
TestMaterial::fragment_shader(),
TestShaderModel::vertex_shader(),
ShaderRef::Default
));
assert!(matches!(
TestShaderModel::fragment_shader(),
ShaderRef::Default
));
}

#[shader_model(vertex = "custom_vertex.wgsl")]
struct TestVertexMaterial {}
struct TestVertexShaderModel {}

#[test]
fn test_custom_vertex_shader() {
assert!(matches!(
TestVertexMaterial::vertex_shader(),
TestVertexShaderModel::vertex_shader(),
ShaderRef::Path(_)
));
assert!(matches!(
TestVertexMaterial::fragment_shader(),
TestVertexShaderModel::fragment_shader(),
ShaderRef::Default
));
}

#[shader_model(fragment = "custom_fragment.wgsl")]
struct TestFragmentMaterial {}
struct TestFragmentShaderModel {}

#[test]
fn test_custom_fragment_shader() {
assert!(matches!(
TestFragmentMaterial::vertex_shader(),
TestFragmentShaderModel::vertex_shader(),
ShaderRef::Default
));
assert!(matches!(
TestFragmentMaterial::fragment_shader(),
TestFragmentShaderModel::fragment_shader(),
ShaderRef::Path(_)
));
}

#[shader_model(vertex = "custom_vertex.wgsl", fragment = "custom_fragment.wgsl")]
struct TestBothMaterial {}
struct TestBothShaderModel {}

#[test]
fn test_both_custom_shaders() {
assert!(matches!(
TestBothMaterial::vertex_shader(),
TestBothShaderModel::vertex_shader(),
ShaderRef::Path(_)
));
assert!(matches!(
TestBothMaterial::fragment_shader(),
TestBothShaderModel::fragment_shader(),
ShaderRef::Path(_)
));
}
1 change: 1 addition & 0 deletions bevy_nannou_draw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ num-traits = "0.2"
bytemuck = "1.15.0"
rayon = { workspace = true }
uuid = "1.8"
bitflags = "2.6.0"

[features]
nightly = []
17 changes: 9 additions & 8 deletions bevy_nannou_draw/src/draw/background.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use bevy::prelude::{Color, Material};
use bevy::prelude::Color;

use crate::draw::{Draw, DrawCommand};
use crate::render::ShaderModel;

/// A type used to update the background colour.
pub struct Background<'a, M>
pub struct Background<'a, SM>
where
M: Material + Default,
SM: ShaderModel + Default,
{
draw: &'a Draw<M>,
draw: &'a Draw<SM>,
}

/// Begin coloring the background.
pub fn new<M>(draw: &Draw<M>) -> Background<M>
pub fn new<SM>(draw: &Draw<SM>) -> Background<SM>
where
M: Material + Default,
SM: ShaderModel + Default,
{
Background { draw }
}

impl<'a, M> Background<'a, M>
impl<'a, SM> Background<'a, SM>
where
M: Material + Default,
SM: ShaderModel + Default,
{
/// Clear the background with the given color.
///
Expand Down
Loading
Loading