-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Feature Suggestion: Support Global Uniforms #16922
Comments
just a suggestion but if you go down this path consider using a prefix, like all global properties are named |
I'm not thrilled about this suggestion. It will only work for some cases the way you envision it, but as a result you will be submitting unnecessary uniforms in every "normal" material. Performance hit will not be huge for a couple of uniforms, but there is no justification for it in most of the standard use-cases. |
I should clarify that this would be an entirely optional feature intended for the application developer to have complete control over. THREE should not automagically define global shader uniforms that override material values. This would simply be a tool of convenience to afford more control over how the scene and materials renders and materials would not require that global uniforms be set in order to function. @greggman So in that case any prefixes would be defined as needed by the app developer and there shouldn't be any THREE magic going on. @Usnul I don't see why unnecessary uniforms would have to be set on every material. A uniform should only be set if a material / shader requires it -- certainly the performance shouldn't be a whole lot different than now in that case? |
I guess I mis-understood. I thought you wanted THREE to define some global uniforms It sounds like you rather meant you just want to make it possible for the user to supply global uniforms, so three provides a way to define them but doesn't define any itself. Correct? @Usnul, As for speed, if you're required to set |
Couple of points to that:
One more point to all of that. Say you have a new material that you defined, and you're such a Mr Smarty-Pants that you made use of global uniforms, well, now others can't use your material without explicitly knowing that some of the uniforms are not declared on the shader but are instead pulled from global scope. |
That's right -- I realize I could have been more clear in the original issue so I've updated it a bit. These all depend on the implementation and I think are solve-able problems.
I think that's true but that doesn't mean that every global uniform needs to be uploaded for every material. A global uniform would be updated only if that uniform already exists in the
I'm not sure why it couldn't work for
Again uniforms should not be auto-injected into shaders. This won't require any changes to the existing shaders.
I'm imagining the global uniform being used would need to exist in the Maybe the feature is better described as "uniform overrides"? |
CUS or Cascading Uniform Sheets? I understand what you are saying. If the If you do this kind of an override - the problem is largely the same, you are doing something in one place, and there is an impact somewhere else without a clear trace. In three.js you can use an For you, I would recommend having some kind of a factory for |
Not the solution you were looking for but a 10% solution is to share the values
now there is just one I actually don't know why three.js uniforms are in the form of
And now you have one place to update It's not nearly as convenient as global uniforms would be but at least there is only one place to update. |
Yes this is the big gap in the idea at the moment and without a solution I don't think this would really be viable. Unity, for example, uses a default > global > per-material uniform fallback so if a uniform is defined on a material it uses that otherwise it falls back to the global or a default value for that datatype. Three doesn't have that concept built in so it would need something like an
There are definitely more manual solutions to this problem but I'm writing a framework for other users to quickly and easily write visualizations in and in that case I think there's a utility to things transparently just working. @greggman If there were a way to track all meshes in a scene being rendered then this type of transparent global uniform behavior could be implemented in a non-invasive way. My PR #16934 enables this type of behavior, which I may actually prefer to this idea because it seems more generally useful. Thanks again! |
Nothing has been implemented so there is no reason if it was implemented that local uniforms couldn't override global ones. |
UBOs could be useful for this scenario. #21558 introduced a new API called |
This sound also useful for UBOs look like a great fit for it, but it should also be easy to do in the current state. This is already done on a per-scene basis for things like fog, lights, etc... |
I've been using the Line example in a recent project and I've found the
resolution
uniform onLineMaterial
a bit difficult to work with. It's per-renderer-specific and must be maintained and updated on every LineMaterial if it changes. I know a comment mentions that the renderer could eventually set it but it seems like there could be a general solution to this type of issue.I'm proposing adding a list of global uniforms to the WebGLRenderer that override a given uniform on all materials being rendered:
Other uniforms such as environment maps, time incrementing variables, adn lighting variables could benefit from this pattern, as well. Unity implements something similar using the Shader.SetGlobalFloat() etc functions.
I think my big open questions in the API design would be:
The text was updated successfully, but these errors were encountered: