Vertex buffer theory question

Started by
8 comments, last by DividedByZero 8 years, 4 months ago

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 :)

Advertisement
Yes. This is the typical approach to using height maps.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Creating a vertex buffer is equivalent to malloc - you can put any structure you want in there. It doesn't need to have any positional data whatsoever!

The input layout tells the vertex shader how to read it's required attributes from the buffer -- so yep, just make a VS that had a float2 position input, and an Input Layout describing how to gather that position data from your buffer.

Nice, thanks guys. +1 to you both cool.png

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.

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.

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.

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.

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.

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 :)

This topic is closed to new replies.

Advertisement