Triplanar Mapping and Material Blending (AKA Splatting) for Bevy Engine
This crate provides the
TriplanarMaterial
, which is based
on bevy_pbr
's StandardMaterial
, but it
supports blending up to 4 materials using array textures and a new
ATTRIBUTE_MATERIAL_WEIGHTS
vertex attribute.
The triplanar material is implemented using the
AsBindGroup
derive macro and
the Material
trait. Most of the magic happens in
the shader code.
Where possible, we reuse shader imports from bevy::pbr
to
implement lighting effects. Sadly there are still some shader functions and
code blocks that are copy-pasted from Bevy; we are hoping to eliminate these
in the future to make this crate easier to maintain.
The new shader code is mostly concerned with how array textures are sampled and blended together. The techniques therein were sourced from the following references:
- Ben Golus, "Normal Mapping for a Triplanar Shader"
- Inigo Quilez, "Biplanar Mapping"
- Colin Barré-Brisebois and Stephen Hill, "Blending in Detail"
- per-layer uniform constants (e.g. "emissive", "metallic", etc.)
- support different texture per plane, using more layers
- blend materials using depth/height map