Crate pixelate_mesh

Source
Expand description

Apply a pixelation effect to any Bevy mesh or scene without post-processing.

§Usage

  • Add the PixelateMeshPlugin, where you specify a component that tracks the main camera.
  • Add this tracking component to your camera.
  • Add the Pixelate component to any entity that you want to pixelate.

The tracking component is needed because the plugin draws the textures on 2D canvases that need to rotate to always face the main camera.

§Example

The following is an annotated minimal example. More can be found in the examples folder.

use bevy::prelude::*;
use pixelate_mesh::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        // Add the plugin
        .add_plugins(PixelateMeshPlugin::<MainCamera>::default())
        .add_systems(Startup, setup)
        .run();
}

// Create a component for the main camera
#[derive(Component)]
struct MainCamera;

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn((
        // This cube will render at 64x64 pixels
        Pixelate::splat(64),
        PbrBundle {
            mesh: meshes.add(Mesh::from(Cuboid::default())),
            material: materials.add(StandardMaterial::from(Color::WHITE)),
            ..default()
        },
    ));

    commands.spawn((
        // Add the tracking component to the camera
        MainCamera,
        Camera3dBundle {
            transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
            ..default()
        },
    ));
}

Modules§

prelude
Everything you need to get started

Structs§

Pixelate
Marks the entity containing a mesh to be pixelated.
PixelateMeshPlugin
The plugin type for this crate. The generic parameter C is the type of the component that tracks the main camera.

Constants§

PIXELATION_RENDER_LAYERS
The render layers used by the plugin. All objects that will be pixelated are rendered on these layers. If you want light to affect them, you need to add the light to the same layers.