-
Notifications
You must be signed in to change notification settings - Fork 17
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
Mesh instancing support #15
Comments
I've done some research. It looks like WebGL 1* only supports instancing via Since we need to use attribute arrays instead of an array of uniforms groups to get instancing to work, my guess is that a new function and new shader type will be needed. Something like this: manyEntities :
InstanceShader attributes perInstanceAttributes uniforms varyings
-> Shader {} uniforms varyings
-> Mesh attributes
-> List perInstanceAttributes -- List.length here determines how many instances we draw. Also unlike attributes, perInstanceAttributes will change often.
-> uniforms -- Same data is used for all instances
-> Entity I imagine adding a new shader type is a substantial change. Maybe even requires changes to the compiler. I think it's worthwhile but I imagine it won't be added anytime soon. I haven't worked with WebGL much so someone let me know if I'm totally off track or if there's a better solution. *I'm assuming this package targets WebGL 1 because version 2 isn't supported on Safari or Edge yet. |
@MartinSStewart thanks for investigating this use case! I'm not exactly sure if we should add custom api for each custom use case like this, or we should rather model WebGL api to be lower level than it is now. By the way, there is a post on discourse about rendering particles. I linked to this issue from there. |
Good point. Thanks for the link! |
Both methods for instanced drawing: are well supported now, maybe something like |
@David-Klemenc sorry for the late reply. The functions that you linked to WebGL2, whilst this package only supports WebGL. |
Support for instancing, aka being able to draw the same mesh many times with different uniforms, would be very useful for my project.
Here's an example of my current work around to be able to efficiently draw many instances of a single mesh (I've excluded some details but this is the general idea).
It's very repetative code and if I want a new shader that also draws multiple instances, I need to copy paste this code.
Also while it's faster than making one draw call per instance, having to do the following in the vertex shader is probably expensive.
I admit, I haven't entirely thought out how the elm-webgl API should be modified in order to support instancing. My initial idea is to change the uniform parameter in
entity
to a list. I'm happy to discuss how this might be organized.The text was updated successfully, but these errors were encountered: