Skip to content

Implement glTF COLOR_0 vertex color support in StandardMaterial and UnlitMaterial#618

Open
yss-ef wants to merge 1 commit intogoogle:mainfrom
yss-ef:main
Open

Implement glTF COLOR_0 vertex color support in StandardMaterial and UnlitMaterial#618
yss-ef wants to merge 1 commit intogoogle:mainfrom
yss-ef:main

Conversation

@yss-ef
Copy link
Copy Markdown

@yss-ef yss-ef commented May 1, 2026


Description

Implement glTF COLOR_0 vertex color support in the scene renderer.

According to the glTF 2.0 specification (Section 3.9.2):

In addition to the material properties, if a primitive specifies a vertex color using the attribute
semantic property COLOR_0, then this value acts as an additional linear multiplier to base color.

Previously, while GltfLoader would load the COLOR_0 accessor, the data was not being utilized by the
StandardMaterial or UnlitMaterial shaders. This PR enables the vertex color attribute across the scene
renderer's shader pipeline and applies it as a linear multiplier to the base color.

Problem

Vertex colors provided in glTF assets were being ignored during shading, resulting in incorrect
rendering for models that rely on COLOR_0 for tinting, baked effects, or specific material tests.

Solution

  1. Shader Pipeline Updates:
    • Modified MaterialVertex.hlsl to define ENABLE_VTX_ATTR_COLOR and pass the color attribute from
      vertex input to the pixel shader.
    • Updated StandardMaterial.hlsl and UnlitMaterial.hlsl to multiply the calculated baseColor by
      input.Color.
  2. GltfLoader Enhancements:
    • Updated GltfLoader::LoadMeshData in scene_gltf_loader.cpp to correctly handle both VEC3 and VEC4
      glTF vertex color formats.
    • Ensured the default vertex color is set to white (1, 1, 1) when the attribute is missing,
      preventing unintended darkening.
  3. Debug Support:
    • Added DBG_VTX_ATTR_INDEX_COLOR to MaterialInterface.hlsli.
    • Updated DebugMaterial.hlsl to allow visualizing vertex colors for debugging purposes.

Verification Results

These changes enable correct rendering for several glTF-Sample-Assets, including:

  • BoxVertexColor
  • CompareBaseColor
  • IridescentDishWithOlives
  • PrimitiveModeNormalsTest
  • RecursiveSkeleton
  • SheenWoodLeatherSofa
  • VertexColorTest

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 1, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@yss-ef yss-ef closed this May 1, 2026
@yss-ef yss-ef reopened this May 1, 2026
@yss-ef yss-ef closed this May 1, 2026
@yss-ef yss-ef reopened this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant