diff --git a/bevy_nannou_derive/src/lib.rs b/bevy_nannou_derive/src/lib.rs index 93b8a8546..8fbe7062a 100644 --- a/bevy_nannou_derive/src/lib.rs +++ b/bevy_nannou_derive/src/lib.rs @@ -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 { - ::vertex_shader() - } - - fn fragment_shader() -> ::nannou::prelude::ShaderRef { - ::fragment_shader() - } - } }; TokenStream::from(expanded) diff --git a/bevy_nannou_derive/tests/shader_model_tests.rs b/bevy_nannou_derive/tests/shader_model_tests.rs index 3897e626f..79e0a44d0 100644 --- a/bevy_nannou_derive/tests/shader_model_tests.rs +++ b/bevy_nannou_derive/tests/shader_model_tests.rs @@ -3,58 +3,58 @@ 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!(TestShaderModel::vertex_shader(), ShaderRef::Default)); assert!(matches!( - TestMaterial::fragment_shader(), + 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(_) )); } diff --git a/bevy_nannou_draw/src/draw/background.rs b/bevy_nannou_draw/src/draw/background.rs index c32d0c8a2..812d3f9dd 100644 --- a/bevy_nannou_draw/src/draw/background.rs +++ b/bevy_nannou_draw/src/draw/background.rs @@ -1,4 +1,4 @@ -use bevy::prelude::{Color, Material}; +use bevy::prelude::{Color}; use crate::draw::{Draw, DrawCommand}; use crate::render::ShaderModel; diff --git a/bevy_nannou_draw/src/draw/drawing.rs b/bevy_nannou_draw/src/draw/drawing.rs index 7ccb2ba48..810ada86b 100644 --- a/bevy_nannou_draw/src/draw/drawing.rs +++ b/bevy_nannou_draw/src/draw/drawing.rs @@ -2,7 +2,6 @@ use std::any::TypeId; use std::marker::PhantomData; use bevy::asset::UntypedAssetId; -use bevy::pbr::{ExtendedMaterial, MaterialExtension}; use bevy::prelude::*; use lyon::path::PathEvent; use lyon::tessellation::{FillOptions, LineCap, LineJoin, StrokeOptions}; diff --git a/bevy_nannou_draw/src/draw/indirect.rs b/bevy_nannou_draw/src/draw/indirect.rs index aaeb6c939..2a5e38e14 100644 --- a/bevy_nannou_draw/src/draw/indirect.rs +++ b/bevy_nannou_draw/src/draw/indirect.rs @@ -98,18 +98,18 @@ where #[derive(Component, ExtractComponent, Clone)] pub struct IndirectMesh; -pub struct IndirectMaterialPlugin(PhantomData); +pub struct IndirectShaderModelPlugin(PhantomData); -impl Default for IndirectMaterialPlugin +impl Default for IndirectShaderModelPlugin where SM: Default, { fn default() -> Self { - IndirectMaterialPlugin(PhantomData) + IndirectShaderModelPlugin(PhantomData) } } -impl Plugin for IndirectMaterialPlugin +impl Plugin for IndirectShaderModelPlugin where SM: ShaderModel, SM::Data: PartialEq + Eq + Hash + Clone, @@ -117,17 +117,17 @@ where fn build(&self, app: &mut App) { app .sub_app_mut(RenderApp) - .add_render_command::>() + .add_render_command::>() .add_systems( Render, - queue_shader_model::, DrawIndirectMaterial> + queue_shader_model::, DrawIndirectShaderModel> .after(prepare_assets::>) .in_set(RenderSet::QueueMeshes), ); } } -type DrawIndirectMaterial = ( +type DrawIndirectShaderModel = ( SetItemPipeline, SetMeshViewBindGroup<0>, SetMeshBindGroup<1>, diff --git a/bevy_nannou_draw/src/draw/instanced.rs b/bevy_nannou_draw/src/draw/instanced.rs index f8425f608..216da60f3 100644 --- a/bevy_nannou_draw/src/draw/instanced.rs +++ b/bevy_nannou_draw/src/draw/instanced.rs @@ -8,7 +8,6 @@ use bevy::{ core_pipeline::core_3d::Transparent3d, ecs::system::{lifetimeless::*, SystemParamItem}, pbr::{ - MaterialPipeline, MaterialPipelineKey, MeshPipeline, MeshPipelineKey, PreparedMaterial, RenderMeshInstances, SetMeshBindGroup, SetMeshViewBindGroup, }, prelude::*, @@ -103,35 +102,35 @@ pub struct InstancedMesh; #[derive(Component, ExtractComponent, Clone)] pub struct InstanceRange(pub Range); -pub struct InstancedMaterialPlugin(PhantomData); +pub struct InstancedShaderModelPlugin(PhantomData); -impl Default for InstancedMaterialPlugin +impl Default for InstancedShaderModelPlugin where SM: Default, { fn default() -> Self { - InstancedMaterialPlugin(PhantomData) + InstancedShaderModelPlugin(PhantomData) } } -impl Plugin for InstancedMaterialPlugin +impl Plugin for InstancedShaderModelPlugin where SM: ShaderModel, SM::Data: PartialEq + Eq + Hash + Clone, { fn build(&self, app: &mut App) { app.sub_app_mut(RenderApp) - .add_render_command::>() + .add_render_command::>() .add_systems( Render, - queue_shader_model::, DrawInstancedMaterial> + queue_shader_model::, DrawInstancedShaderModel> .after(prepare_assets::>) .in_set(RenderSet::QueueMeshes), ); } } -type DrawInstancedMaterial = ( +type DrawInstancedShaderModel = ( SetItemPipeline, SetMeshViewBindGroup<0>, SetMeshBindGroup<1>, diff --git a/bevy_nannou_draw/src/render.rs b/bevy_nannou_draw/src/render.rs index 0c4edd0a1..c0170dd18 100644 --- a/bevy_nannou_draw/src/render.rs +++ b/bevy_nannou_draw/src/render.rs @@ -1,7 +1,7 @@ use crate::{ draw::{ - indirect::{IndirectMaterialPlugin, IndirectMesh}, - instanced::{InstanceRange, InstancedMaterialPlugin, InstancedMesh}, + indirect::{IndirectShaderModelPlugin, IndirectMesh}, + instanced::{InstanceRange, InstancedShaderModelPlugin, InstancedMesh}, mesh::MeshExt, render::{RenderContext, RenderPrimitive}, DrawCommand, DrawContext, @@ -16,10 +16,9 @@ use bevy::{ system::{lifetimeless::SRes, SystemParamItem}, }, pbr::{ - DefaultOpaqueRendererMethod, DrawMesh, ExtendedMaterial, MaterialBindGroupId, - MaterialExtension, MaterialExtensionKey, MaterialExtensionPipeline, MaterialPipeline, - MaterialProperties, MeshPipeline, MeshPipelineKey, OpaqueRendererMethod, PreparedMaterial, - RenderMeshInstances, SetMeshBindGroup, SetMeshViewBindGroup, StandardMaterial, + DefaultOpaqueRendererMethod, DrawMesh, + MeshPipeline, MeshPipelineKey, OpaqueRendererMethod, + RenderMeshInstances, SetMeshBindGroup, SetMeshViewBindGroup, }, prelude::{TypePath, *}, render::{ @@ -134,8 +133,8 @@ where .add_plugins(( ExtractInstancesPlugin::>::extract_visible(), RenderAssetPlugin::>::default(), - IndirectMaterialPlugin::::default(), - InstancedMaterialPlugin::::default(), + IndirectShaderModelPlugin::::default(), + InstancedShaderModelPlugin::::default(), )) .add_systems(PostUpdate, update_shader_model::.after(update_draw_mesh)); @@ -249,7 +248,7 @@ bitflags::bitflags! { } #[derive(Asset, AsBindGroup, TypePath, Debug, Clone, Default)] -#[bind_group_data(NannouMaterialKey)] +#[bind_group_data(NannouBindGroupData)] #[uniform(0, NannouShaderModelUniform)] pub struct NannouShaderModel { pub color: Color, @@ -284,12 +283,12 @@ impl AsBindGroupShaderType for NannouShaderModel { } #[derive(Eq, PartialEq, Hash, Clone)] -pub struct NannouMaterialKey { +pub struct NannouBindGroupData { polygon_mode: PolygonMode, blend: Option, } -impl From<&NannouShaderModel> for NannouMaterialKey { +impl From<&NannouShaderModel> for NannouBindGroupData { fn from(shader_model: &NannouShaderModel) -> Self { Self { polygon_mode: shader_model.polygon_mode, diff --git a/nannou/src/app.rs b/nannou/src/app.rs index 4ed5794e4..9233d9b06 100644 --- a/nannou/src/app.rs +++ b/nannou/src/app.rs @@ -362,14 +362,6 @@ where self } - /// Load a fragment shader asset from the given path for use with the nannou `Draw` API. - #[cfg(feature = "nightly")] - pub fn init_fragment_shader(mut self) -> Self { - self.app - .add_plugins(NannouShaderModelPlugin::>::default()); - self - } - pub fn compute(mut self, compute_fn: ComputeUpdateFn) -> Self { let render_app = self.app.sub_app_mut(bevy::render::RenderApp); render_app.insert_resource(ComputeShaderHandle(CM::shader()));