-
-
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
WebGLUniformsGroups: Support for array of Uniform Buffer Object #27293
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
src/renderers/WebGLRenderer.js
Outdated
@@ -2091,6 +2091,8 @@ class WebGLRenderer { | |||
|
|||
const group = groups[ i ]; | |||
|
|||
if ( group.uniforms.length === 0 ) continue; |
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 understand you have added this line to prevent a processing from a uniforms group without defined uniforms.
But is this a real use case? Why should a developer setup an instance of UniformsGroup
like that?
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 say that's coming from a bad habits of always wanting to protect most use case even if I don't encounter the issues in my code. But I understand that's not something we would want in threejs as the shader will break if the developer forget to bind the UBO.
Anyway UBOs are something pretty advanced, as you mentioned in the other comment let's wait and see if developers complains.
For the moment I removed it 👍
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.
Also regarding UBOs errors are sometimes misleading.
For example if you forget to bind it in JS it will throw the error GL_INVALID_OPERATION: It is undefined behaviours to use a uniform buffer that is too small.
.
Maybe we can add another PR in the future just to help developers to make it easier to understand.
src/core/UniformsGroup.js
Outdated
// TODO: Should we unbind in the renderer instead? | ||
return; | ||
|
||
} |
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'm not sure we need this kind of validation. IMO, UniformsGroup
should be used like geometries or textures. After the first render, devs should not alter the number of uniforms in their group. If this is required, they can call dispose()
and create a new group.
Changing the layout of uniforms means the shader changes so a call of dispose()
on the respective shader material is required as well.
Make example code more consistent to other demos.
Do you mind removing the build files from the PR? It was a good idea to update the files so it's possible to preview the demo but for the merge it's better to remove them. Side note: I have slightly updated |
Clean up.
The changes in |
That sounds good to me! I would not add further validation checking until devs start requesting such a feature. |
Should be good to go! Next I will try to add |
…ob#27293) * ubo array support * dpr to 1 * update ubo * Update webgl2_ubo_arrays.html Make example code more consistent to other demos. * Update WebGLUniformsGroups.js Clean up. * feedbacks * checkout build folder from dev --------- Co-authored-by: Michael Herzog <[email protected]>
Description:
Support for array of Uniform Buffer Object and included a demo of 51 unique mesh sharing a light UBO consisting of 300 point lights.
The way I implemented is that you can blend arrays of UBOs and simple UBOs among the same Group:
glsl:
js:
Important to know, if we add a size of array of uniform
!==
than the size specified in the shader it will break, which is pretty normal behavior IMO. Should we fill with empty clones or throw a warning somewhere if it's not the case?Next it could be great to add support to
struct
format (doesn't break but driver issues), I added a TODO for another PR.Also I believe there is not Integer support in the UBOs so far, added a TODO for this one so we don't forget.
Preview: https://raw.githack.com/renaudrohlinger/three.js/ubo-patch3/examples/webgl2_ubo_arrays.html