Support Warning
WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. If they don't work on your configuration, you can check the WebGL2 examples here.pixel_grid_snap.rs:
//! Shows how to create graphics that snap to the pixel grid by rendering to a texture in 2D
use ;
/// In-game resolution width.
const RES_WIDTH: u32 = 160;
/// In-game resolution height.
const RES_HEIGHT: u32 = 90;
/// Default render layers for pixel-perfect rendering.
/// You can skip adding this component, as this is the default.
const PIXEL_PERFECT_LAYERS: RenderLayers = layer;
/// Render layers for high-resolution rendering.
const HIGH_RES_LAYERS: RenderLayers = layer;
/// Low-resolution texture that contains the pixel-perfect world.
/// Canvas itself is rendered to the high-resolution world.
;
/// Camera that renders the pixel-perfect world to the [`Canvas`].
;
/// Camera that renders the [`Canvas`] (and other graphics on [`HIGH_RES_LAYERS`]) to the screen.
;
;
/// Spawns a capsule mesh on the pixel-perfect layer.
/// Rotates entities to demonstrate grid snapping.
/// Scales camera projection to fit the window (integer multiples only).