Skip to content

Support model vertex colors #16743

@appgurueu

Description

@appgurueu

Problem

Most model file formats, and all the formats we support (.b3d, .obj, .gltf / .glb, .x), support vertex colors, however we do not. For nodes, we overwrite colors with lighting information. For objects, we mostly overwrite colors with all white.

It is possible to bake colors into textures, which is why colors are not strictly necessary. However, it would still be nice to have colors for a couple reasons:

  • Models with colors just work, no extra steps, just grab the file.
  • Color-only mesh buffers are easy to optimize (e.g. by batching or instancing) since no textures need to be bound in-between. (Array textures offer a decent alternative though.)
  • Colors offer an interesting target for morph animations. See also Add glTF morph animation support (PoC) #16096.

For the last point specifically, I have a dream: That one day, we will be able to render an animated hue-manatee in Luanti. Generally I think vertex color animations are quite an interesting and flexible tool, e.g. for "shine" or "glow" effects.

Hue-manatee

Solutions

Colors are already there as a vertex attribute, we just need to refrain from overwriting them; we should make sure the readers set them properly.

As for node lighting, I see two options. One is to add new vertex attributes for lights. This is probably the cleanest option and if I recall correctly, would also allow the resumption of #14343. The other is to just premultiply.

Alternatives

Textures. Even the hue-manatee is possible using an appropriately animated texture, but it won't be smooth without SSCSM, and even with SSCSM it would be wasteful (as you'd not be doing the coloring in hardware / need many textures to swap), or you'd have to hackily use morph animation of texture coordinates.

Additional context

The .x and .b3d readers seem to read colors properly and the .obj reader sets colors based on materials (this might need tweaking). The gltf reader at the moment does not read colors, but this is easily implemented.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions