-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
WebGL2: Added support for Uniform Buffer Objects. #15562
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
Conversation
|
Looking good! How about |
This comment has been minimized.
This comment has been minimized.
|
BTW: Thanks to @Alejandro_Insua from the forum for already testing this feature 👍 |
I've realized that we already have |
| // the following two properties will be used for partial buffer updates | ||
|
|
||
| uniform.__data = new Float32Array( info.storage / Float32Array.BYTES_PER_ELEMENT ); | ||
| uniform.__offset = offset; |
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.
Honestly I don't think spoiling uniform with __xxx properties is a clean approach. But I think it's ok so far. Let's clean up later 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.
May I ask why you don't like this approach?^^
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.
For example, those properties are unnecessarily exposed to other modules which can access uniform (tho the property names begin with __ indicating it's private).
|
Nice job @Mugen87 with this one. One probably obvious question that probably must be addressed in another PR instead of this one, is what about adding uniform support to the standard materials as most of the devs will be using them instead of custom ones, so we could really get the benefits of UBO in all the apps around |
|
He mentioned
I'm making a test evaluating the performance if built-in material supports UBO. I'll share the result later. |
|
Ops I totally misread that part :D |
You are right, that's of course the long-term goal^^. But let's do it step by step. This PR should be (hopefully) a good basis for further enhancements. And we enable devs like @Alejandro_Insua to use UBOs in their custom shaders. |
|
|
||
| return this; | ||
|
|
||
| }, |
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.
Do you think some users may want to change the name runtime?
If I understand correctly name is required. And if we can think it's immutable, what do you think of taking name argument as constructor parameter and removing .setName()?
var group = new THREE.UniformsGroup( 'ViewData' );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.
Do you think some users may want to change the name runtime?
Maybe, although that would actually not make sense. It's like adding uniforms at runtime which would also be an invalid operation. Still, I think the current interface is cleaner than defining everything as ctor parameters.
I consider UBOs as an advanced WebGL feature so the API does not need to be foolproof from my point of view^^
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 commented some stuffs but I don't think they are big deals. Maybe we can enhance, optimize, and clean up later if needed. This PR is looking good as initial UBO support.
|
I'm evaluating the performance. One feedback so far. Calling |
|
Hi, we Mozilla Hubs wants UBO in Three.js. If the conflicts are resolved, can we get this PR merged? Or is there anything blocking this PR other than the conflicts? |
|
@takahirox I've created a new PR (#21558) since a lot of things have changed over two years. |
This PR enables the usage of Uniform Buffer Objects for
ShaderMaterialandRawShaderMaterialwith WebGL 2. Users who build their own materials can use UBOs in order to manage global uniforms like camera or lighting related data more efficiently.WebGLUniformBlocksencapsulates most parts of the UBO related code. The changes toWebGLRendererare straightforward. At some point, upcoming build-in materials might also useWebGLUniformBlocks.Related: #13700