Using Instanced Meshes doesn't reduce draw calls
Hi, there :
I had tried two methods to create instanced static meshes : First method, Create a Blueprint within only one component which is InstancedMeshComponent, and added an element in the property "Instances"； Second method, as first method which has only one InstancedMeshComponent, but write a construction script to Add Instance.
The result of two methods all shows that drawcalls are same as indivisual staticmeshes which are not instanced, which means that it didn't reduce drawcalls.
Did I do something wrong? or I missunderstand the meaning of InstancedStaticmeshComponent ?
asked Nov 03 '14 at 09:14 AM in Rendering
Hey ZenTechEntertinament -
Instanced meshes will reduce the draw call overhead on the CPU but will not reduce the GPU cost. In fact the GPU time can increase when using instancing. Allow me to get a little technical for a moment:
This process has to do with the limitations of the CPU vs. GPU and how the API (OpenGL or DirectX) tries to maximize this limitation through batching. Instancing being a special case of batching. With a scene rendered with many small or simple objects each with only a few triangles, the performance is entirely CPU-bound by the API; the GPU has no ability to increase it. More precisely, "the processing time on the CPU for the draw call is greater than the amount of time the GPU takes to actually draw the mesh, so the GPU is starved." [Moeller, Real Time Rendering, 708]. So Batching attempts to allow the CPU to combine a number of objects into a single API call. In the case of Instancing it is the one mesh and the number of times you are drawing with a separate data structure for holding information about each separate mesh.
From a Rendering Engineerer:
"On meshes and material IDs, let me present a hypothetical situation to try to explain the situation more clearly. Let's say you have a mesh that has three materials: wood, chrome, and leather. Now let's say you place 100 of these meshes in your level. Ignoring other passes (shadow, depth only), this will result in 300 draw calls: one per-ID, per-instance. You can see this by looking at the section counts in the primitive stats window.
First thing to keep in mind: some draw calls are more expensive than others. The renderer sorts by material. So in this hypothetical scene we will draw the 100 wood elements first, the 100 chrome elements next, and the 100 leather elements last. Once we draw a wood element, the cost of drawing another wood element is not so high because we are rendering using the same shader and with mostly the same textures. But once we switch materials to draw the chrome we incur a high cost. That's why the renderer sorts by material.
Compare that situation to another scene where you have the same mesh instanced 100 times but each mesh has its own unique material. The scene is still 300 draw calls but the renderer incurs the material switch cost for every draw call. Instancing a mesh provides performance benefits even if the total number of draw calls does not reflect that"
To really see the performance boost in using Instances bring up the Stat UNIT and watch the DRAW versus GPU (CPU vGPU) and notice when you instance a mesh the CPU time remains fairly consistent depending on the additional information you are wanting to pass to each instance, while the GPU will increase. All of these numbers are still dependent on the size of your mesh and the type of material setup and the ultimate limitations of your CPU and GPU.
answered Nov 24 '14 at 03:50 PM
Lovecraft_K ♦♦ STAFF
Hey ZenTechEntertainment -
There actually is a draw call difference between a instanced static mesh and a normal static mesh setup. Here is some examples of what I mean. The Green Boxes are normal static meshes and the red boxes are all instances of the same mesh. The Material setup, which is also import to consider when dealing with draw calls, is a Master Material, green, and an Instance of that Material, red. The value you should be looking at specifically is the Static List Draw Calls.
Here you can see that it a value of 4 which is one material assigned to each mesh.
Here you can see that it has a value of 1 which is one material assigned to the master mesh and instanced out.
Here is the meshes all together and you can see it has a value of 5, the 4 individual meshes and the instanced set.
Hopefully that clarifies, but if not please feel free to ask -
answered Nov 11 '14 at 03:56 PM
Lovecraft_K ♦♦ STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here