-
-
Notifications
You must be signed in to change notification settings - Fork 56
Description
I’ve recently been refactoring the code and logic related to colormap
, colorspace
, vertex color
, and other related components.
Currently, our Materials object has a color_mode
property, which can take values such as uniform
, vertex
, face
, vertex_map
, face_map
, auto
, and debug
. These are enumerations (parallel relationship) that determine the method of obtaining an object’s base color.
Here, there are a few issues:
1. Uniform color、vertex volor and colormap
In Mesh rendering, according to the glTF specification (and generally in 3D rendering practice), "uniform color", "vertex color", and "colormap" are not separate, independent rendering modes; instead, they collectively influence the final diffuse color. In fact, "uniform color" and "vertex color" are factors for the colormap.
The diffuse color equation would be:
diffuse_color = base_color_factor * vertex_color_factor? * sample(colormap)?
- Where
base_color_factor
is theuniform_color (material.color)
, which defaults to (1,1,1). - When vertex data includes color,
vertex_color_factor
is present and takes effect, multiplying with "base_color". (Some engines might also have an additional boolean variable, likeuse_vertex_colors
, to control whether vertex color is used when it exists.) - When a colormap exists, it is sampled and multiplied by "color_factor".
- All color factors should be in linear space.
So I think they should not exist side by side as a "color mode".
2. face and face_map
We've also allowed for face
and face_map
modes, which feels a bit odd. Typically, geometry stores vertex attributes (per-vertex data), which are the inputs to the vertex shader. In our abstraction model and rendering pipeline, there shouldn’t be per-face data. Per-face data in the shader should come from the interpolation of vertex data. In practice, there seem to be very few use cases where per-face data is provided externally. If the goal is to give each face of the mesh a unique color for a "flat" shading effect, WebGPU actually provides a flat interpolation mode for vertex data (options are perspective
, linear
, flat
, with the default being perspective
).