Jump to content

[SOLVED] Problem with Instancing


photo

Recommended Posts

Hey guys,
 
I tried to figure out how Instancing of Meshes work exactly, and how much percentage of FPS I can gain with it.
So I have programmed a little test-case for it. I spawn my node on the one hand with clone() and on the other side I load it every time with a NodeReference. Although, I can change their number on the fly with my UserInterface, and toggle the instancing too. Nethertheless, I can't see any performance advantage for any numbers of spawned nodes (e.g. 10,100,....). I tried cloning my nodes, clone and give them all the same Material...., but I can't see any different results for my test cases

 

void Update_NodesCount()
{
	NodeArray.delete();			//löscht alle Nodes im Spiel

	ObjectMesh InstancedMesh = class_cast("ObjectMesh",InstancedNode);

	forloop(int i = 0; field_length;1)
	{
		forloop(int j = 0; field_depth;1)
		{
			if (ActivateInstancing.isChecked() == 1)
			{
				//Instanziere das Mesh vom Droiden
				Node newNode = InstancedNode.clone();
				ObjectMesh newObject = class_cast("ObjectMesh",newNode);

				forloop(int k = 0; k < newObject.getNumSurfaces();1)
				{
					newObject.setMaterial(Material(InstancedMesh.getMaterial(k)).getName(),k);
				}
				class_append(newNode);
				newNode.setEnabled(1);
				newNode.setWorldPosition(vec3(i*2.0f,j*2.0f,2.0f));
				NodeArray.append(newNode);
			}
			else
			{
				//Lade jedes mal das neue Mesh
				NodeReference newReference = new NodeReference("data/project/nodes/droid.node");
				Node newNode = newReference.getNode();
				class_append(newNode);
				newNode.setWorldPosition(vec3(i*2.0f,j*2.0f,2.0f));
				NodeArray.append(newNode);
			}
		}
	}
	engine.message("Number of Nodes: %d",NodeArray.size());
}
Link to comment

In both cases you are creating instances by different means. As I understand it, if your node references have the same materials on the surfaces, then they are instanced mesh. (or iI have been doing it wrongly for a long time).

 

A good way to check the advantage of instances / and if they are working, run profiler (press 1 twice). Look at the number of surfaces compared to rdips.

 

It should show more surfaces than rdips, which are actual drawcalls.

Search "profiler" in the documentation for a more wholesome explanation.

Link to comment

Thanks for your quick answer. I checked the profiler and in both examples (copy and load) there are the same number (644 surfaces to 36 rdips). As far as I can see, sometimes instancing is used (more surfaces, same rdips), and sometimes the code will add additional drawcalls, if I raised the number of the surfaces. For example, regardless if I have 40 or 60 nodes spawned, I have the same amount of rdips (32). If I raised the number by 10 the number of rdips will also raised by 7 (for the next 20 to 30 surfaces).

Link to comment

Christian,

 

Nat is absolutely right, NodeReferences are instanced no matter how you load them, since that's what they are designed for in the first place. The number of DIPs going up at some point means that it's not possible to instance the given number of objects in one go because the buffer limit is reached. So the data will be send to the GPU driver in two DIPs, that's all.

Link to comment
×
×
  • Create New...