Flat shade glTF primitives without vertex normals - #9193
Merged
Conversation
The glTF spec requires flat normals to be used when a primitive omits the NORMAL attribute, but the engine generated smooth ones instead, averaging each face normal across the shared vertices. Such primitives now get Material#flatShading enabled, on a clone of their material so that primitives which do supply normals are unaffected. The smooth normals are still generated for the vertex buffer, so the previous rendering can be restored by setting flatShading back to false. Also regenerates the PrimitiveModeNormalsTest sample asset, whose previous conversion had lost the COLOR_0 and NORMAL attributes of its line strips, and replaces the example's copy-pasted clear coat description.
Build size reportThis PR changes the size of the minified bundles.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The glTF spec requires that a primitive which omits the NORMAL attribute is rendered with flat normals (§3.7.2.1, Meshes → Overview). The engine instead generated smooth normals for it, averaging each face normal across the shared vertices, so such meshes rendered smooth.
Those primitives now get
Material#flatShadingenabled, which resolves the non-compliance while building on the flat shading added in #9191.Note this changes how existing content renders: a mesh which relies on the engine's generated normals becomes faceted. The generated smooth normals are deliberately still produced, so the previous rendering is fully recoverable by setting
flatShadingback to false - either at runtime, or at load time through the existingmaterial.postprocesscontainer asset option.Changes:
KHR_materials_variantsmappings as well as the default materialExamples:
test/primitive-mode- the description was a copy of the clear coat example's and has been replaced with one describing what the example actually showsPrimitiveModeNormalsTest.glbregenerated from the current Khronos sample. The previous conversion was lossy: every LINE_STRIP mesh had lost its COLOR_0 and NORMAL attributes, and triangle COLOR_0 had been de-quantized to float. The sample's labels and vertex colours now renderPerformance:
This is what we get:

And this is what the gltf expects:
