GPU Mesh Instancing

Is there a way to render multiple mesh instances with only one draw call (i.e. pass the mesh once and multiple matrixes, e.g. to get multiple trees)?

Can we use the MaterialPropertyBlock to attain such a functionality?

We want to have something like XNA’s Mesh Instancing (http://creators.xna.com/en-US/sample/meshinstancing).

Regards,
Afonso

No.

The big question with instancing is: how would one do instancing in real-life cases? Where multiple instances are affected by different lights, for example?

You usually use geometry instancing in outdoor environments (where the lighting isn’t really a problem). I think there is an article on how Lionhead used that technology in Black&White 2 on GPU Gems 2.

Besides, I think, in this case, there is trade off to be made between the individual quality of each instance and the overall effect you convey by drawing hundreds of characters on screen…

Small question though, I don’t have all the details on how to implement GPU instancing in mind but, technically, why wouldn’t this be possible to do inside Unity?

There are platform specific difficulties (e.g. instancing does not exist in OpenGL on OS X, at least right now).

Then there are integration difficulties, like the lighting issue I mentioned. Adopting an approach from some particular game can be hard, because in that game they can optimize everything based on their own usage pattern, whereas doing the same in “a generic way” can be next to impossible.

I’m not saying Unity won’t ever have instancing, just in my view it’s not a very useful feature to have in a generic engine. Also, on a lot of hardware instancing is actually slower than no instancing (again, depending on a lot of factors).

You got it all wrong.

Doubt that
Mesh instancing is no shader thing, its an engine thing and the engine does not support it.

If you were talking more about geometry shaders and instancing of algorithmic geometry through the shader at realtime: Unity is strictly shader Model 3 and lower, so no SM4 features like Geometry Shaders.

wat?

In other words, what did I get wrong?

Oh how odd, that post was meant for a different topic, the funny bit? the topic is on a completely different forum! epic posting fail

/me sends snicholls 7 pounds of fresh coffee and an IV rig.

-Jeremy

Thats gotta go on some forum mispost record. Epic!

Not to get old cows out of the water, but instancing can be very helpfull in case of a deferred rendering setup. But my guess is that unity has forward rendering :wink:

Unity does forward rendering.

:?:

euhw sorry it’s a dutch expression, it’s like saying you don’t want to blame or bring up something old, nvm :slight_smile:

Mes instanciation can be also very useful to reduce file size, especially in case of Web or iPhone publishing
I got a scene with trees and mesh instanciation would have been useful

perhaps in Unity 3.0 ?

That won’t reduce file size. If all your trees use the same mesh, then Unity’s already just using one mesh, so there’s nothing to reduce.

–Eric

Eric,
Thank you for that information. As I have not seen that feature in the documentation (I am rather new to Unity) I did not know that.
I assume that it is supported via the “instance” feature of the DCC via fbx file format ?

No, that’s not used, but you don’t need anything special. If you have a mesh, then any number of objects can use that mesh. If you duplicated all the trees in a 3D app and imported them as a group, then each one will be unique and it will result in large files, but that’s usually a poor way to work unless you need all the meshes to be unique for some reason.

–Eric

Sorry, I do not mean to be annoying but I do not get it .
In a DCC, IMHO, there are 2 ways to duplicate : either using “copy” or “create instance”.
If I understood correctly (which is not obviously the case :slight_smile: ) if I use copy the mesh will not be shared, but I do not have to use “create instance” either.

Do you mean unity parses all the meshes and compare them to “build” the mesh sharing in the scene ?

you can just try it.
export it, import into unity and select the mesh on the mesh renderers. if it goes to the same its the same otherwise not :slight_smile:

and there is never hardware instancing. you can only get “mesh data sharing” so the mesh data isn’t multiple times in RAM but it will always be a distinct mesh with own render request etc, so all you can get is a reduced size for the mesh data in ram