Sign in to follow this  
wh1sp3rik

Mesh instance

Recommended Posts

wh1sp3rik    248
Hello, I would like to know, how hardware instancing works and how can i make it ? I can't find any information about that. I hope, it's not only to save pointer to new instanced object hehe. Thank you very much for any information :) if you know any websites, i will be happy ;-)

Share this post


Link to post
Share on other sites
MJP    19753
Well you'll definitely want to have a look at the Instancing sample in the SDK. That will demonstrate the API calls and how to setup your shaders. You can also have a look at this sample.

The basic premise is like this:

-Your mesh and index data stays the same (your triangles must be indexed for instancing to work)
-In addition to your mesh data, you create a secondary vertex buffer containing all per-instance data for all instances that you want to draw. This might be a position, a full world matrix, a color, UV offsets, anything that can change from instance to instance.
-Your vertex declaration must contain all elements in your mesh vertex buffer, as well as all elements in your instance data buffer (with the instance data elements mapped to stream 1 instead of stream 0).
-When you're ready to draw, you bind the mesh vertex buffer to stream 0 and your instance data buffer to stream 1. You then set the frequency divider to indicate how many instances you need to draw.
-In your vertex shader, you include inputs for instance data elements. You then transform vertices like you normally would.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this