Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualbombshell93

Posted 24 March 2013 - 07:58 PM

okay I've given it a go and expanded the rendering engine in general, but I have a problem, for sake of testing I'm drawing 27 instances of a single model (which is fairly low poly), and my framerate is through the floor at 16 FPS.
the problem seems to be updating the vertex buffer (per second taking up over half of the second)
Here is the part taking up the most time, though its worth noting both rendering the shadow map and rendering the scene itself is taking up 12% of the second each too.


				Model model = assetManager.getModel(m);
				if (!buffers.ContainsKey(m) || models[m].Count > modelCount[m])
				{
					if (!buffers.ContainsKey(m))
					{
						buffers.Add(m, null);
						modelCount.Add(m, 0);
					}
					else
						buffers[m].Dispose();

					modelCount[m] = models[m].Count;
					if (modelCount[m] < 10)
						modelCount[m] = 10;
					buffers[m] = new DynamicVertexBuffer(graphicsDevice, vertexDeclaration, 
						modelCount[m], BufferUsage.None);
					instances.Add(m, new Instance[modelCount[m]]);
					int i;
					for (i = 0; i < models[m].Count; i++)
					{
						instances[m][i] = new Instance(models[m][i].transform, 
							camera, models[m][i].textureCoord);
						models[m][i].index = i;
					}
					for (; i < modelCount[m]; i++)
					{
						instances[m][i] = new Instance(Matrix.CreateScale(0), 
							camera, Vector2.Zero);
					}
					buffers[m].SetData(instances[m]);
				}
				else
				{
					int i = 0;
					for (i = 0; i < models[m].Count; i++)
					{
						instances[m][i].transform = 
							Matrix.Transpose(models[m][i].transform);
						instances[m][i].worldViewIT = 
							Matrix.Transpose(Matrix.Invert(instances[m][i].transform * camera.View));
						models[m][i].index = i;
					}
					//for (; i < modelCount[m]; i++)
					//{
					//	instances[i] = new Instance(Matrix.CreateScale(0), camera, Vector2.Zero);
					//}

					buffers[m].SetData(instances[m]);
				}
			}

 


I'm obviously doing something wrong but I'm not all that familiar with how to efficiently use instancing,
if anyone can spare some advice or references on the matter it would be a great help.

My mistake, my stopwatch was placed awkwardly giving me false times, I was also sending a bad value to the draw call telling it to draw thousands of instances.


#1bombshell93

Posted 24 March 2013 - 05:05 PM

okay I've given it a go and expanded the rendering engine in general, but I have a problem, for sake of testing I'm drawing 27 instances of a single model (which is fairly low poly), and my framerate is through the floor at 16 FPS.
the problem seems to be updating the vertex buffer (per second taking up over half of the second)
Here is the part taking up the most time, though its worth noting both rendering the shadow map and rendering the scene itself is taking up 12% of the second each too.


				Model model = assetManager.getModel(m);
				if (!buffers.ContainsKey(m) || models[m].Count > modelCount[m])
				{
					if (!buffers.ContainsKey(m))
					{
						buffers.Add(m, null);
						modelCount.Add(m, 0);
					}
					else
						buffers[m].Dispose();

					modelCount[m] = models[m].Count;
					if (modelCount[m] < 10)
						modelCount[m] = 10;
					buffers[m] = new DynamicVertexBuffer(graphicsDevice, vertexDeclaration, 
						modelCount[m], BufferUsage.None);
					instances.Add(m, new Instance[modelCount[m]]);
					int i;
					for (i = 0; i < models[m].Count; i++)
					{
						instances[m][i] = new Instance(models[m][i].transform, 
							camera, models[m][i].textureCoord);
						models[m][i].index = i;
					}
					for (; i < modelCount[m]; i++)
					{
						instances[m][i] = new Instance(Matrix.CreateScale(0), 
							camera, Vector2.Zero);
					}
					buffers[m].SetData(instances[m]);
				}
				else
				{
					int i = 0;
					for (i = 0; i < models[m].Count; i++)
					{
						instances[m][i].transform = 
							Matrix.Transpose(models[m][i].transform);
						instances[m][i].worldViewIT = 
							Matrix.Transpose(Matrix.Invert(instances[m][i].transform * camera.View));
						models[m][i].index = i;
					}
					//for (; i < modelCount[m]; i++)
					//{
					//	instances[i] = new Instance(Matrix.CreateScale(0), camera, Vector2.Zero);
					//}

					buffers[m].SetData(instances[m]);
				}
			}

 


I'm obviously doing something wrong but I'm not all that familiar with how to efficiently use instancing,
if anyone can spare some advice or references on the matter it would be a great help.


PARTNERS