From ebc74c8b006ac1c302a03dba4dcb969f70e263a7 Mon Sep 17 00:00:00 2001 From: Charlotte McElwain Date: Thu, 26 Sep 2024 22:20:42 -0700 Subject: [PATCH] Cleanup names. --- bevy_nannou_draw/src/draw/drawing.rs | 34 +++++----- bevy_nannou_draw/src/draw/indirect.rs | 4 +- bevy_nannou_draw/src/draw/instanced.rs | 4 +- bevy_nannou_draw/src/draw/mod.rs | 40 +++++------ bevy_nannou_draw/src/render.rs | 50 +++++++------- bevy_nannou_isf/src/asset.rs | 2 +- examples/Cargo.toml | 14 ++-- ...ial.wgsl => draw_custom_shader_model.wgsl} | 6 +- ...aterial.wgsl => particle_mouse_model.wgsl} | 0 ..._material.wgsl => particle_sdf_model.wgsl} | 0 ...w_video_material.wgsl => video_model.wgsl} | 0 examples/compute/particle_mouse.rs | 8 +-- examples/compute/particle_sdf.rs | 8 +-- ...aterial.rs => draw_custom_shader_model.rs} | 8 +-- examples/draw/draw_material.rs | 66 ------------------- examples/draw/draw_material_bloom.rs | 58 ---------------- ...ideo_material.rs => video_shader_model.rs} | 6 +- 17 files changed, 89 insertions(+), 219 deletions(-) rename examples/assets/{draw_custom_material.wgsl => draw_custom_shader_model.wgsl} (54%) rename examples/assets/shaders/{particle_mouse_material.wgsl => particle_mouse_model.wgsl} (100%) rename examples/assets/shaders/{particle_sdf_material.wgsl => particle_sdf_model.wgsl} (100%) rename examples/assets/{draw_video_material.wgsl => video_model.wgsl} (100%) rename examples/draw/{draw_custom_material.rs => draw_custom_shader_model.rs} (71%) delete mode 100644 examples/draw/draw_material.rs delete mode 100644 examples/draw/draw_material_bloom.rs rename examples/video/{video_material.rs => video_shader_model.rs} (84%) diff --git a/bevy_nannou_draw/src/draw/drawing.rs b/bevy_nannou_draw/src/draw/drawing.rs index bdb1ea8ff..7ccb2ba48 100644 --- a/bevy_nannou_draw/src/draw/drawing.rs +++ b/bevy_nannou_draw/src/draw/drawing.rs @@ -114,16 +114,16 @@ where Err(err) => eprintln!("drawing failed to borrow state and finish: {}", err), Ok(mut state) => { match &self.draw { - // If we are "Owned", that means we mutated our material and so need to + // If we are "Owned", that means we mutated our shader model and so need to // spawn a new entity just for this primitive. DrawRef::Owned(draw) => { let id = draw.shader_model.clone(); - let material_cmd = state + let shader_model_cmd = state .draw_commands .get_mut(self.shader_model_index) - .expect("Expected a valid material index"); - if let None = material_cmd { - *material_cmd = Some(DrawCommand::ShaderModel(id)); + .expect("Expected a valid shdaer model index"); + if let None = shader_model_cmd { + *shader_model_cmd = Some(DrawCommand::ShaderModel(id)); } } DrawRef::Borrowed(_) => (), @@ -140,7 +140,7 @@ where self.finish_inner() } - // Map the the parent's material to a new material type, taking ownership over the + // Map the the parent's shader model to a new shader model type, taking ownership over the // draw instance clone. pub fn map_shader_model(mut self, map: F) -> Drawing<'a, T, SM> where @@ -151,12 +151,12 @@ where let Drawing { ref draw, index, - shader_model_index: material_index, + shader_model_index: shader_model_index, .. } = self; let state = draw.state.clone(); - let material = state.read().unwrap().shader_models[&self.draw.shader_model] + let shader_model = state.read().unwrap().shader_models[&self.draw.shader_model] .downcast_ref::() .unwrap() .clone(); @@ -166,10 +166,10 @@ where uuid: Uuid::new_v4(), }; - let material = map(material.clone()); + let shader_model = map(shader_model.clone()); let mut state = state.write().unwrap(); - state.shader_models.insert(new_id.clone(), Box::new(material)); - // Mark the last material as the new material so that further drawings use the same material + state.shader_models.insert(new_id.clone(), Box::new(shader_model)); + // Mark the last shader model as the new model so that further drawings use the same model // as the parent draw ref. state.last_shader_model = Some(new_id.clone()); @@ -178,13 +178,13 @@ where context: draw.context.clone(), shader_model: new_id.clone(), window: draw.window, - _material: Default::default(), + _shader_model: Default::default(), }; Drawing { draw: DrawRef::Owned(draw), index, - shader_model_index: material_index, + shader_model_index, finish_on_drop: true, _ty: PhantomData, } @@ -208,13 +208,13 @@ where let Drawing { ref draw, index, - shader_model_index: material_index, + shader_model_index, .. } = self; Drawing { draw: draw.clone(), index, - shader_model_index: material_index, + shader_model_index, finish_on_drop: true, _ty: PhantomData, } @@ -242,13 +242,13 @@ where let Drawing { ref draw, index, - shader_model_index: material_index, + shader_model_index, .. } = self; Drawing { draw: draw.clone(), index, - shader_model_index: material_index, + shader_model_index, finish_on_drop: true, _ty: PhantomData, } diff --git a/bevy_nannou_draw/src/draw/indirect.rs b/bevy_nannou_draw/src/draw/indirect.rs index eaa987a55..aaeb6c939 100644 --- a/bevy_nannou_draw/src/draw/indirect.rs +++ b/bevy_nannou_draw/src/draw/indirect.rs @@ -160,10 +160,10 @@ impl RenderCommand

let Some(asset_id) = instances.get(&item.entity()) else { return RenderCommandResult::Skip; }; - let Some(material) = models.get(*asset_id) else { + let Some(model) = models.get(*asset_id) else { return RenderCommandResult::Skip; }; - pass.set_bind_group(I, &material.bind_group, &[]); + pass.set_bind_group(I, &model.bind_group, &[]); RenderCommandResult::Success } } diff --git a/bevy_nannou_draw/src/draw/instanced.rs b/bevy_nannou_draw/src/draw/instanced.rs index bd68295ed..f8425f608 100644 --- a/bevy_nannou_draw/src/draw/instanced.rs +++ b/bevy_nannou_draw/src/draw/instanced.rs @@ -164,10 +164,10 @@ impl RenderCommand

let Some(asset_id) = instances.get(&item.entity()) else { return RenderCommandResult::Skip; }; - let Some(material) = models.get(*asset_id) else { + let Some(shader_model) = models.get(*asset_id) else { return RenderCommandResult::Skip; }; - pass.set_bind_group(I, &material.bind_group, &[]); + pass.set_bind_group(I, &shader_model.bind_group, &[]); RenderCommandResult::Success } } diff --git a/bevy_nannou_draw/src/draw/mod.rs b/bevy_nannou_draw/src/draw/mod.rs index 481b49905..2d42e63b2 100644 --- a/bevy_nannou_draw/src/draw/mod.rs +++ b/bevy_nannou_draw/src/draw/mod.rs @@ -65,12 +65,12 @@ where pub state: Arc>, /// The current context of this [Draw] instance. context: DrawContext, - /// The current material of this [Draw] instance. + /// The current type erased shader model of this [Draw] instance. shader_model: UntypedAssetId, /// The window to which this [Draw] instance is associated. pub(crate) window: Entity, - /// The type of material used by this [Draw] instance. - _material: PhantomData, + /// The type of shader model used by this [Draw] instance. + _shader_model: PhantomData, } /// A reference to a [Draw] instance that is either borrowed or owned. @@ -112,7 +112,7 @@ impl Default for DrawContext { } } -/// Commands generated by drawing that instruct how to create the meshes and materials that will be +/// Commands generated by drawing that instruct how to create the meshes and shader model that will be /// rendered. #[derive(Clone, Debug)] pub enum DrawCommand { @@ -138,7 +138,7 @@ pub enum DrawCommand { /// drawing stuff. In order to be friendlier to new users, we want to avoid requiring them to think /// about mutability and instead focus on creativity. Rust-lang nuances can come later. pub struct State { - /// The last material used to draw an image, used to detect changes and emit commands for them. + /// The last shader model used to draw an image, used to detect changes and emit commands for them. last_shader_model: Option, /// The last context used to draw an image, used to detect changes and emit commands for them. last_draw_context: Option, @@ -148,7 +148,7 @@ pub struct State { /// /// Keys are indices into the `draw_commands` Vec. drawing: HashMap, - /// A map of all type erased materials used by the draw. + /// A map of all type erased shader models used by the draw. pub(crate) shader_models: HashMap>, /// A list of indices of primitives that are being drawn via an alternate method and /// should not be drawn @@ -245,7 +245,7 @@ where context, shader_model: model_id, window, - _material: PhantomData, + _shader_model: PhantomData, } } @@ -458,27 +458,27 @@ where /// Produce a new [Draw] instance with the given context. fn context(&self, context: DrawContext) -> Draw { let state = self.state.clone(); - let material = self.shader_model.clone(); + let shader_model = self.shader_model.clone(); let window = self.window; Draw { state, context, - shader_model: material, + shader_model, window, - _material: PhantomData, + _shader_model: PhantomData, } } fn clone_shader_model(&self) -> SM { let mut state = self.state.write().unwrap(); - let material = state.shader_models.get_mut(&self.shader_model).unwrap(); - material + let shader_model = state.shader_models.get_mut(&self.shader_model).unwrap(); + shader_model .downcast_ref::() - .expect("Expected material to be of the correct type") + .expect("Expected shader model to be of the correct type") .clone() } - /// Produce a new [Draw] instance with a new material type. + /// Produce a new [Draw] instance with a new shader model type. pub fn shader_model(&self, model: SM2) -> Draw { let context = self.context.clone(); let DrawContext { transform, .. } = context; @@ -501,7 +501,7 @@ where context, shader_model: model_id, window, - _material: PhantomData, + _shader_model: PhantomData, } } @@ -545,8 +545,8 @@ where state.last_shader_model = Some(id.clone()); } - // Insert a material slot to be used if the drawing switches materials. - let material_index = state.draw_commands.len(); + // Insert a model slot to be used if the drawing switches models. + let shader_model_index = state.draw_commands.len(); state.draw_commands.push(None); // The primitive will be inserted in the next element. @@ -554,7 +554,7 @@ where let primitive: Primitive = primitive.into(); state.draw_commands.push(None); state.drawing.insert(index, primitive); - (index, material_index) + (index, shader_model_index) }; drawing::new(self, index, model_index) } @@ -694,7 +694,7 @@ impl Default for IntermediaryState { impl Default for State { fn default() -> Self { - let last_material = None; + let last_shader_model = None; let last_draw_context = None; let background_color = Default::default(); let draw_commands = Default::default(); @@ -702,7 +702,7 @@ impl Default for State { let intermediary_state = Arc::new(Default::default()); let theme = Default::default(); State { - last_shader_model: last_material, + last_shader_model, last_draw_context, draw_commands, drawing, diff --git a/bevy_nannou_draw/src/render.rs b/bevy_nannou_draw/src/render.rs index bc5b7756e..0c4edd0a1 100644 --- a/bevy_nannou_draw/src/render.rs +++ b/bevy_nannou_draw/src/render.rs @@ -61,13 +61,13 @@ pub const DEFAULT_NANNOU_SHADER_HANDLE: Handle = Handle::weak_from_u128( pub trait ShaderModel: Asset + AsBindGroup + Clone + Default + Sized + Send + Sync + 'static { - /// Returns this material's vertex shader. If [`ShaderRef::Default`] is returned, the default mesh vertex shader + /// Returns this shader model's vertex shader. If [`ShaderRef::Default`] is returned, the default mesh vertex shader /// will be used. fn vertex_shader() -> ShaderRef { ShaderRef::Default } - /// Returns this material's fragment shader. If [`ShaderRef::Default`] is returned, the default mesh fragment shader + /// Returns this shader model's fragment shader. If [`ShaderRef::Default`] is returned, the default mesh fragment shader /// will be used. #[allow(unused_variables)] fn fragment_shader() -> ShaderRef { @@ -137,7 +137,7 @@ where IndirectMaterialPlugin::::default(), InstancedMaterialPlugin::::default(), )) - .add_systems(PostUpdate, update_material::.after(update_draw_mesh)); + .add_systems(PostUpdate, update_shader_model::.after(update_draw_mesh)); app.sub_app_mut(RenderApp) .add_render_command::>() @@ -174,17 +174,17 @@ impl RenderAsset for PreparedShaderModel { type Param = (SRes, SRes>, SM::Param); fn prepare_asset( - material: Self::SourceAsset, - (render_device, pipeline, ref mut material_param): &mut SystemParamItem, + shader_model: Self::SourceAsset, + (render_device, pipeline, ref mut shader_model_param): &mut SystemParamItem, ) -> Result> { - match material.as_bind_group(&pipeline.shader_model_layout, render_device, material_param) { + match shader_model.as_bind_group(&pipeline.shader_model_layout, render_device, shader_model_param) { Ok(prepared) => Ok(PreparedShaderModel { bindings: prepared.bindings, bind_group: prepared.bind_group, key: prepared.data, }), Err(AsBindGroupError::RetryNextUpdate) => { - Err(PrepareAssetError::RetryNextUpdate(material)) + Err(PrepareAssetError::RetryNextUpdate(shader_model)) } Err(other) => Err(PrepareAssetError::AsBindGroupError(other)), } @@ -214,13 +214,13 @@ impl RenderCommand

let models = models.into_inner(); let model_instances = model_instances.into_inner(); - let Some(material_asset_id) = model_instances.get(&item.entity()) else { + let Some(shader_model_asset_id) = model_instances.get(&item.entity()) else { return RenderCommandResult::Skip; }; - let Some(material) = models.get(*material_asset_id) else { + let Some(model) = models.get(*shader_model_asset_id) else { return RenderCommandResult::Skip; }; - pass.set_bind_group(I, &material.bind_group, &[]); + pass.set_bind_group(I, &model.bind_group, &[]); RenderCommandResult::Success } } @@ -290,10 +290,10 @@ pub struct NannouMaterialKey { } impl From<&NannouShaderModel> for NannouMaterialKey { - fn from(material: &NannouShaderModel) -> Self { + fn from(shader_model: &NannouShaderModel) -> Self { Self { - polygon_mode: material.polygon_mode, - blend: material.blend, + polygon_mode: shader_model.polygon_mode, + blend: shader_model.blend, } } } @@ -535,11 +535,11 @@ fn setup_default_texture(mut commands: Commands, mut images: ResMut( +fn update_shader_model( draw_q: Query<&DrawHolder>, mut commands: Commands, - mut materials: ResMut>, - materials_q: Query<(Entity, &UntypedShaderModelId)>, + mut models: ResMut>, + models_q: Query<(Entity, &UntypedShaderModelId)>, ) where SM: ShaderModel, { @@ -548,12 +548,12 @@ fn update_material( state.shader_models.iter().for_each(|(id, model)| { if id.type_id() == TypeId::of::() { let model = model.downcast_ref::().unwrap(); - materials.insert(id.typed(), model.clone()); + models.insert(id.typed(), model.clone()); } }); } - for (entity, UntypedShaderModelId(id)) in materials_q.iter() { + for (entity, UntypedShaderModelId(id)) in models_q.iter() { if id.type_id() == TypeId::of::() { commands .entity(entity) @@ -592,7 +592,7 @@ fn update_draw_mesh( let mut fill_tessellator = FillTessellator::new(); let mut stroke_tessellator = StrokeTessellator::new(); - let mut last_mat = None; + let mut last_shader_model = None; let mut mesh = meshes.add(Mesh::init()); let mut curr_ctx: DrawContext = Default::default(); @@ -639,11 +639,11 @@ fn update_draw_mesh( let mut mesh = Mesh::init(); prim.render_primitive(ctxt, &mut mesh); let mesh = meshes.add(mesh); - let mat_id = last_mat.expect("No material set for instanced draw command"); + let model_id = last_shader_model.expect("No shader model set for instanced draw command"); commands.spawn(( InstancedMesh, InstanceRange(range), - UntypedShaderModelId(mat_id), + UntypedShaderModelId(model_id), mesh.clone(), Transform::default(), GlobalTransform::default(), @@ -675,11 +675,11 @@ fn update_draw_mesh( let mut mesh = Mesh::init(); prim.render_primitive(ctxt, &mut mesh); let mesh = meshes.add(mesh); - let mat_id = last_mat.expect("No material set for instanced draw command"); + let model_id = last_shader_model.expect("No shader model set for instanced draw command"); commands.spawn(( IndirectMesh, indirect_buffer, - UntypedShaderModelId(mat_id), + UntypedShaderModelId(model_id), mesh.clone(), Transform::default(), GlobalTransform::default(), @@ -696,8 +696,8 @@ fn update_draw_mesh( curr_ctx = ctx; } DrawCommand::ShaderModel(model_id) => { - // We switched materials, so start rendering into a new mesh - last_mat = Some(model_id.clone()); + // We switched models, so start rendering into a new mesh + last_shader_model = Some(model_id.clone()); mesh = meshes.add(Mesh::init()); commands.spawn(( UntypedShaderModelId(model_id), diff --git a/bevy_nannou_isf/src/asset.rs b/bevy_nannou_isf/src/asset.rs index 46ed9804c..16f495c72 100644 --- a/bevy_nannou_isf/src/asset.rs +++ b/bevy_nannou_isf/src/asset.rs @@ -95,7 +95,7 @@ impl AssetLoader for IsfLoader { } } -// 4. Plugin to register the asset loader and material +// 4. Plugin to register the asset loader pub struct IsfAssetPlugin; impl Plugin for IsfAssetPlugin { diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 06e638d6d..a21893b26 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -85,19 +85,13 @@ path = "draw/draw_blend.rs" name = "draw_capture" path = "draw/draw_capture.rs" [[example]] -name = "draw_custom_material" -path = "draw/draw_custom_material.rs" +name = "draw_custom_shader_model" +path = "draw/draw_custom_shader_model.rs" required-features = ["nannou/hot_reload"] [[example]] name = "draw_loop" path = "draw/draw_loop.rs" [[example]] -name = "draw_material" -path = "draw/draw_material.rs" -[[example]] -name = "draw_material_bloom" -path = "draw/draw_material_bloom.rs" -[[example]] name = "draw_mesh" path = "draw/draw_mesh.rs" [[example]] @@ -232,8 +226,8 @@ name = "simple_video" path = "video/simple_video.rs" required-features = ["video"] [[example]] -name = "video_material" -path = "video/video_material.rs" +name = "video_shader_model" +path = "video/video_shader_model.rs" required-features = ["video"] # WebGPU diff --git a/examples/assets/draw_custom_material.wgsl b/examples/assets/draw_custom_shader_model.wgsl similarity index 54% rename from examples/assets/draw_custom_material.wgsl rename to examples/assets/draw_custom_shader_model.wgsl index 95180787a..b96bda574 100644 --- a/examples/assets/draw_custom_material.wgsl +++ b/examples/assets/draw_custom_shader_model.wgsl @@ -1,14 +1,14 @@ #import bevy_pbr::forward_io::VertexOutput -struct CustomMaterial { +struct CustomShaderModel { color: vec4, }; -@group(2) @binding(0) var material: CustomMaterial; +@group(2) @binding(0) var shader_model: CustomShaderModel; @fragment fn fragment( mesh: VertexOutput, ) -> @location(0) vec4 { - return material.color; + return shader_model.color; } diff --git a/examples/assets/shaders/particle_mouse_material.wgsl b/examples/assets/shaders/particle_mouse_model.wgsl similarity index 100% rename from examples/assets/shaders/particle_mouse_material.wgsl rename to examples/assets/shaders/particle_mouse_model.wgsl diff --git a/examples/assets/shaders/particle_sdf_material.wgsl b/examples/assets/shaders/particle_sdf_model.wgsl similarity index 100% rename from examples/assets/shaders/particle_sdf_material.wgsl rename to examples/assets/shaders/particle_sdf_model.wgsl diff --git a/examples/assets/draw_video_material.wgsl b/examples/assets/video_model.wgsl similarity index 100% rename from examples/assets/draw_video_material.wgsl rename to examples/assets/video_model.wgsl diff --git a/examples/compute/particle_mouse.rs b/examples/compute/particle_mouse.rs index 9def1fa33..796a27879 100644 --- a/examples/compute/particle_mouse.rs +++ b/examples/compute/particle_mouse.rs @@ -27,7 +27,7 @@ struct Model { } impl Model { - fn material(&self) -> ShaderModel { + fn shader_model(&self) -> ShaderModel { ShaderModel { particles: self.particles.clone(), } @@ -81,8 +81,8 @@ impl Compute for ComputeModel { } #[shader_model( - fragment = "shaders/particle_mouse_material.wgsl", - vertex = "shaders/particle_mouse_material.wgsl" + fragment = "shaders/particle_mouse_model.wgsl", + vertex = "shaders/particle_mouse_model.wgsl" )] struct ShaderModel { #[storage(0, read_only, visibility(vertex))] @@ -165,7 +165,7 @@ fn view(app: &App, model: &Model) { let draw = app.draw(); draw.background().color(GRAY); - let draw = draw.shader_model(model.material()); + let draw = draw.shader_model(model.shader_model()); match model.shape { Shape::Circle => { draw_particles_circle(&draw); diff --git a/examples/compute/particle_sdf.rs b/examples/compute/particle_sdf.rs index 0d838231f..e69c1ce53 100644 --- a/examples/compute/particle_sdf.rs +++ b/examples/compute/particle_sdf.rs @@ -29,7 +29,7 @@ struct Model { } impl Model { - fn material(&self) -> ShaderModel { + fn shader_model(&self) -> ShaderModel { ShaderModel { particles: self.particles.clone(), } @@ -119,8 +119,8 @@ impl Compute for ComputeModel { // Our shader model that will be used to render the particles #[shader_model( - fragment = "shaders/particle_sdf_material.wgsl", - vertex = "shaders/particle_sdf_material.wgsl" + fragment = "shaders/particle_sdf_model.wgsl", + vertex = "shaders/particle_sdf_model.wgsl" )] struct ShaderModel { #[storage(0, read_only, visibility(vertex))] @@ -232,7 +232,7 @@ fn view(app: &App, model: &Model) { let draw = app.draw(); draw.background().color(GRAY); - let draw = draw.shader_model(model.material()); + let draw = draw.shader_model(model.shader_model()); draw.indirect() .primitive(draw.rect().w_h(2.0, 2.0)) .buffer(model.indirect_params.clone()); diff --git a/examples/draw/draw_custom_material.rs b/examples/draw/draw_custom_shader_model.rs similarity index 71% rename from examples/draw/draw_custom_material.rs rename to examples/draw/draw_custom_shader_model.rs index b0f1c6718..474f95cd2 100644 --- a/examples/draw/draw_custom_material.rs +++ b/examples/draw/draw_custom_shader_model.rs @@ -3,7 +3,7 @@ use nannou::prelude::*; fn main() { nannou::app(model) .simple_window(view) - // Register our custom material to make it available for use in our drawing + // Register our custom shader model to make it available for use in our drawing .shader_model::() .run() } @@ -11,7 +11,7 @@ fn main() { struct Model {} // This struct defines the data that will be passed to your shader -#[shader_model(fragment = "draw_custom_material.wgsl")] +#[shader_model(fragment = "draw_custom_shader_model.wgsl")] struct ShaderModel { #[uniform(0)] color: LinearRgba, @@ -25,12 +25,12 @@ fn view(app: &App, model: &Model, window: Entity) { // Begin drawing let draw = app .draw() - // Initialize our draw instance with our custom material + // Initialize our draw instance with our custom shader model .shader_model(ShaderModel { color: RED.into() }); draw.ellipse().x(-200.0); - // We can also map the material manually + // We can also map the shader model manually draw.ellipse() .map_shader_model(|mut mat| { mat.color = BLUE.into(); diff --git a/examples/draw/draw_material.rs b/examples/draw/draw_material.rs deleted file mode 100644 index 317a841ce..000000000 --- a/examples/draw/draw_material.rs +++ /dev/null @@ -1,66 +0,0 @@ -use nannou::prelude::light_consts::lux::DIRECT_SUNLIGHT; -use nannou::prelude::primitive::polygon::PolygonOptions; -use nannou::prelude::*; - -fn main() { - nannou::app(model).update(update).run(); -} - -struct Model { - window: Entity, - light: Entity, -} - -fn model(app: &App) -> Model { - let light = app.new_light().color(WHITE).illuminance(1000.0).build(); - let window = app - .new_window() - .size_pixels(1024, 512) - .light(light) - .view(view) - .build(); - - Model { light, window } -} - -fn update(app: &App, model: &mut Model) { - let light = app.light(model.light); - let window_rect = app.window_rect(); - let window_center = window_rect.xy(); - let mouse_x = app.mouse().x; - let mouse_y = app.mouse().y; - let norm_mouse_x = (mouse_x / window_rect.w()) + 0.5; - let norm_mouse_y = (mouse_y / window_rect.h()) + 0.5; - - // Calculate the light's position based on time t - let time = app.time(); - let radius = window_rect.w().min(window_rect.h()) * 0.4; - let light_x = window_center.x + radius * (time * 2.0 * PI).cos(); - let light_y = window_center.y + radius * (time * 2.0 * PI).sin(); - - let light_color = Color::hsl((1.0 - norm_mouse_x) * 360.0, 1.0, 0.5); - light - .color(light_color) - .illuminance(norm_mouse_y * DIRECT_SUNLIGHT) - .x_y_z(light_x, light_y, 1000.0) - .look_at(Vec2::ZERO); -} - -fn view(app: &App, model: &Model) { - // Begin drawing - let draw = app.draw(); - - for y in -2..=2 { - for x in -5..=5 { - let x01 = (x + 5) as f32 / 10.0; - let y01 = (y + 2) as f32 / 2.0; - - draw.ellipse() - .w_h(50.0, 50.0) - .x_y_z(x as f32 * 100.0, y as f32 * 100.0, 10.0) - .roughness(x01) - .metallic(y01) - .color(Color::gray(0.5)); - } - } -} diff --git a/examples/draw/draw_material_bloom.rs b/examples/draw/draw_material_bloom.rs deleted file mode 100644 index a0e2def2b..000000000 --- a/examples/draw/draw_material_bloom.rs +++ /dev/null @@ -1,58 +0,0 @@ -use nannou::prelude::*; - -fn main() { - nannou::app(model).update(update).run(); -} - -struct Model { - window: Entity, - camera: Entity, -} - -fn model(app: &App) -> Model { - let camera = app - .new_camera() - // HDR is required for bloom to work. - .hdr(true) - // Pick a default bloom settings. This also can be configured manually. - .bloom_settings(BloomSettings::OLD_SCHOOL) - .build(); - - let window = app - .new_window() - .camera(camera) - .size_pixels(1024, 1024) - .view(view) - .build(); - - Model { camera, window } -} - -fn update(app: &App, model: &mut Model) { - let camera = app.camera(model.camera); - let window_rect = app.window_rect(); - let norm_mouse_y = (app.mouse().y / window_rect.w()) + 0.5; - - camera.bloom_intensity(norm_mouse_y.clamp(0.0, 0.8)); -} - -fn view(app: &App, model: &Model) { - // Begin drawing - let draw = app.draw(); - let window_rect = app.window_rect(); - let norm_mouse_x = (app.mouse().x / window_rect.w()) + 0.5; - - // Use the normalized mouse coordinate to create an initial color. - let color_hsl = Color::hsl((1.0 - norm_mouse_x) * 360.0, 1.0, 0.5); - - // Convert the color to linear RGBA and multiply (for emissives, values outside of 1.0 are used). - let mut color_linear_rgb: LinearRgba = color_hsl.into(); - color_linear_rgb = color_linear_rgb * 5.0; - - let t = app.time(); - - draw.tri() - .width(100.0) - .emissive(color_linear_rgb) - .color(WHITE); -} diff --git a/examples/video/video_material.rs b/examples/video/video_shader_model.rs similarity index 84% rename from examples/video/video_material.rs rename to examples/video/video_shader_model.rs index 0a3f2ca15..87afe68a2 100644 --- a/examples/video/video_material.rs +++ b/examples/video/video_shader_model.rs @@ -3,7 +3,7 @@ use nannou::prelude::*; fn main() { nannou::app(model) - // Register our custom material to make it available for use in our drawing + // Register our custom shader model to make it available for use in our drawing .shader_model::() .run(); } @@ -16,7 +16,7 @@ struct Model { } // This struct defines the data that will be passed to your shader -#[shader_model(fragment = "draw_video_material.wgsl")] +#[shader_model(fragment = "video_model.wgsl")] struct VideoShaderModel { #[texture(0)] #[sampler(1)] @@ -51,7 +51,7 @@ fn view(app: &App, model: &Model) { let draw = app .draw() - // Initialize our draw instance with our custom material + // Initialize our draw instance with our custom shader model .shader_model(VideoShaderModel { texture: video.texture.clone(), });