Skip to main content

ImageSampler

Enum ImageSampler 

Source
pub enum ImageSampler {
    Default,
    Descriptor(ImageSamplerDescriptor),
}
Available on crate feature bevy_image only.
Expand description

Used in Image, this determines what image sampler to use when rendering. The default setting, ImageSampler::Default, will read the sampler from the ImagePlugin at setup. Setting this to ImageSampler::Descriptor will override the global default descriptor for this Image.

Variants§

§

Default

Default image sampler, derived from the ImagePlugin setup.

§

Descriptor(ImageSamplerDescriptor)

Custom sampler for this image which will override global default.

Implementations§

Source§

impl ImageSampler

Source

pub fn linear() -> ImageSampler

Returns an image sampler with ImageFilterMode::Linear min and mag filters

Examples found in repository?
examples/2d/texture_atlas.rs (line 65)
50fn setup(
51    mut commands: Commands,
52    rpg_sprite_handles: Res<RpgSpriteFolder>,
53    asset_server: Res<AssetServer>,
54    mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
55    loaded_folders: Res<Assets<LoadedFolder>>,
56    mut textures: ResMut<Assets<Image>>,
57) {
58    let loaded_folder = loaded_folders.get(&rpg_sprite_handles.0).unwrap();
59
60    // Create texture atlases with different padding and sampling
61
62    let (texture_atlas_linear, linear_sources, linear_texture) = create_texture_atlas(
63        loaded_folder,
64        None,
65        Some(ImageSampler::linear()),
66        &mut textures,
67    );
68    let atlas_linear_handle = texture_atlases.add(texture_atlas_linear);
69
70    let (texture_atlas_nearest, nearest_sources, nearest_texture) = create_texture_atlas(
71        loaded_folder,
72        None,
73        Some(ImageSampler::nearest()),
74        &mut textures,
75    );
76    let atlas_nearest_handle = texture_atlases.add(texture_atlas_nearest);
77
78    let (texture_atlas_linear_padded, linear_padded_sources, linear_padded_texture) =
79        create_texture_atlas(
80            loaded_folder,
81            Some(UVec2::new(6, 6)),
82            Some(ImageSampler::linear()),
83            &mut textures,
84        );
85    let atlas_linear_padded_handle = texture_atlases.add(texture_atlas_linear_padded.clone());
86
87    let (texture_atlas_nearest_padded, nearest_padded_sources, nearest_padded_texture) =
88        create_texture_atlas(
89            loaded_folder,
90            Some(UVec2::new(6, 6)),
91            Some(ImageSampler::nearest()),
92            &mut textures,
93        );
94    let atlas_nearest_padded_handle = texture_atlases.add(texture_atlas_nearest_padded);
95
96    commands.spawn(Camera2d);
97
98    // Padded textures are to the right, unpadded to the left
99
100    // Draw unpadded texture atlas
101    commands.spawn((
102        Sprite::from_image(linear_texture.clone()),
103        Transform {
104            translation: Vec3::new(-250.0, -160.0, 0.0),
105            scale: Vec3::splat(0.5),
106            ..default()
107        },
108    ));
109
110    // Draw padded texture atlas
111    commands.spawn((
112        Sprite::from_image(linear_padded_texture.clone()),
113        Transform {
114            translation: Vec3::new(250.0, -160.0, 0.0),
115            scale: Vec3::splat(0.5),
116            ..default()
117        },
118    ));
119
120    let font = asset_server.load("fonts/FiraSans-Bold.ttf");
121
122    // Padding label text style
123    let text_style: TextFont = TextFont {
124        font: font.clone().into(),
125        font_size: FontSize::Px(42.0),
126        ..default()
127    };
128
129    // Labels to indicate padding
130
131    // No padding
132    create_label(
133        &mut commands,
134        (-250.0, 250.0, 0.0),
135        "No padding",
136        text_style.clone(),
137    );
138
139    // Padding
140    create_label(&mut commands, (250.0, 250.0, 0.0), "Padding", text_style);
141
142    // Get handle to a sprite to render
143    let vendor_handle: Handle<Image> = asset_server
144        .get_handle("textures/rpg/chars/vendor/generic-rpg-vendor.png")
145        .unwrap();
146
147    // Configuration array to render sprites through iteration
148    let configurations: [(
149        &str,
150        Handle<TextureAtlasLayout>,
151        TextureAtlasSources,
152        Handle<Image>,
153        f32,
154    ); 4] = [
155        (
156            "Linear",
157            atlas_linear_handle,
158            linear_sources,
159            linear_texture,
160            -350.0,
161        ),
162        (
163            "Nearest",
164            atlas_nearest_handle,
165            nearest_sources,
166            nearest_texture,
167            -150.0,
168        ),
169        (
170            "Linear",
171            atlas_linear_padded_handle,
172            linear_padded_sources,
173            linear_padded_texture,
174            150.0,
175        ),
176        (
177            "Nearest",
178            atlas_nearest_padded_handle,
179            nearest_padded_sources,
180            nearest_padded_texture,
181            350.0,
182        ),
183    ];
184
185    // Label text style
186    let sampling_label_style = TextFont {
187        font: font.into(),
188        font_size: FontSize::Px(25.0),
189        ..default()
190    };
191
192    let base_y = 80.0; // y position of the sprites
193
194    for (sampling, atlas_handle, atlas_sources, atlas_texture, x) in configurations {
195        // Render a sprite from the texture_atlas
196        create_sprite_from_atlas(
197            &mut commands,
198            (x, base_y, 0.0),
199            atlas_texture,
200            atlas_sources,
201            atlas_handle,
202            &vendor_handle,
203        );
204
205        // Render a label to indicate the sampling setting
206        create_label(
207            &mut commands,
208            (x, base_y + 110.0, 0.0), // Offset to y position of the sprite
209            sampling,
210            sampling_label_style.clone(),
211        );
212    }
213}
Source

pub fn nearest() -> ImageSampler

Returns an image sampler with ImageFilterMode::Nearest min and mag filters

Examples found in repository?
examples/ui/images/ui_texture_slice_flip_and_tile.rs (line 22)
17fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
18    let image = asset_server
19        .load_builder()
20        .with_settings(|settings: &mut ImageLoaderSettings| {
21            // Need to use nearest filtering to avoid bleeding between the slices with tiling
22            settings.sampler = ImageSampler::nearest();
23        })
24        .load("textures/fantasy_ui_borders/numbered_slices.png");
25
26    let slicer = TextureSlicer {
27        // `numbered_slices.png` is 48 pixels square. `BorderRect::square(16.)` insets the slicing line from each edge by 16 pixels, resulting in nine slices that are each 16 pixels square.
28        border: BorderRect::all(16.),
29        // With `SliceScaleMode::Tile` the side and center slices are tiled to fill the side and center sections of the target.
30        // And with a `stretch_value` of `1.` the tiles will have the same size as the corresponding slices in the source image.
31        center_scale_mode: SliceScaleMode::Tile { stretch_value: 1. },
32        sides_scale_mode: SliceScaleMode::Tile { stretch_value: 1. },
33        ..default()
34    };
35
36    // ui camera
37    commands.spawn(Camera2d);
38
39    commands
40        .spawn(Node {
41            width: percent(100),
42            height: percent(100),
43            justify_content: JustifyContent::Center,
44            align_content: AlignContent::Center,
45            flex_wrap: FlexWrap::Wrap,
46            column_gap: px(10),
47            row_gap: px(10),
48            ..default()
49        })
50        .with_children(|parent| {
51            for [columns, rows] in [[3, 3], [4, 4], [5, 4], [4, 5], [5, 5]] {
52                for (flip_x, flip_y) in [(false, false), (false, true), (true, false), (true, true)]
53                {
54                    parent.spawn((
55                        ImageNode {
56                            image: image.clone(),
57                            flip_x,
58                            flip_y,
59                            image_mode: NodeImageMode::Sliced(slicer.clone()),
60                            ..default()
61                        },
62                        Node {
63                            width: px(16 * columns),
64                            height: px(16 * rows),
65                            ..default()
66                        },
67                    ));
68                }
69            }
70        });
71}
More examples
Hide additional examples
examples/asset/asset_saving.rs (line 110)
85fn setup(
86    mut commands: Commands,
87    asset_server: Res<AssetServer>,
88    mut images: ResMut<Assets<Image>>,
89) {
90    commands.spawn((
91        Camera2d,
92        Projection::Orthographic(OrthographicProjection {
93            scaling_mode: ScalingMode::FixedVertical {
94                viewport_height: 125.0,
95            },
96            ..OrthographicProjection::default_2d()
97        }),
98    ));
99
100    commands.spawn(Text(
101        r"Select a color from the palette at the bottom
102LMB - Draw with selected color
103F5 - Save image"
104            .into(),
105    ));
106
107    let handle = asset_server
108        .load_builder()
109        .with_settings(|settings: &mut ImageLoaderSettings| {
110            settings.sampler = ImageSampler::nearest();
111        })
112        .load(ASSET_PATH);
113    commands.spawn((
114        Sprite {
115            image: handle.clone(),
116            ..Default::default()
117        },
118        SpriteToSave,
119        Pickable::default(),
120    ));
121
122    // We're doing something a little cursed here: we initiate a load, and then insert a default
123    // image into that handle. If the load succeeds, the image will be replaced with the loaded
124    // contents. If it fails, the default image will remain. In real code, you likely want to poll
125    // `AssetServer::load_state` and only insert this on load failure.
126    images
127        .insert(&handle, {
128            let mut image = Image::new_fill(
129                Extent3d {
130                    width: 100,
131                    height: 100,
132                    depth_or_array_layers: 1,
133                },
134                TextureDimension::D2,
135                &[0, 0, 0, 255],
136                TextureFormat::Rgba8Unorm,
137                RenderAssetUsages::all(),
138            );
139            image.sampler = ImageSampler::nearest();
140            image
141        })
142        .unwrap();
143
144    commands.insert_resource(ImageToSave(handle));
145
146    let container = commands
147        .spawn((
148            Node {
149                width: percent(100),
150                height: percent(100),
151                align_items: AlignItems::End,
152                justify_content: JustifyContent::Center,
153                ..Default::default()
154            },
155            Pickable::IGNORE,
156        ))
157        .id();
158
159    for color in [
160        Color::WHITE,
161        Color::Srgba(tailwind::RED_500),
162        Color::Srgba(tailwind::ORANGE_500),
163        Color::Srgba(tailwind::YELLOW_500),
164        Color::Srgba(tailwind::GREEN_500),
165        Color::Srgba(tailwind::BLUE_500),
166        Color::Srgba(tailwind::INDIGO_500),
167        Color::Srgba(tailwind::VIOLET_500),
168        Color::BLACK,
169    ] {
170        let mut entity = commands.spawn((
171            Node {
172                width: vw(5),
173                height: vh(5),
174                border: px(5).all(),
175                ..Default::default()
176            },
177            SelectableColor,
178            BackgroundColor(color),
179            BorderColor::all(NORMAL_COLOR),
180            ChildOf(container),
181        ));
182        if color == Color::WHITE {
183            entity.insert((Selected, BorderColor::all(SELECTED_COLOR)));
184        }
185    }
186}
examples/asset/asset_settings.rs (line 68)
21fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
22    // Without any .meta file specifying settings, the default sampler [ImagePlugin::default()] is used for loading images.
23    // If you are using a very small image and rendering it larger like seen here, the default linear filtering will result in a blurry image.
24    // Useful note: The default sampler specified by the ImagePlugin is *not* the same as the default implementation of sampler. This is why
25    // everything uses linear by default but if you look at the default of sampler, it uses nearest.
26    commands.spawn((
27        Sprite {
28            image: asset_server.load("bevy_pixel_dark.png"),
29            custom_size: Some(Vec2 { x: 160.0, y: 120.0 }),
30            ..Default::default()
31        },
32        Transform::from_xyz(-100.0, 0.0, 0.0),
33    ));
34
35    // When a .meta file is added with the same name as the asset and a '.meta' extension
36    // you can (and must) specify all fields of the asset loader's settings for that
37    // particular asset, in this case [ImageLoaderSettings]. Take a look at
38    // examples/asset/files/bevy_pixel_dark_with_meta.png.meta
39    // for the format and you'll notice, the only non-default option is setting Nearest
40    // filtering. This tends to work much better for pixel art assets.
41    // A good reference when filling this out is to check out [ImageLoaderSettings::default()]
42    // and follow to the default implementation of each fields type.
43    // https://docs.rs/bevy/latest/bevy/image/struct.ImageLoaderSettings.html
44    commands.spawn((
45        Sprite {
46            image: asset_server.load("bevy_pixel_dark_with_meta.png"),
47            custom_size: Some(Vec2 { x: 160.0, y: 120.0 }),
48            ..Default::default()
49        },
50        Transform::from_xyz(100.0, 0.0, 0.0),
51    ));
52
53    // Another option is to use the LoadBuilder::with_settings function.
54    // With this you can specify the same settings upon loading your asset with a
55    // couple of differences. A big one is that you aren't required to set *every*
56    // setting, just modify the ones that you need. It works by passing in a function
57    // (in this case an anonymous closure) that takes a reference to the settings type
58    // that is then modified in the function.
59    // Do note that if you want to load the same asset with different settings, the
60    // settings changes from any loads after the first of the same asset will be ignored.
61    // This is why this one loads a differently named copy of the asset instead of using
62    // same one as without a .meta file.
63    commands.spawn((
64        Sprite {
65            image: asset_server
66                .load_builder()
67                .with_settings(|settings: &mut ImageLoaderSettings| {
68                    settings.sampler = ImageSampler::nearest();
69                })
70                .load("bevy_pixel_dark_with_settings.png"),
71            custom_size: Some(Vec2 { x: 160.0, y: 120.0 }),
72            ..Default::default()
73        },
74        Transform::from_xyz(0.0, 150.0, 0.0),
75    ));
76
77    commands.spawn(Camera2d);
78}
examples/testbed/2d.rs (line 504)
460    pub fn setup(
461        mut commands: Commands,
462        mut textures: ResMut<Assets<Image>>,
463        mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
464    ) {
465        commands.spawn((Camera2d, DespawnOnExit(super::Scene::TextureAtlasBuilder)));
466
467        for (i, padding) in [UVec2::ZERO, PADDING_SIZE].into_iter().enumerate() {
468            // generate solid red green and blue and yellow images
469            let images = [
470                [255, 0, 0, 255],
471                [0, 255, 0, 255],
472                [0, 0, 255, 255],
473                [255, 255, 0, 255],
474            ]
475            .map(|pixel| {
476                Image::new_fill(
477                    Extent3d {
478                        width: 28,
479                        height: 28,
480                        depth_or_array_layers: 1,
481                    },
482                    TextureDimension::D2,
483                    &pixel,
484                    TextureFormat::Rgba8UnormSrgb,
485                    RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD,
486                )
487            });
488
489            let mut texture_atlas_builder = TextureAtlasBuilder::default();
490            texture_atlas_builder
491                .initial_size(ATLAS_SIZE)
492                .max_size(ATLAS_SIZE)
493                .padding(padding);
494            for image in &images {
495                texture_atlas_builder.add_texture(None, image);
496            }
497
498            let (atlas_layout, _, atlas_texture) = texture_atlas_builder.build().expect(
499                "The images are 28 pixels square, so they should fit with 4 pixels left over",
500            );
501            let atlas_layout = texture_atlases.add(atlas_layout);
502
503            let mut nearest_atlas_image = atlas_texture.clone();
504            nearest_atlas_image.sampler = ImageSampler::nearest();
505
506            let atlas_handle = textures.add(atlas_texture);
507            let nearest_atlas_handle = textures.add(nearest_atlas_image);
508
509            let position = ((2. * i as f32 - 1.) * (0.625 * ATLAS_SIZE.x as f32 * ATLAS_SCALE))
510                .round()
511                * Vec3::X;
512
513            commands.spawn((
514                Sprite {
515                    image: nearest_atlas_handle,
516                    custom_size: Some(ATLAS_SIZE.as_vec2() * ATLAS_SCALE),
517                    ..default()
518                },
519                Anchor::BOTTOM_CENTER,
520                ShowAabbGizmo {
521                    color: Some(Color::WHITE),
522                },
523                DespawnOnExit(super::Scene::TextureAtlasBuilder),
524                Transform::from_translation(position),
525            ));
526
527            for (index, anchor) in [
528                Anchor::BOTTOM_RIGHT,
529                Anchor::BOTTOM_LEFT,
530                Anchor::TOP_LEFT,
531                Anchor::TOP_RIGHT,
532            ]
533            .into_iter()
534            .enumerate()
535            {
536                commands.spawn((
537                    Sprite {
538                        image: atlas_handle.clone(),
539                        texture_atlas: Some(TextureAtlas {
540                            layout: atlas_layout.clone(),
541                            index,
542                        }),
543                        custom_size: Some(IMAGE_SIZE.as_vec2() * IMAGE_SCALE),
544                        ..default()
545                    },
546                    Transform::from_translation(
547                        position
548                            + -2.
549                                * IMAGE_SCALE
550                                * (Vec3::Y * IMAGE_SIZE.y as f32 + anchor.as_vec().extend(0.)),
551                    ),
552                    anchor,
553                    DespawnOnExit(super::Scene::TextureAtlasBuilder),
554                ));
555            }
556        }
557    }
examples/2d/texture_atlas.rs (line 73)
50fn setup(
51    mut commands: Commands,
52    rpg_sprite_handles: Res<RpgSpriteFolder>,
53    asset_server: Res<AssetServer>,
54    mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
55    loaded_folders: Res<Assets<LoadedFolder>>,
56    mut textures: ResMut<Assets<Image>>,
57) {
58    let loaded_folder = loaded_folders.get(&rpg_sprite_handles.0).unwrap();
59
60    // Create texture atlases with different padding and sampling
61
62    let (texture_atlas_linear, linear_sources, linear_texture) = create_texture_atlas(
63        loaded_folder,
64        None,
65        Some(ImageSampler::linear()),
66        &mut textures,
67    );
68    let atlas_linear_handle = texture_atlases.add(texture_atlas_linear);
69
70    let (texture_atlas_nearest, nearest_sources, nearest_texture) = create_texture_atlas(
71        loaded_folder,
72        None,
73        Some(ImageSampler::nearest()),
74        &mut textures,
75    );
76    let atlas_nearest_handle = texture_atlases.add(texture_atlas_nearest);
77
78    let (texture_atlas_linear_padded, linear_padded_sources, linear_padded_texture) =
79        create_texture_atlas(
80            loaded_folder,
81            Some(UVec2::new(6, 6)),
82            Some(ImageSampler::linear()),
83            &mut textures,
84        );
85    let atlas_linear_padded_handle = texture_atlases.add(texture_atlas_linear_padded.clone());
86
87    let (texture_atlas_nearest_padded, nearest_padded_sources, nearest_padded_texture) =
88        create_texture_atlas(
89            loaded_folder,
90            Some(UVec2::new(6, 6)),
91            Some(ImageSampler::nearest()),
92            &mut textures,
93        );
94    let atlas_nearest_padded_handle = texture_atlases.add(texture_atlas_nearest_padded);
95
96    commands.spawn(Camera2d);
97
98    // Padded textures are to the right, unpadded to the left
99
100    // Draw unpadded texture atlas
101    commands.spawn((
102        Sprite::from_image(linear_texture.clone()),
103        Transform {
104            translation: Vec3::new(-250.0, -160.0, 0.0),
105            scale: Vec3::splat(0.5),
106            ..default()
107        },
108    ));
109
110    // Draw padded texture atlas
111    commands.spawn((
112        Sprite::from_image(linear_padded_texture.clone()),
113        Transform {
114            translation: Vec3::new(250.0, -160.0, 0.0),
115            scale: Vec3::splat(0.5),
116            ..default()
117        },
118    ));
119
120    let font = asset_server.load("fonts/FiraSans-Bold.ttf");
121
122    // Padding label text style
123    let text_style: TextFont = TextFont {
124        font: font.clone().into(),
125        font_size: FontSize::Px(42.0),
126        ..default()
127    };
128
129    // Labels to indicate padding
130
131    // No padding
132    create_label(
133        &mut commands,
134        (-250.0, 250.0, 0.0),
135        "No padding",
136        text_style.clone(),
137    );
138
139    // Padding
140    create_label(&mut commands, (250.0, 250.0, 0.0), "Padding", text_style);
141
142    // Get handle to a sprite to render
143    let vendor_handle: Handle<Image> = asset_server
144        .get_handle("textures/rpg/chars/vendor/generic-rpg-vendor.png")
145        .unwrap();
146
147    // Configuration array to render sprites through iteration
148    let configurations: [(
149        &str,
150        Handle<TextureAtlasLayout>,
151        TextureAtlasSources,
152        Handle<Image>,
153        f32,
154    ); 4] = [
155        (
156            "Linear",
157            atlas_linear_handle,
158            linear_sources,
159            linear_texture,
160            -350.0,
161        ),
162        (
163            "Nearest",
164            atlas_nearest_handle,
165            nearest_sources,
166            nearest_texture,
167            -150.0,
168        ),
169        (
170            "Linear",
171            atlas_linear_padded_handle,
172            linear_padded_sources,
173            linear_padded_texture,
174            150.0,
175        ),
176        (
177            "Nearest",
178            atlas_nearest_padded_handle,
179            nearest_padded_sources,
180            nearest_padded_texture,
181            350.0,
182        ),
183    ];
184
185    // Label text style
186    let sampling_label_style = TextFont {
187        font: font.into(),
188        font_size: FontSize::Px(25.0),
189        ..default()
190    };
191
192    let base_y = 80.0; // y position of the sprites
193
194    for (sampling, atlas_handle, atlas_sources, atlas_texture, x) in configurations {
195        // Render a sprite from the texture_atlas
196        create_sprite_from_atlas(
197            &mut commands,
198            (x, base_y, 0.0),
199            atlas_texture,
200            atlas_sources,
201            atlas_handle,
202            &vendor_handle,
203        );
204
205        // Render a label to indicate the sampling setting
206        create_label(
207            &mut commands,
208            (x, base_y + 110.0, 0.0), // Offset to y position of the sprite
209            sampling,
210            sampling_label_style.clone(),
211        );
212    }
213}
Source

pub fn get_or_init_descriptor(&mut self) -> &mut ImageSamplerDescriptor

Initialize the descriptor if it is not already initialized.

Descriptor is typically initialized by Bevy when the image is loaded, so this is convenient shortcut for updating the descriptor.

Examples found in repository?
tests/3d/test_meshlet.rs (line 220)
190fn mipmap_material(
191    standard_materials: &mut Assets<StandardMaterial>,
192    images: &mut Assets<Image>,
193) -> Handle<StandardMaterial> {
194    let mip_colors = [
195        Srgba::rgb(1.0, 0.0, 0.0),
196        Srgba::rgb(0.0, 1.0, 0.0),
197        Srgba::rgb(0.0, 0.0, 1.0),
198        Srgba::rgb(1.0, 1.0, 0.0),
199        Srgba::rgb(0.0, 1.0, 1.0),
200        Srgba::rgb(1.0, 0.0, 1.0),
201    ];
202
203    let size = 256;
204
205    let mut image = Image::new_uninit(
206        Extent3d {
207            width: size as u32,
208            height: size as u32,
209            depth_or_array_layers: 1,
210        },
211        TextureDimension::D2,
212        TextureFormat::Rgba8UnormSrgb,
213        RenderAssetUsages::default(),
214    );
215
216    image.texture_descriptor.mip_level_count = mip_colors.len() as u32;
217
218    image
219        .sampler
220        .get_or_init_descriptor()
221        .set_filter(ImageFilterMode::Linear)
222        .set_address_mode(ImageAddressMode::Repeat);
223
224    image.data = Some(
225        mip_colors
226            .iter()
227            .enumerate()
228            .flat_map(|(level, color)| checkerboard(size / 2_usize.pow(level as u32), *color))
229            .collect(),
230    );
231
232    standard_materials.add(StandardMaterial {
233        base_color_texture: Some(images.add(image)),
234        perceptual_roughness: 1.0,
235        ..default()
236    })
237}
More examples
Hide additional examples
examples/3d/solari_reflections.rs (line 322)
297fn spawn_room(
298    commands: &mut Commands,
299    asset_server: &AssetServer,
300    meshes: &mut Assets<Mesh>,
301    materials: &mut Assets<StandardMaterial>,
302) {
303    let mut floor_mesh = raytraced(Plane3d::new(Vec3::Y, Vec2::new(9.0, 10.5)));
304    match floor_mesh.attribute_mut(Mesh::ATTRIBUTE_UV_0).unwrap() {
305        VertexAttributeValues::Float32x2(items) => {
306            items.iter_mut().flatten().for_each(|x| *x *= 9.0);
307        }
308        _ => unreachable!(),
309    }
310    let floor = meshes.add(floor_mesh);
311    commands.spawn((
312        RaytracingMesh3d(floor.clone()),
313        Mesh3d(floor),
314        MeshMaterial3d(
315            materials.add(StandardMaterial {
316                base_color_texture: Some(
317                    asset_server
318                        .load_builder()
319                        .with_settings::<ImageLoaderSettings>(|settings| {
320                            settings
321                                .sampler
322                                .get_or_init_descriptor()
323                                .set_address_mode(ImageAddressMode::Repeat);
324                        })
325                        .load("textures/uv_checker_bw.png"),
326                ),
327                perceptual_roughness: 0.9,
328                ..default()
329            }),
330        ),
331        Transform::from_xyz(0.0, 0.0, 1.5),
332    ));
333
334    let neutral = materials.add(StandardMaterial {
335        base_color: Color::srgb(0.55, 0.54, 0.52),
336        perceptual_roughness: 0.9,
337        ..default()
338    });
339
340    for (z, normal) in [(-9.0, Vec3::Z), (12.0, Vec3::NEG_Z)] {
341        let wall = meshes.add(raytraced(Plane3d::new(normal, Vec2::new(9.0, 4.0))));
342        commands.spawn((
343            RaytracingMesh3d(wall.clone()),
344            Mesh3d(wall),
345            MeshMaterial3d(neutral.clone()),
346            Transform::from_xyz(0.0, 4.0, z),
347        ));
348    }
349
350    for (x, normal, tint) in [
351        (-9.0, Vec3::X, Color::srgb(0.6, 0.25, 0.22)),
352        (9.0, Vec3::NEG_X, Color::srgb(0.22, 0.3, 0.6)),
353    ] {
354        let wall = meshes.add(raytraced(Plane3d::new(normal, Vec2::new(4.0, 10.5))));
355        commands.spawn((
356            RaytracingMesh3d(wall.clone()),
357            Mesh3d(wall),
358            MeshMaterial3d(materials.add(StandardMaterial {
359                base_color: tint,
360                perceptual_roughness: 0.9,
361                ..default()
362            })),
363            Transform::from_xyz(x, 4.0, 1.5),
364        ));
365    }
366
367    let ceiling = meshes.add(raytraced(Plane3d::new(Vec3::NEG_Y, Vec2::splat(10.5))));
368    commands.spawn((
369        RaytracingMesh3d(ceiling.clone()),
370        Mesh3d(ceiling),
371        MeshMaterial3d(neutral),
372        Transform::from_xyz(0.0, 8.0, 1.5),
373    ));
374
375    let lamp = meshes.add(raytraced(Plane3d::new(Vec3::NEG_Y, Vec2::splat(1.75))));
376    commands.spawn((
377        RaytracingMesh3d(lamp.clone()),
378        Mesh3d(lamp),
379        MeshMaterial3d(materials.add(StandardMaterial {
380            emissive: LinearRgba::rgb(40000.0, 38000.0, 34000.0),
381            ..default()
382        })),
383        Transform::from_xyz(0.0, 7.8, 0.5),
384    ));
385}
examples/3d/solari.rs (line 254)
203fn setup_many_lights(
204    mut commands: Commands,
205    asset_server: Res<AssetServer>,
206    mut meshes: ResMut<Assets<Mesh>>,
207    mut materials: ResMut<Assets<StandardMaterial>>,
208    args: Res<Args>,
209    #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] dlss_rr_supported: Option<
210        Res<DlssRayReconstructionSupported>,
211    >,
212) {
213    let mut rng = ChaCha8Rng::seed_from_u64(42);
214
215    let mut plane_mesh = Plane3d::default()
216        .mesh()
217        .size(400.0, 400.0)
218        .build()
219        .with_generated_tangents()
220        .unwrap();
221    match plane_mesh.attribute_mut(Mesh::ATTRIBUTE_UV_0).unwrap() {
222        VertexAttributeValues::Float32x2(items) => {
223            items.iter_mut().flatten().for_each(|x| *x *= 3.0);
224        }
225        _ => unreachable!(),
226    }
227    let plane_mesh = meshes.add(plane_mesh);
228    let cube_mesh = meshes.add(
229        Cuboid::default()
230            .mesh()
231            .build()
232            .with_generated_tangents()
233            .unwrap(),
234    );
235    let sphere_mesh = meshes.add(
236        Sphere::new(1.0)
237            .mesh()
238            .build()
239            .with_generated_tangents()
240            .unwrap(),
241    );
242
243    commands
244        .spawn((
245            RaytracingMesh3d(plane_mesh.clone()),
246            MeshMaterial3d(
247                materials.add(StandardMaterial {
248                    base_color_texture: Some(
249                        asset_server
250                            .load_builder()
251                            .with_settings::<ImageLoaderSettings>(|settings| {
252                                settings
253                                    .sampler
254                                    .get_or_init_descriptor()
255                                    .set_address_mode(ImageAddressMode::Repeat);
256                            })
257                            .load("textures/uv_checker_bw.png"),
258                    ),
259                    perceptual_roughness: 0.0,
260                    ..default()
261                }),
262            ),
263        ))
264        .insert_if(Mesh3d(plane_mesh), || args.pathtracer != Some(true));
265
266    for _ in 0..8000 {
267        commands
268            .spawn((
269                RaytracingMesh3d(cube_mesh.clone()),
270                MeshMaterial3d(materials.add(StandardMaterial {
271                    base_color: Color::srgb(rng.random(), rng.random(), rng.random()),
272                    perceptual_roughness: rng.random(),
273                    ..default()
274                })),
275                Transform::default()
276                    .with_scale(Vec3 {
277                        x: rng.random_range(0.2..=2.0),
278                        y: rng.random_range(0.2..=2.0),
279                        z: rng.random_range(0.2..=2.0),
280                    })
281                    .with_translation(Vec3::new(
282                        rng.random_range(-180.0..=180.0),
283                        0.2,
284                        rng.random_range(-180.0..=180.0),
285                    )),
286            ))
287            .insert_if(Mesh3d(cube_mesh.clone()), || args.pathtracer != Some(true));
288    }
289
290    for x in -10..=10 {
291        for y in -10..=10 {
292            commands
293                .spawn((
294                    RaytracingMesh3d(sphere_mesh.clone()),
295                    MeshMaterial3d(
296                        materials.add(StandardMaterial {
297                            emissive: Color::linear_rgb(
298                                rng.random::<f32>() * 60000.0,
299                                rng.random::<f32>() * 60000.0,
300                                rng.random::<f32>() * 60000.0,
301                            )
302                            .into(),
303                            ..default()
304                        }),
305                    ),
306                    Transform::default().with_translation(Vec3::new(
307                        (x * 20) as f32,
308                        7.0,
309                        (y * 20) as f32,
310                    )),
311                ))
312                .insert_if(Mesh3d(sphere_mesh.clone()), || {
313                    args.pathtracer != Some(true)
314                });
315        }
316    }
317
318    let mut camera = commands.spawn((
319        Camera3d::default(),
320        Camera {
321            clear_color: ClearColorConfig::Custom(Color::BLACK),
322            ..default()
323        },
324        FreeCamera {
325            walk_speed: 3.0,
326            run_speed: 10.0,
327            ..Default::default()
328        },
329        Transform::from_translation(Vec3::new(6.11329, 166.74896, 451.8226)).with_rotation(
330            Quat::from_xyzw(-0.183938, 0.009093744, 0.0017017953, 0.9828943),
331        ),
332        // Msaa::Off and CameraMainTextureUsages with STORAGE_BINDING are required for Solari
333        CameraMainTextureUsages::default().with(TextureUsages::STORAGE_BINDING),
334        Msaa::Off,
335        Bloom {
336            intensity: 0.1,
337            ..Bloom::NATURAL
338        },
339    ));
340
341    if args.pathtracer == Some(true) {
342        camera.insert(Pathtracer::default());
343    } else {
344        camera.insert(SolariLighting::default());
345    }
346
347    // Using DLSS Ray Reconstruction for denoising (and cheaper rendering via upscaling) is _highly_ recommended when using Solari
348    #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))]
349    if dlss_rr_supported.is_some() {
350        camera.insert(Dlss::<DlssRayReconstructionFeature>::default());
351    }
352
353    commands.spawn((
354        ControlText,
355        Text::default(),
356        Node {
357            position_type: PositionType::Absolute,
358            bottom: px(12.0),
359            left: px(12.0),
360            ..default()
361        },
362    ));
363
364    commands.spawn((
365        Node {
366            position_type: PositionType::Absolute,
367            right: px(0.0),
368            padding: px(4.0).all(),
369            border_radius: BorderRadius::bottom_left(px(4.0)),
370            ..default()
371        },
372        BackgroundColor(Color::srgba(0.10, 0.10, 0.10, 0.8)),
373        children![(
374            PerformanceText,
375            Text::default(),
376            TextFont {
377                font_size: FontSize::Px(8.0),
378                ..default()
379            },
380        )],
381    ));
382}

Trait Implementations§

Source§

impl Clone for ImageSampler

Source§

fn clone(&self) -> ImageSampler

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ImageSampler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for ImageSampler

Source§

fn default() -> ImageSampler

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ImageSampler

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ImageSampler, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Enum for ImageSampler

Source§

fn field(&self, __name_param: &str) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field (in the current variant) with the given name. Read more
Source§

fn field_at( &self, __index_param: usize, ) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field (in the current variant) at the given index.
Source§

fn field_mut( &mut self, __name_param: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field (in the current variant) with the given name. Read more
Source§

fn field_at_mut( &mut self, __index_param: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field (in the current variant) at the given index.
Source§

fn index_of(&self, __name_param: &str) -> Option<usize>

Returns the index of the field (in the current variant) with the given name. Read more
Source§

fn name_at(&self, __index_param: usize) -> Option<&str>

Returns the name of the field (in the current variant) with the given index. Read more
Source§

fn iter_fields(&self) -> VariantFieldIter<'_> ⓘ

Returns an iterator over the values of the current variant’s fields.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the current variant.
Source§

fn variant_name(&self) -> &str

The name of the current variant.
Source§

fn variant_index(&self) -> usize

The index of the current variant.
Source§

fn variant_type(&self) -> VariantType

The type of the current variant.
Source§

fn to_dynamic_enum(&self) -> Result<DynamicEnum, ReflectCloneError>

Creates a new DynamicEnum from this enum. Read more
Source§

fn is_variant(&self, variant_type: VariantType) -> bool

Returns true if the current variant’s type matches the given one.
Source§

fn variant_path(&self) -> String

Returns the full path to the current variant.
Source§

fn get_represented_enum_info(&self) -> Option<&'static EnumInfo>

Will return None if TypeInfo is not available.
Source§

impl FromArg for ImageSampler

Source§

type This<'from_arg> = ImageSampler

The type to convert into. Read more
Source§

fn from_arg( arg: Arg<'_>, ) -> Result<<ImageSampler as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromReflect for ImageSampler

Source§

fn from_reflect( __param0: &(dyn PartialReflect + 'static), ) -> Option<ImageSampler>

Constructs a concrete instance of Self from a reflected value.
Source§

fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
Source§

impl GetOwnership for ImageSampler

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetTypeRegistration for ImageSampler

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl IntoReturn for ImageSampler

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where ImageSampler: 'into_return,

Converts Self into a Return value.
Source§

impl PartialEq for ImageSampler

Source§

fn eq(&self, other: &ImageSampler) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialReflect for ImageSampler

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn try_apply( &mut self, __value_param: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<ImageSampler>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn try_into_reflect( self: Box<ImageSampler>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>

Attempts to cast this type to a boxed, fully-reflected value.
Source§

fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>

Attempts to cast this type to a fully-reflected value.
Source§

fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>

Attempts to cast this type to a mutable, fully-reflected value.
Source§

fn into_partial_reflect(self: Box<ImageSampler>) -> Box<dyn PartialReflect>

Casts this type to a boxed, reflected value. Read more
Source§

fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)

Casts this type to a reflected value. Read more
Source§

fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)

Casts this type to a mutable, reflected value. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

fn reflect_partial_cmp( &self, value: &(dyn PartialReflect + 'static), ) -> Option<Ordering>

Returns a “partial comparison” result. Read more
Source§

fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Debug formatter for the value. Read more
Source§

fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>

Attempts to clone Self using reflection. Read more
Source§

fn apply(&mut self, value: &(dyn PartialReflect + 'static))

Applies a reflected value to this value. Read more
Source§

fn to_dynamic(&self) -> Result<Box<dyn PartialReflect>, ReflectCloneError>

Converts this reflected value into its dynamic representation based on its kind. Read more
Source§

fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
where T: 'static, Self: Sized + TypePath,

For a type implementing PartialReflect, combines reflect_clone and take in a useful fashion, automatically constructing an appropriate ReflectCloneError if the downcast fails.
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl Reflect for ImageSampler

Source§

fn into_any(self: Box<ImageSampler>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any. Read more
Source§

fn into_reflect(self: Box<ImageSampler>) -> Box<dyn Reflect>

Casts this type to a boxed, fully-reflected value.
Source§

fn as_reflect(&self) -> &(dyn Reflect + 'static)

Casts this type to a fully-reflected value.
Source§

fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)

Casts this type to a mutable, fully-reflected value.
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

impl Serialize for ImageSampler

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ImageSampler

Source§

impl TypePath for ImageSampler

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
Source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for ImageSampler

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Brush for T
where T: Clone + PartialEq + Default + Debug,

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> DynamicTypePath for T
where T: TypePath,

Source§

impl<T> DynamicTyped for T
where T: Typed,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromTemplate for T
where T: Clone + Default + Unpin,

Source§

type Template = T

The Template for this type.
Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

Source§

fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
Source§

fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
Source§

fn path<'p, T>( &self, path: impl ReflectPath<'p>, ) -> Result<&T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
Source§

fn path_mut<'p, T>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> HitDataExtra for T
where T: Send + Sync + Debug + Any + 'static,

Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<G> PatchFromTemplate for G
where G: FromTemplate,

Source§

type Template = <G as FromTemplate>::Template

The Template that will be patched.
Source§

fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
where F: FnOnce(&mut <G as PatchFromTemplate>::Template, &mut ResolveContext<'_>),

Takes a “patch function” func, and turns it into a TemplatePatch.
Source§

impl<T> PatchTemplate for T
where T: Template,

Source§

fn patch_template<F>(func: F) -> TemplatePatch<F, T>
where F: FnOnce(&mut T, &mut ResolveContext<'_>),

Takes a “patch function” func that patches this Template, and turns it into a TemplatePatch.
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Reflectable for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> Template for T
where T: Clone + Unpin,

Source§

type Output = T

The type of value produced by this Template.
Source§

fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>

Uses this template and the given entity context to produce a Template::Output.
Source§

fn clone_template(&self) -> T

Clones this template. See Clone.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of self.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more