Sign in to follow this  

Terrain, vertex construction

This topic is 4109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I was wondering how i would go about sending vertex data to a shader in 2 seperate parts. I am trying to send the x,z coords through 1 vertex buffer and in another have all the y coordinates. I am trying to implement a chunklod style implementation without the optimized triangulation. I plan is to have a couple of base xz vertex/index buffers and then translate + scale them in the shader, however this means i need to add the height data after this. My problem is having the vertex buffer recognise the 2nd VB stream (The height data), at the moment it picks up the x,z coords to the height data. If you could direct me to an example of this in action or just tell me how it would be great thanks.

Share this post


Link to post
Share on other sites
I'm not sure about any example code, but the trick is with the vertex declaration.

Set up both your VB's and make the corresponding SetStreamSource() calls. Then, declaration should be something like:

D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 1, 0, D3DDECLTYPE_FLOAT, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1 },
// Other elements here...
};


The trick is in the first and last fields. The first field is the stream ID (the FLOAT2 comes from the first stream and the FLOAT comes from the 2nd) and then the usage index at the end so you can differentiate between the two POSITION semantics.

It should map to the following input declaration:

struct VS_INPUT
{
float2 xzPosition : POSITION0;
float yPosition : POSITION1;
};


Note the use of indexes for the semantics.

hth
Jack

Share this post


Link to post
Share on other sites

This topic is 4109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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