-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InterleavedBuffer: Improve example and docs #12790
Conversation
docs/api/core/InterleavedBuffer.html
Outdated
@@ -11,21 +11,34 @@ | |||
<h1>[name]</h1> | |||
|
|||
<div class="desc"> | |||
"Interleaved" means that multiple types of data (position, color etc.) are packed into a single array buffer. | |||
Organizing geometry data in this way improves memory locality. By keeping vertex data close together, it is more likely | |||
that also caches (e.g. pre-transform vertex cache) store logically related data together. This leads to more cache hits and a better performance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR, but maybe you can rephrase or remove these two sentences...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make a suggestion for an alternative? I thought it might be a good Idea to highlight the primary motivation for using interleaved buffers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write it this way:
"Interleaved" means that multiple attributes, possibly of different types, (e.g., position, normal, uv, color) are packed into a single array buffer.
I would leave it at that and avoid a tutorial. Also, avoid making performance claims.
I thought it might be a good Idea to highlight the primary motivation for using interleaved buffers.
What is your reference for the last two sentences? Is that the "primary motivation"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, i updated the docs with your suggestion. It's okay for me to exclude the other stuff. (For a moment i forgot to focus just on docs and not tutorials 😇).
What is your reference for the last two sentences? Is that the "primary motivation"?
It is mentioned in this literature , Chapter 3, Interleaving your vertex data for improved performance.
From a performance point of view, the preferred way to organize your vertex data is to interleave the data as an array of structures. This is because you get better memory locality for your vertex data. It is likely that when a vertex shader needs the position of a certain vertex, it will also need the normal and texture coordinates for the same vertex at almost the same time. By keeping these coordinates close together in the memory, it is more likely that when one is read into the pre-transform vertex cache, the others will also be read in the same block and will be available in the pre-transform vertex cache when they are needed by the vertex shader.
Well, "primary motivation" is actually my personal wording 😉 . But i think it's okay to say that performance is the main reason when people interleaving vertex data.
docs/api/core/InterleavedBuffer.html
Outdated
<h2>Constructor</h2> | ||
<h3>[name]( [page:TypedArray array], [page:Integer stride] )</h3> | ||
<div> | ||
[page:TypedArray array] -- A typed array with a shared buffer. Stores the geometry data.<br/> | ||
[page:Integer stride] -- How far apart is the start of each vertex. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How far apart is the start of each vertex
This is worded as a question - can you change it to something like: "The distance between the start of each vertex" or "How far apart the start of each vertex is"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now 😊
docs/api/core/InterleavedBuffer.html
Outdated
</div> | ||
|
||
<h3>[property:Integer stride]</h3> | ||
<div> | ||
How far apart is the start of each vertex. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
@looeee looks good? |
He approved already 😊 #12790 (comment) |
I'm still waiting on a reply... The definition of |
I'm sry, i've missed that. How about:
|
Check the WebGL docs for the definition of /ping @benaadams |
Sry, but i can't find your guess. Am i blind now? I would say that the description should be okay now. We are not defining the see https://github.com/mrdoob/three.js/blob/dev/src/renderers/WebGLRenderer.js#L914 |
Well. its not necessary the amount of vertex data - but how much to jump from the start of one vertex data to get to the next. e.g. the increment you'd have on a |
Usually it will be the amount of data per vertex :) |
I'll pick your definition. I always struggle with this stuff 😅 |
Whatever I posted is gone... :/ It was something like:
That means it is unitless. This definition should be improved further. Maybe someone can come up with something better. |
I vote for merging the PR. We can still add a more precise definition of |
I would define
|
Great! I'll make a commit 😊 |
Done! 👍 |
docs/api/core/InterleavedBuffer.html
Outdated
<h2>Constructor</h2> | ||
<h3>[name]( [page:TypedArray array], [page:Integer stride] )</h3> | ||
<div> | ||
[page:TypedArray array] -- A typed array with a shared buffer. Stores the geometry data.<br/> | ||
[page:Integer stride] -- How far apart the start of each vertex is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How far apart the start of each vertex is.
Can you please check the source code and see if you can verify that the following description is correct?...
The number of elements between the beginning of consecutive vertex attributes.
stride = [ number of bytes between the beginning of consecutive vertex attributes ] / [ bytesPerElement ]
Maybe that description can be reworded, simplified, or corrected, if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, now i see your original post about stride
. I guess you did not submit the review and therefore the post was not visible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mugen87 Yeah, this is all messed up...
var ibp = new THREE.InterleavedBuffer( interleaved_buffer_float32, 4 ); | ||
var ibc = new THREE.InterleavedBuffer( interleaved_buffer_uint8, 16 ); | ||
var interleavedPositionBuffer = new THREE.InterleavedBuffer( interleavedFloat32Buffer, 4 ); | ||
var interleavedColorBuffer = new THREE.InterleavedBuffer( interleavedUint8Buffer, 16 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not the "position" and "color" buffers. It would be better to call them interleavedBuffer32
and interleavedBuffer8
.
That would become more clear if, for example, there was also normal and uv data in addition to position data. That is, if this example had additional Float32 attributes, you would not refer to the buffer as the "position buffer", because it would contain normal and uv data, too.
For sake of clarity, I would use the names I suggested -- or something similar to those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. I'll pick your suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Thanks!
I think this PR is OK, now. |
Thanks! |
As the title suggests, a small improvement of docs and example.