Skip to main content

Module paint

Module paint 

Source
Expand description

Texture painting: blend several surface textures with a painted mask, so dirt can be brushed along a road edge and fade into grass without a hard seam.

A TexturePaint component names four layer textures and a mask. The mask is an RGBA image: red, green and blue are the weights of layers 2, 3 and 4; whatever is left is layer 1. The editor’s brush edits the mask in memory (PaintMaps) and saves it to assets/paint/<name>.png.

use kvas_engine::paint::{PaintMaps, BrushMode};
let maps = PaintMaps::global();
maps.create("doc-example", 32, 32);
maps.brush("doc-example", [0.5, 0.5], 0.2, 1.0, 0.5, BrushMode::Layer(1));
let (_, rgba, _) = maps.snapshot("doc-example").unwrap();
assert!(rgba[(16 * 32 + 16) * 4] > 200); // the red channel (layer 2) at the centre

Structs§

PaintMap
One painted mask kept in memory.
PaintMaps
All painted masks of the running editor / game, by name.
TexturePaint
Four textures blended by a painted mask. Put it on an object with a mesh (a plane, a terrain chunk, a road strip). The component takes over the object’s material.

Enums§

BrushMode
What the brush does.

Constants§

PAINT_PREFIX
Prefix of the mask texture keys the renderer understands (paint:<name>#<version>).
SPLAT_PREFIX
Prefix of the layer atlas keys (splat:<a>|<b>|<c>|<d>).

Functions§

paint_key
Texture key of a mask at its current version (changes with every edit so the GPU copy refreshes).
update
Keeps the material of every painted object in sync with its component and mask.