Builtin Library
- ..
- .metadata354 B
- README.md1.7 KB
- mat.yaml553 B
- preview.png32.4 KB
README.md
Instance Color
A lit white surface that every instance wearing it colours from its own
shader-data lane 2, built on @builtin::shaders.pbr with
instance_color_lane = 2. One material draws hundreds of members in hundreds of
colours, and a colour that changes every frame costs one
renderer.instanceData.set per member: a stress map over a bridge, a heat map,
a damage flash, team colours, a selection highlight, a gauge.
local LANE = 2
for i, id in members do
local load = loads[i] -- 0 relaxed .. 1 at its limit
renderer.instanceData.set(id, LANE, load, 1 - load, 0, 1) -- green to red, fully covered
end
The lane's rgb is the colour and its a is how much of it covers the base
colour and the emission, 0 none through 1 all; an instance whose lane was never
written reads zero and draws plain white. The colour replaces the base colour
before lighting, so the member still shades, casts its highlights and shows the
lane colour in the albedo capture pass. Set instance_emission above 0 for a
colour that glows where it covers.
renderer.mesh.drawInstanced reads the same lane from its
instanceDataBuffer, so a GPU-filled population colours each copy the same
way. The writes are local to the engine that makes them and replicate nothing;
Model.tint is the synced form of a tint, for a colour every participant
must see.
Inputs
floats.instance_color_lane(2): the lane read; lanes 0 and 1 carry a baked lightmap's rect and layer.floats.instance_emission(0): how brightly the lane colour glows.colors.base_color(white),floats.roughness(0.5),floats.metallic(0): the surface under the lane colour.