Using multiple vertex streams

Started by
5 comments, last by Jeremy6996 14 years ago
I understand everything perfectly fine when working with a single vertex stream. However I have encountered a situation where I need to use two vertex streams, and pass them to a vertex shader. Can someone direct me to an article which describes how to use multiple vertex streams, how to use them in shaders, and how to setup vertex declarations when using multiple streams? Thanks.
Advertisement
Are you using them for hardware instancing? If so, there's an instancing sample with the DirectX SDK.
-- gekko
Quote:Original post by gekko
Are you using them for hardware instancing? If so, there's an instancing sample with the DirectX SDK.


I'm actually using XNA(but at such a low-level it's pretty much DirectX).

Thanks for your quick reply gekko!

FYI: When I say frame. I refer to a single frame in an animation.

What is happening is I'm trying to optimize the way my MD2 models render and animate. I have it setup to compile a static vertex buffer for all of the animation's frames, and then, what I plan to do, is setup two vertex streams(one for, say, frame1, and another for the next frame(frame2)). Then, in the vertexshader I'm writing, I'm going to interlope the two vectors representing each of the two vertices positions to create a smooth transition between the two frames. This might be what you've refereed to as hardware instancing(as I am unfamiliar with the term). If so, please correct me.

I've considered using a dynamic vertex buffer, but as I've been informed by the people over at the XNA forum, writing to the vertexbuffer is a rather slow process on the 360(which is my targeted console).

Thanks.
If you're targeting the Xbox 360, it might be easier for you to just pack your animation data into textures that you sample in the vertex shader.
Quote:Original post by MJP
If you're targeting the Xbox 360, it might be easier for you to just pack your animation data into textures that you sample in the vertex shader.


I was going to do this, but I am also interested in how multiple vertex streams work.
Well in general they're simpler than you think. On the app side of things, you simply create multiple vertex buffers. Your VertexDeclaration must contain all of the elements in all of your vertex streams. Then you bind your buffers to different input streams, in render. In your vertex shader, you then get data from all of your streams simultaneously using semantics that match your declaration. So for instance let's just say you had positions. You would create two vertex buffers of the same size, with a Vector3 for each vertex. Then in your declaration you would first have usage set to Position and a usage index of 0, bound to stream 0. Then your second element would be another Position with usage index 1, and stream 1. Your vertex shader input would look like this:
struct VSInput{    float4 Position0 : POSITION0;    float4 Position1 : POSITION1;};
Quote:Original post by MJP
Well in general they're simpler than you think. On the app side of things, you simply create multiple vertex buffers. Your VertexDeclaration must contain all of the elements in all of your vertex streams. Then you bind your buffers to different input streams, in render. In your vertex shader, you then get data from all of your streams simultaneously using semantics that match your declaration. So for instance let's just say you had positions. You would create two vertex buffers of the same size, with a Vector3 for each vertex. Then in your declaration you would first have usage set to Position and a usage index of 0, bound to stream 0. Then your second element would be another Position with usage index 1, and stream 1. Your vertex shader input would look like this:
struct VSInput{    float4 Position0 : POSITION0;    float4 Position1 : POSITION1;};


Ah, thank you. This makes perfect sense.

This topic is closed to new replies.

Advertisement