-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
How to render a renderable in different positions of one scene at a time #1513
Comments
We might be able to add a simple instancing feature to gltfio. Out of curiosity how many instances will you be creating, ballpark? Hundreds? Thousands? |
Renderables are fairly lightweight wrappers around vertex buffers, index buffers and material instances. It should be fairly trivial to add an API to at least clone a renderable. That would solve this request without using a ton of memory. |
Thanks for the reply. For now we just need about a dozen or so instances. |
@romainguy, Would it be possible instead to allow a renderable to store an optional array of mat4 transforms, which would allow its efficient rendering at various locations using OpenGL instancing? |
Instancing is something we'd like to do at some point but it's more complicated than just having multiple transforms since it could be useful to vary other attributes as well. |
Yes, that is true. Supporting a transform would be a good start though :-) |
I've been thinking about this. Currently, FilamentAsset has unique ownership over vertex buffers, index buffers, and textures. If I changed these to use shared ownership, then I could add a I think this would be a simple solution. Each clone would have unique transforms and material instances, but they would share their materials and vertex buffers. |
How can I help add this feature? I see currently it is possible to do this with Filamesh (since it exposes Vertex and IndexBuffer), just not with gtfio, is that right? What changes need to be made in gtfio? |
I still think that adding a public |
Wouldn't cloning FilamentAsset potentially end up cloning a lot more than necessary? Cloning Renderable instances seems more precise |
It would not be a deep clone, the textures etc would be shared, which is why I mentioned the potential use of shared_ptr to help with the implementation. The cloned FilamentAsset would have a separate set of entities, components, and material instances. The textures, vertex buffers, and index buffers would be shared. |
It just seems like a waste if you need to clone a particular mesh renderable a dozen times that you would also have to clone the For my current use I actually only need to clone Renderables' meshes which would only require making the VertexBuffers and IndexBuffers accessible. But then the question is how to match up the entities (since not every one is necessarily a Renderable) and also things like what PrimitiveType is it .. filament/libs/gltfio/src/FFilamentAsset.h Lines 228 to 229 in 1292610
|
But you wouldn't clone the textures or lights, just the renderables. |
Yes, the Renderable and Transformable components would be cloned (i.e. the entity hierarchy) as well as Material Instances. Textures and buffers would gain shared ownership semantics so that we can release them properly. Using the Perhaps a better way to expose this functionality would be to add a |
You only need to clone Material instances if you want to modify the materials of the clones. Otherwise they can be shared too. |
Also @prideout clone() has a specific meaning in Java, we should avoid using that name. |
So I can see filament/libs/gltfio/src/AssetLoader.cpp Lines 164 to 167 in 58bb1f6
If Then there could be a function This way it doesn't require any new loading/entity creation logic. But we would need to change some things in
Ok that was a wall of text hopefully makes sense. |
This new API concept uses a "Master Asset + Instances" ownership model which lets us avoid complex shared ownership semantics. Instances have their own API, which turns out to make a lot of sense. For example, light sources and material instances are not instanced, and therefore are not accessible through the FilamentInstance interface. Issue #1513
This adds createInstancedAsset() to AssetLoader, which creates a master asset and a set of slave instances. Vertex buffers, index buffers, textures, and material instances are shared. Entities and components are duplicated. Instances have their own API object that is very simple. Light sources and material instances are not instanced, so are not accessible through the instance API object. The master-slave ownership model lets us avoid complex shared ownership semantics. The existing cache structures in AssetLoader allow the implementation of this feature to be fairly simple. The master asset exposes the union of all entities and allows clients to modify all instances en masse if they wish. This design also works naturally with ResourceLoader, which does not need to know about instancing. For example, asynchronous loading is completely unchanged; the dependency graph simply contains the union of entities across all instances. Fixes #1513.
I have this implemented locally (sneak peek in 72fe00d) but I need to do more testing, add Java / JavaScript bindings, etc. The API is quite different from earlier proposals but it is simple and works quite well. For example, it does not use |
This adds createInstancedAsset() to AssetLoader, which creates a master asset and a set of slave instances. Vertex buffers, index buffers, textures, and material instances are shared. Entities and components are duplicated. Instances have their own API object that is very simple. Light sources and material instances are not instanced, so are not accessible through the instance API object. The master-slave ownership model lets us avoid complex shared ownership semantics. The existing cache structures in AssetLoader allow the implementation of this feature to be fairly simple. The master asset exposes the union of all entities and allows clients to modify all instances en masse if they wish. This design also works naturally with ResourceLoader, which does not need to know about instancing. For example, asynchronous loading is completely unchanged; the dependency graph simply contains the union of entities across all instances. Fixes #1513.
This adds createInstancedAsset() to AssetLoader, which creates a master asset and a set of slave instances. Vertex buffers, index buffers, textures, and material instances are shared. Entities and components are duplicated. Instances have their own API object that is very simple. Light sources and material instances are not instanced, so are not accessible through the instance API object. The master-slave ownership model lets us avoid complex shared ownership semantics. The existing cache structures in AssetLoader allow the implementation of this feature to be fairly simple. The master asset exposes the union of all entities and allows clients to modify all instances en masse if they wish. This design also works naturally with ResourceLoader, which does not need to know about instancing. For example, asynchronous loading is completely unchanged; the dependency graph simply contains the union of entities across all instances. Fixes #1513.
When animation is applied to the master asset, all instances are animated. Instances can also be individually animated via the Animator in FilamentInstance. Fixes #1513.
This adds createInstancedAsset() to AssetLoader, which creates a master asset and a set of slave instances. Vertex buffers, index buffers, textures, and material instances are shared. Entities and components are duplicated. Instances have their own API object that is very simple. Light sources and material instances are not instanced, so are not accessible through the instance API object. The master-slave ownership model lets us avoid complex shared ownership semantics. The existing cache structures in AssetLoader allow the implementation of this feature to be fairly simple. The master asset exposes the union of all entities and allows clients to modify all instances en masse if they wish. This design also works naturally with ResourceLoader, which does not need to know about instancing. For example, asynchronous loading is completely unchanged; the dependency graph simply contains the union of entities across all instances. Support for animation is added in a subsequent commit. Fixes #1513.
When animation is applied to the master asset, all instances are animated. Instances can also be individually animated via the Animator in FilamentInstance. Fixes #1513.
When animation is applied to the master asset, all instances are animated. Instances can also be individually animated via the Animator in FilamentInstance. Fixes #1513.
This adds createInstancedAsset() to AssetLoader, which creates a master asset and a set of slave instances. Vertex buffers, index buffers, textures, and material instances are shared. Entities and components are duplicated. Instances have their own API object that is very simple. Light sources and material instances are not instanced, so are not accessible through the instance API object. The master-slave ownership model lets us avoid complex shared ownership semantics. The existing cache structures in AssetLoader allow the implementation of this feature to be fairly simple. The master asset exposes the union of all entities and allows clients to modify all instances en masse if they wish. This design also works naturally with ResourceLoader, which does not need to know about instancing. For example, asynchronous loading is completely unchanged; the dependency graph simply contains the union of entities across all instances. Support for animation is added in a subsequent commit. Fixes #1513.
When animation is applied to the master asset, all instances are animated. Instances can also be individually animated via the Animator in FilamentInstance. Fixes #1513.
This adds createInstancedAsset() to AssetLoader, which creates a master asset and a set of slave instances. Vertex buffers, index buffers, textures, and material instances are shared. Entities and components are duplicated. Instances have their own API object that is very simple. Light sources and material instances are not instanced, so are not accessible through the instance API object. The master-slave ownership model lets us avoid complex shared ownership semantics. The existing cache structures in AssetLoader allow the implementation of this feature to be fairly simple. The master asset exposes the union of all entities and allows clients to modify all instances en masse if they wish. This design also works naturally with ResourceLoader, which does not need to know about instancing. For example, asynchronous loading is completely unchanged; the dependency graph simply contains the union of entities across all instances. Support for animation is added in a subsequent commit. Fixes #1513.
When animation is applied to the master asset, all instances are animated. Instances can also be individually animated via the Animator in FilamentInstance. Fixes #1513.
This adds createInstancedAsset() to AssetLoader, which creates a master asset and a set of slave instances. Vertex buffers, index buffers, textures, and material instances are shared. Entities and components are duplicated. Instances have their own API object that is very simple. Light sources and material instances are not instanced, so are not accessible through the instance API object. The master-slave ownership model lets us avoid complex shared ownership semantics. The existing cache structures in AssetLoader allow the implementation of this feature to be fairly simple. The master asset exposes the union of all entities and allows clients to modify all instances en masse if they wish. This design also works naturally with ResourceLoader, which does not need to know about instancing. For example, asynchronous loading is completely unchanged; the dependency graph simply contains the union of entities across all instances. Support for animation is added in a subsequent commit. Fixes #1513.
When animation is applied to the master asset, all instances are animated. Instances can also be individually animated via the Animator in FilamentInstance. Fixes #1513.
@prideout Great stuff, thanks so much! |
Hay sorry to comment on such an old issue, But i came across this issue while trying to create an array of meshes and i just can't figure it out. and i don't want to make a new issue. @prideout |
If you are using gltfio, we recently added an API to create multiple instance of the asset. See #3225 |
@davidwarford gltfio has had support for software instancing since May and you should be able to use The JS version of |
In our practical use, we need to render a renderable several times on one scene with different transforms at the same time. For now, we have tried to load a glb file for multiple times so that we have several filamentAssets at the same time. But it turns out to be a burden on the memory if the glb file has many textures, since each filament asset will load its own buffer and textures.
We wish to have an easy way to render a renderable more than once on one scene at a time, or to copy filamentAssets without load glb for multiple times. Is there a possible solution to this?
The text was updated successfully, but these errors were encountered: