
# Objective Currently the `missing_docs` lint is allowed-by-default and enabled at crate level when their documentations is complete (see #3492). This PR proposes to inverse this logic by making `missing_docs` warn-by-default and mark crates with imcomplete docs allowed. ## Solution Makes `missing_docs` warn at workspace level and allowed at crate level when the docs is imcomplete.
59 lines
1.6 KiB
Rust
59 lines
1.6 KiB
Rust
//! A shader and a material that uses it.
|
|
|
|
use bevy::{
|
|
prelude::*,
|
|
reflect::TypePath,
|
|
render::render_resource::{AsBindGroup, ShaderRef},
|
|
sprite::{Material2d, Material2dPlugin, MaterialMesh2dBundle},
|
|
};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins,
|
|
Material2dPlugin::<CustomMaterial>::default(),
|
|
))
|
|
.add_systems(Startup, setup)
|
|
.run();
|
|
}
|
|
|
|
// Setup a simple 2d scene
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<CustomMaterial>>,
|
|
asset_server: Res<AssetServer>,
|
|
) {
|
|
// camera
|
|
commands.spawn(Camera2dBundle::default());
|
|
|
|
// quad
|
|
commands.spawn(MaterialMesh2dBundle {
|
|
mesh: meshes.add(shape::Quad::default()).into(),
|
|
transform: Transform::default().with_scale(Vec3::splat(128.)),
|
|
material: materials.add(CustomMaterial {
|
|
color: Color::BLUE,
|
|
color_texture: Some(asset_server.load("branding/icon.png")),
|
|
}),
|
|
..default()
|
|
});
|
|
}
|
|
|
|
// This is the struct that will be passed to your shader
|
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
|
struct CustomMaterial {
|
|
#[uniform(0)]
|
|
color: Color,
|
|
#[texture(1)]
|
|
#[sampler(2)]
|
|
color_texture: Option<Handle<Image>>,
|
|
}
|
|
|
|
/// The Material2d trait is very configurable, but comes with sensible defaults for all methods.
|
|
/// You only need to implement functions for features that need non-default behavior. See the Material2d api docs for details!
|
|
impl Material2d for CustomMaterial {
|
|
fn fragment_shader() -> ShaderRef {
|
|
"shaders/custom_material_2d.wgsl".into()
|
|
}
|
|
}
|