# Instancing with the SharpDX toolkit

I am starting on the graphical portion of my project and before I begin I need to get Instancing working. I can do instancing with SharpDX, but not with the Toolkit Models. The main reason I want to use the Tookkit is for loading models, textures, fonts, etc...

The most helpful thing for me would be a link to an example that instances a SharpDX.Toolkit.Graphics.Model -- but anything the shows the Model working with a custom effect should be fine... I can make instancing work from there right?

I have searched and searched for that though so I am not too hopeful - so if this is not something easily done alternative solutions would be great. As I said, I can use SharpDX without the toolkit just fine - but I want the benefits that come with loading models and fonts mostly.

## 1 Answer

Instancing requires to change the InputLayout of vertex buffers and pass an instancing buffer along the mesh vertices. Unfortunately, there is nothing automatic to do this with Toolkit models, though possible but would require to dig into the internals to do this yourself. Before even trying to do some instancing with models, you should start with a basic instancing sample with your own raw vertex buffers/index buffer and effect. You will see exactly what needs to be changed and how to setup/use instancing. With this proof of concept working and with the source code of the Toolkit available, you should be able to figure out how to use existing toolkit Model data to turn it into instancing friendly.

• Thank you for the resoponse. I understand how to do instancing with sharpDX, it getting it working in the Toolkit that I don't understand. I was just thinking there was some way to make a custom Effect and pass it into the models Draw method: _model.Draw(Device, _world, _view, _projection, _instancingEffect); -- But I can't figure out how to do this... Or how to get any effect to work with it really. Is it possible to create a custom SharpDX.Toolkit.Graphics.Effect that handles instancing? Feb 1, 2014 at 23:52
• There is a sample with a custom effect in the SDK that is working. Simply put the build action "ToolkitFxc" on the effect and it should be compiled at compile time. The main problem is not the effect but to override the default behavior of MeshPart.Draw to pass a layout with instancing, as long as vertices and instancing buffer. Feb 2, 2014 at 12:00
• So am I right in understanding the the toolkit does not support instancing? To get it working I would have to create my own classes for Effect, Model, ModelMesh & MedelPart? Feb 2, 2014 at 21:18
• The toolkit model is not supporting instancing. You should not have to modify Effect. It is a couple of lines to modify in Model/ModelMesh/MeshPart files (only signature in Model and ModelMesh to pass the instancing buffer and MeshPart to pass the instancing buffer along the vertices buffer to d3d11) and you have to recreat the layout of the MeshPart. Instancing is something that is a bit more difficult to standardize, as you can put whatever you want in the instancing bufffer, hence the layout would change...etc. But again, a couple of line to modify in the toolkit to match your needs Feb 2, 2014 at 23:38
• SharpDX is using Assimp.net for loading/converting 3d models to toolkit model. The code is specific to the toolkit conventions/layout/object model, so your code will be. You can always have a look at the model converter in SharpDX.Toolkit to learn how it is done (github.com/sharpdx/SharpDX/blob/master/Source/Toolkit/…) Feb 11, 2014 at 2:59