First off, I want to say thanks for the new instanced sample because it really helped a lot.
This is a screenshot from my game using Sunburn and the new instanced model setup. Currently, the obstacles (pyramid like shapes), enemies (purple and white guys) and the red spawners are all using instanced models. As you can see there seems to be a problem with the spawner models and there is a triangle connecting the two spawners that should not be there. The mouse with guns in the center also has a triangle connecting it to a spawner but it's not being rendered by Sunburn, but by the normal XNA renderer. I think it may be a problem with the actual model file since I don't see the problem happening to other instanced models. Anyone experience such a thing and know what possibly may be causing it?
Also, there are some times where there are more of the spawner models being rendered on screen than should be. At one point I stepped through the code and only a matrix array of length 1 was being submitted but two spawners were being rendered. Each model is added with a Frame life span so there shouldn't be any extra models.
Maybe someone experienced something like this and can point me in the right direction.
Thanks.
Hi bioroid,
Ahh, ok I definitely see what's going on there - the indices going into the index buffer are overflowing the short data type. The AddInstances method needs to verify that the number of vertices being added plus the number already in the container is not > short.MaxValue.
If the index values are too high there are a couple of ways to handle this, either have the method alert you during development with an exception, or if a lot of the containers are highly dynamic and you want to avoid a rogue exception in the released game then return a boolean stating whether the instance was added and have your game code roll over to a new container if not.
I'll edit the example to include one of these solutions.
Let me know if this helps!
Btw: the game looks cool - that's Cyborg Mice Arena right? Great work!
Follow me on Twitter – development and personal tweetsAwesome XNA Videos – Lighting, Rendering, and game videos
Yes, that model had 1255 vertices so that was definitely overflowing. I'm thinking about adding a function could be to the container that takes the model and automatically fills it to max capacity and then stores that amount (max capacity - 58 or less) in a variable that can be used later when trying to determine how many models can be rendered by the container. (I think the rest of this ties into the Instanced Models thread.) The primitive count for each instance could be stored and then use that to limit how many instances are being rendered. Would the renderer ignore the rest of the vertex buffer that isn't being used just based on the primitive count (multiplied by the number of instances being rendered)?
Yeah, the game is Cyborg Mice Arena. I think Sunburn will help improve the visuals a lot and it's even looking good with the programmer generated normal/specular maps. :) I plan on releasing a graphical update sooner or later and am planning on using Sunburn on future 3D XNA games. Is there (or will there be) any support for 2D spritebatch like functionality within Sunburn to be able to do nice 2D games with normal/specular maps to have the graphics pop out a bit? I'm just asking because my next few games will be strictly 2D and it would be cool to get some of those types of effects in there. i realize that a wrapper could probably be written for that kind of functionality, and it could actually open up Sunburn more to 2D developers.
bioroid:Would the renderer ignore the rest of the vertex buffer that isn't being used just based on the primitive count
The renderer will, but DirectX will not. DirectX needs to be told the vertex range, which is the number of vertices between the maximum and minimum vertex index referenced during the draw call.
For instance if the draw call renders a single triangle using vertices 0, 10, 101, although only 3 vertices are rendered DirectX needs to send enough of the vertex buffer to render those vertices (in this case a range of 102).
If the container tracks the vertex max and min indices for each instance (as well as the primitive count) it can then provide the total range along with the primitive count for a sub-group of rendered instances.
bioroid:Is there (or will there be) any support for 2D spritebatch like functionality within Sunburn to be able to do nice 2D games with normal/specular maps to have the graphics pop out a bit?
Yes, we put together a rough prototype of this a few months back:
Right now a community member is working on a much better version, which is a SpriteBatch replacement. I'm not sure when it will be ready, but something like this will be available at some point.
JohnK (WorkingOnTheSite): For instance if the draw call renders a single triangle using vertices 0, 10, 101, although only 3 vertices are rendered DirectX needs to send enough of the vertex buffer to render those vertices (in this case a range of 102). If the container tracks the vertex max and min indices for each instance (as well as the primitive count) it can then provide the total range along with the primitive count for a sub-group of rendered instances.
So if we know the primitive count per instance and the max index for the first instance, can't we just use 0 for the min index and (max index * instance count) for the max index of n instances?
Yes, if all the instances are of the same model. We use instancing to pack many different models into a single renderable object, so I was thinking along those lines. :)