You provide some very helpful information. I suggest making a video about LOD, Multi-threading and render distance. All of these things will help optimize everyone's projects.
Just made interactive grass using this last night with hardly any CPU usage at all. At first couldn't figure out what was wrong because I used "DrawMesh" and not "DrawMeshInstanced". Something else good to note is that you can set the transforms of the Matrix4x4 with ArrayForInstancing[numhere].SetTRS(position,rotation,scale).
Hi, yes there is a big difference. While GPU instancing the objects through code, it is not creating GameObjects for each of the meshes. For this reason instancing the objects through code is more performant than simply checking the box in the material. When you make the material GPU instanced, Unity renders all of the objects with the same material in a single draw call, but the objects remain as GameObjects in the scene. Still this technique improves performance a lot.
It surely could be, but it would be hard to add any logic etc. to the NPCs, as with this method of GPU instancing, you can just spawn meshes with no components I believe.
Thanks! The way you make GPU instancing work is always the same, so I didnt cover more examples. Search online and you will definitely find more of them :)
That's a good tutorial. I wonder if this works for my Editor tool. I spawn details on the Terrain with this tool, and I want to know if I can use this method outside of runtime.
Does the grass paint terrain tools also use gpu instancing by default? If we are using monobehavior update to call rendermeshinstanced won't it halt the main thread too if we want to render thousands of mesh?
The RenderMeshIntanced was made for instantiating thousands of objects. The CPU sends that information to GPU in one go, so for the CPU, it doesn't matter how many objects you want to instantiate.
you could give a value to your instances, and create a switch custom function inside the shader that switch depending of the value of the instance, works pretty well for me
You provide some very helpful information.
I suggest making a video about LOD, Multi-threading and render distance.
All of these things will help optimize everyone's projects.
I am glad it was helpful! On Friday, you can expect a tutorial about DOTS.
Thank you for the info, it was really helpful🙌
Love to hear that!
Exactly what I needed, you just provided my CPU freedom from the bondage of 1000s of gameobjects.
I am glad it was useful!
Just made interactive grass using this last night with hardly any CPU usage at all.
At first couldn't figure out what was wrong because I used "DrawMesh" and not "DrawMeshInstanced".
Something else good to note is that you can set the transforms of the Matrix4x4 with ArrayForInstancing[numhere].SetTRS(position,rotation,scale).
Hello, is there a difference between GPU instancing like you did and just simply checking the GPU instancing box in the material of gameobjects?
Hi, yes there is a big difference. While GPU instancing the objects through code, it is not creating GameObjects for each of the meshes. For this reason instancing the objects through code is more performant than simply checking the box in the material. When you make the material GPU instanced, Unity renders all of the objects with the same material in a single draw call, but the objects remain as GameObjects in the scene. Still this technique improves performance a lot.
I'm an art guy and I dont have any clue about programming. Could this be used to have 500 NPCs walking around in a small city?
It surely could be, but it would be hard to add any logic etc. to the NPCs, as with this method of GPU instancing, you can just spawn meshes with no components I believe.
good ! and where can i see more example ?
Thanks! The way you make GPU instancing work is always the same, so I didnt cover more examples. Search online and you will definitely find more of them :)
That's a good tutorial. I wonder if this works for my Editor tool. I spawn details on the Terrain with this tool, and I want to know if I can use this method outside of runtime.
Most functions can run in the editor as well. Try it and let me know what you find out!
Does the grass paint terrain tools also use gpu instancing by default?
If we are using monobehavior update to call rendermeshinstanced won't it halt the main thread too if we want to render thousands of mesh?
The RenderMeshIntanced was made for instantiating thousands of objects. The CPU sends that information to GPU in one go, so for the CPU, it doesn't matter how many objects you want to instantiate.
What if I want a different color for each cube? Should I use an array of materials in that case, or can I use the same material for all the cubes?
I think you will need to call the function multiple times and pass in different material each time as it doesn't accept material array.
you could give a value to your instances, and create a switch custom function inside the shader that switch depending of the value of the instance, works pretty well for me
hi does this method works for mobile devices i do not think they have GPU?
Yes. Mobiles certainly have GPU. It is just not the dedicated GPU you have in PC but an integrated one.
@@freedomcoding thank you
thanks
You are welcome!