Implement glTF COLOR_0 vertex color support in StandardMaterial and UnlitMaterial - #618
Implement glTF COLOR_0 vertex color support in StandardMaterial and UnlitMaterial#618ind4x wants to merge 4 commits into
Conversation
|
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. |
footballhead
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
However, I'm encountering a validation layer error on Linux. When I run vk_gltf_basic_materials with the validation layers enabled, I ecounter the following assertion:
*** VULKAN VALIDATION ERROR MESSAGE ***
Severity : ERROR
Type : [VALIDATION]
Objects : [0]: <UNNAMED OBJECT>
Message : vkCreateGraphicsPipelines(): pCreateInfos[0].pVertexInputState->pVertexAttributeDescriptions does not have a Location 4 but vertex shader has an input variable at that Location. (This can be valid if either the vertexAttributeRobustness or maintenance9 feature is enabled).
The Vulkan spec states: If the vertexAttributeRobustness feature is not enabled, and the maintenance9 feature is not enabled, and the pipeline is being created with vertex input state and pVertexInputState is not dynamic, then all variables with the Input storage class decorated with Location in the Vertex Execution Model OpEntryPoint must contain a location in VkVertexInputAttributeDescription::location (https://vulkan.lunarg.com/doc/view/1.4.335.0/linux/antora/spec/latest/chapters/pipelines.html#VUID-VkGraphicsPipelineCreateInfo-Input-07904)
The primary consumer of the scene loader is the gltf_basic_materials sample; I've added instructions for running it in #621. What results are you seeing?
| // Process vertex data | ||
| for (cgltf_size i = 0; i < gltflAccessors.pPositions->count; ++i) { | ||
| TriMeshVertexData vertexData = {}; | ||
| vertexData.color = glm::float3(1, 1, 1); |
There was a problem hiding this comment.
This file needs to be formatted with clang-format-16. Alternatively, the clang-format GitHub action includes a diff in its log that can be applied in order to format.
Address the Vulkan validation error reported when running vk_gltf_basic_materials: the scene-renderer pipeline is built from the shared MaterialVertex vertex shader which (with vertex color support) declares an input at Location 4, but the loader was still forcing `bits.colors = false`, so the pipeline never received a matching vertex attribute description. - Stop disabling vertex colors in GltfLoader::LoadMeshInternal so the material-requested COLOR_0 attribute (Location 4) is actually loaded. - Drop the overly strict color-format assert in LoadMeshData. COLOR_0 is valid as VEC3/VEC4 with float or normalized component types; the unpack helpers already convert components to floats via cgltf_accessor_unpack_floats. - Request vertex colors from UnlitMaterial since its shader now multiplies the base color by input.Color. - clang-format-16 pass over the changed sources.
|
Thanks for the review! I tracked down the validation error and fixed it, and ran clang-format-16 on the changed files. The Location 4 validation errorThe root cause is that the scene renderer builds every pipeline from the single shared This PR now:
Please let me know if you still see the validation error or would prefer a different structure. |
Description
Implement glTF COLOR_0 vertex color support in the scene renderer.
According to the glTF 2.0 specification (Section 3.9.2):
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
vertex input to the pixel shader.
input.Color.
glTF vertex color formats.
preventing unintended darkening.
Verification Results
These changes enable correct rendering for several glTF-Sample-Assets, including: