question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarification with "Color_0" vertex attribute accessor byte length.

See original GitHub issue

Hi

I’ve been testing the new 0.6.1 assets collection, and I’ve found some assets in the “positive” directory that I think are invalid.

Specifically, the one located at Positive/Buffer_Interleaved/Buffer_Interleaved_01.gltf

It is true that the specification says valid values for the Color_0 attribute are:

Name Accessor Type(s) Component Type(s) Description
COLOR_0 "VEC3"
"VEC4"
5126 (FLOAT)
5121 (UNSIGNED_BYTE) normalized
5123 (UNSIGNED_SHORT) normalized
RGB or RGBA vertex color

But also I had the understanding that any attribute byte length was required to be multiple of 4 bytes, thus, UNSIGNED_BYTE and UNSIGNED_SHORT encodings can only be used with VEC4 colors, and VEC3 can only be used with FLOAT encoding.

Buffer_Interleaved_01.gltf Uses a VEC3 x UNSIGNED_BYTE attribute, which produces a 3 bytes stride.

I undertand that the BufferView’s ByteStride already pads the vertex length with the missing byte so the whole vertex length is multiple of 4, but… could not have been better to enforce VEC4 color anyway?

I’ve noticed glTF validator also passes this one as good…

So, should I interpret that vertex attributes can indeed be defined with odd lengths, and let the ByteStride padding do the work?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lexaknyazevcommented, Apr 17, 2019

should I interpret that vertex attributes can indeed be defined with odd lengths, and let the ByteStride padding do the work?

Yes. Graphics APIs usually take byte offset, stride, and attribute format, so length is handled implicitly.

could not have been better to enforce VEC4 color anyway?

While it is the same layout in terms of alignment, VEC3 type signals that per-vertex colors do not contain alpha.

there is a scenario …

Interleaving like 3/3/2 is not allowed in the core spec, because each attribute must start at 4-byte boundaries. An extension could relax this in the future.

1reaction
bghgarycommented, Apr 17, 2019

should I interpret that vertex attributes can indeed be defined with odd lengths, and let the ByteStride padding do the work?

Yes, there is a scenario where this is useful for interleaving data, though it’s not possible without an extension right now. For example, if you have COLOR_0 (byte vec3), COLOR_1 (byte vec3), and uv0 (byte vec2). This has a stride of 8. If we enforced vec4 color, then this would have a byte stride of 12.

cc @lexaknyazev to double check me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is BufferView.Target optional? · Issue #1440
It means byte-distance between consequential elements. This field is defined only for buffer views that contain vertex attributes." There's a ...
Read more >
What is the most efficient way to store/pass color values ...
According to the documentation of glVertexAttribPointer you have to set the normalize parameter to let the bytes be scaled to the range 0.0...
Read more >
Vertex Specification - OpenGL Wiki
Each attribute index represents a vector of some type, from 1 to 4 components in length. The size​ parameter of the glVertexAttribPointer ...
Read more >
Vertex Specification Best Practices - OpenGL Wiki
Take advantage of the ability to use signed/unsigned normalized shorts and bytes, as well as other specialized formats.
Read more >
Is it possible to create minimal glTF files with vertex and ...
I am currently looking into glTF to use as a transfer format for my WebGL project. I already have the geometries I wish...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found