#mesh #bevy #scene #graphics #pixelation #pixelate

pixelate_mesh

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

3 releases (breaking)

0.3.0 Feb 18, 2024
0.2.0 Jan 22, 2024
0.1.0 Mar 13, 2023

#220 in Rendering

24 downloads per month

MIT/Apache

37KB
578 lines

Pixelate Mesh

crates.io docs.rs

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

Pixelated foxes

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.

Compatibility

bevy pixelate_mesh
0.13 0.3
0.12 0.2
0.10 0.1

Examples

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_plugin(PixelateMeshPlugin::<MainCamera>::default())
        .add_systems(Startupsetup)
        .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(shape::Cube { size: 1.0 })),
            material: materials.add(Color::WHITE.into()),
            ..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()
        },
    ));
}

Inspiration

The plugin tries to emulate the effect as seen in Prodeus:
Source

Shortcomings

  • The current setup does not work with multiple main cameras. Feel free to comment on the issue if you have an idea for how to fix this!
  • The plugin deactivates MSAA globally.

Dependencies

~46–88MB
~1.5M SLoC