Jump to content
  • Advertisement
Sign in to follow this  
lonewolff

Vertex buffer theory question

This topic is 918 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

Hi Guys,

 

I have flat geometry in my game (sort of a 2.5D style concept) and I am wondering, is it possible create a vertex buffer that uses x, y positions only. So, each vertex is a total of 8 bytes instead of 12?

 

If this is possible, can I then still translate the z axis via the shader so it can still be positioned in 2D space?

 

My geometry is pretty vertex heavy and if this is possible, I'll be able to cut down the geometry by discarding the un-used z position (as it is always zero).

 

Thanks in advance :)

Share this post


Link to post
Share on other sites
Advertisement
Ala vertex shader tricks you can determine the coordinates through the index buffer alone, no need for a vertex buffer tongue.png
 
cbuffer Parameters
{
    uint Subdivisions;
    matrix WVP;
}

void VS(uint vid : SV_VertexID, out float2 tex : TEXCOORD, out float4 posh: SV_POSITION)
{
    float x = vid % (Subdivisions + 1);
    float y = vid / (Subdivisions + 1);
    tex = float2(x,y) / Subdivisions;
    posh = mul(float4(tex, 0, 1), WVP);
}
Edit: This assumes a uniform grid or at least discrete coordinates ( (0,0), (0,1), (0,2) etc.).

Edit2: Sorry, misunderstood the problem at hand. This is not useful for DarkRonin's setup. I was thinking of heightmap patches. Edited by unbird

Share this post


Link to post
Share on other sites

Ala vertex shader tricks you can determine the coordinates through the index buffer alone, no need for a vertex buffer tongue.png
 


cbuffer Parameters
{
    uint Subdivisions;
    matrix WVP;
}

void VS(uint vid : SV_VertexID, out float2 tex : TEXCOORD, out float4 posh: SV_POSITION)
{
    float x = vid % (Subdivisions + 1);
    float y = vid / (Subdivisions + 1);
    tex = float2(x,y) / Subdivisions;
    posh = mul(float4(tex, 0, 1), WVP);
}
Edit: This assumes a uniform grid or at least discrete coordinates ( (0,0), (0,1), (0,2) etc.).

 

 

 

Sorry, I'm not understanding what this does or how this relates to creating models using just x & y co-ordinates.

Share this post


Link to post
Share on other sites
First, read the article I linked to (mainly about the full screen triangle and the particles). Then assuming you use a uniform grid and index buffer, there's a simple 1:1 mapping from index to grid coordinates (division-remainder math), if you lay out the vertices row-wise.

Simple example: A grid with subdivision 2 (2x2 quads) looks like this (numbers mean indices).


0---1---2
| \ | \ |
3---4---5
| \ | \ |
6---7---8

Now, with an indexed draw SV_VertexID gives you these very indices. Let's consider the triangle 0-1-4. If you do the calculations of the first two lines I showed this will give the following (i means index):


i | x | y |
--+---+---+
0 | 0 | 0 |
1 | 1 | 0 |
4 | 1 | 1 |
--+---+---+


Which are precisely the coordinates of those vertices (left-to-right, top-to-bottom). Transform them with a world transform or something to bring it into the desired position. Similarly the tex-coords are just normalized into the 0-1 range.

Nevermind, I just like such stuff. Stay with your current approach but you may consider lower precision coordinates to further decrease memory usage (e.g. R16G16_UNORM). One rarely needs full floats for geometry.

Share this post


Link to post
Share on other sites

Ah ok, I think we are thinking along different lines. Are you talking about quads and then mapping textures to them?

 

In my case, I am creating geometry along the lines of SVG's, so I am not using quad's or textures. Pure vertices to convey the scene.

Share this post


Link to post
Share on other sites

Oh, well, in that case: Sorry. L.Spiro's post led me to believe we are talking about height map patches. Reading helps wacko.png . So no, this has no use for you I think.

Share this post


Link to post
Share on other sites

Oh, well, in that case: Sorry. L.Spiro's post led me to believe we are talking about height map patches. Reading helps wacko.png . So no, this has no use for you I think.

 

Hehe, no worries :)

 

Thanks for the link though, it looks like it has some very useful info in there :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!