Skip to main content
GameDev.net gamedev.net
🔒 Locked

shared vertices

Started by Chaucer Oct 24, 2002 at 12:23 AM 16 replies 650+ views
Original Post
Chaucer
Chaucer
I''ve seen some of you post that you''ve been able to create your tiled terrain using shared vertices. I was wondering if any of you could explain how you do this. A couple questions.. Do you still have 4 vertices in each tile? How do you set up the index buffer? (very curious about this one) Do your texture coords have to be setup any differently? Thanks!
Thanks!
Chaucer
Chaucer
nobody knows?
Thanks!
Chaucer
Chaucer
I''m using a vertex buffer that contains all of my vertices and an index buffer for each type of tile that I use. In this setup, I''m using a triangle list for it to work correctly.

I don''t think a triangle strip will work unless all of the tiles in that type are touching. I''d like to be able to modify my vertex buffer and filter out all vertices with the same x,y,z coords so that there is only one of each. If I do that, though, there''s no telling how my index buffer should be set up.

Also, I don''t know if the texture coords need to be different since up to 4 tiles will be sharing the same vertex.
Thanks!
No
No
You''re doing the right, where exactly is your problem with shared Vertices? My Engine has a list . In this list are
saved the tile informations and which Vertices belongs to that tile. Is it clear? You can ask. My Engine''s already working :-))
No
No
You''re doing the right, where exactly is your problem with shared Vertices? My Engine has a list . In this list are
saved the tile informations and which Vertices belongs to that tile. Is it clear? You can ask. My Engine''s already working :-))
Chaucer
Chaucer
Ok. Each tile in my engine has 4 vertices. This means that when a tile touches another tile, there are multiple vertices with the same values. This becomes a problem when I try to raise the height of a certain vertex, since raising the height of one vertex of a tile won''t raise the vertex on the tiles surrounding it that have the same x,z value.

I can easily filter out the vertices that have the same values but I have a problem when it comes to creating the index buffers for each type of tile.
Thanks!
Chaucer
Chaucer
more like this:

2--3,6--7,10--11

0--1,4--5, 8--9

and my index buffers are something like this:

0,1,2,3,2,1,4,5,6,7,6,5

So say I filter out all of the second occurences of the vertex with the same values. Then I have

8--9--10--11

2--3--4--6

0--1--5--7

0,1,2,3,2,1,1,5,3,4,3,5,5,7,4,6,4,7
2,3,8,9,8,3,3,4,9,10,9,4,4,6,10,11,10,6

I guess my problem is that I don't really see a way to calculate which vertices will be part of the index buffer without manually looking at it. Without shared vertices, it's easy to do.

[edited by - Chaucer on November 11, 2002 11:52:56 AM]
Thanks!
No
No
I think thebest way is to change your Vertices.
So theat they are like I mentioned. Thers nothing bad about this method
and its very easy to create the Vertex and the Indexbuffer
Thathmew
Thathmew
yes you can do this and it''s pretty easy
here''s our lay out:
---x--across
1--2--3--4

5--6--7--8

|
Y
|
down

so we have three tiles I''ll call them a, b, c
and I''ll say the tile a and c are grass and b is stone.
each vertex has an x,y,z position and a tu, tv for texture, lighting is another matter.

here''s the data for vertex 1: (z is 0 in all, but could be anything)
x = 0
y = 0
z = 0
tu = 0
tv = 0

vertex2
x = 1.0
y = 0
z = 0
tu = 1.0
tv = 0

vertex5
x = 0.0
y = 1.0
z = 0
tu = 0.0
tv = 1.0

vertex8
x = 3.0
y = 1.0
z = 0
tu = 3.0
tv = 1.0

these fill your vertex buffer

this assumes each tile is 1.0 units across (your texture can be any size in pixels, doesn''t matter) basically because of texture wrapping, texturing from 0.0 - 1.0 is the same as 5.0 to 6.0.

basically tu = x and tv = y for all cases. This will cause your texture to stretch as you lift or low the z factor.

now you create a draw list for each texture:
draw list grass:
1,2,5,2,6,5,3,4,7,4,87

12 indices = 4 triangles = 2 tiles

draw list stone:
2,3,6,3,7,6

6 indices = 2 triangles = 1 tile

so you set texture to stone, draw the buffer using the stone list, then set the texture to grass, then draw the buffer using the grass list.

hope this helps.

cheers,
-mat












mat williams
Lead Programmer, Designer
Zero Sum Software
www.zero-sum.com
mat williamsLead Programmer, DesignerZero Sum Softwarewww.zero-sum.com
Igilima
Igilima
Thathmew, I don''t think that will work very well.

In effect, you would have to have a texture for each terrain type that is the same size as the entire terrain. In other words, you couldn''t re-use the same patch of texture for different tiles, it would always go to exactly one tile on the map.

I really don''t see any way around having a set of 4 vertices per tile that are used only by that tile if you want to re-use the same part of a texture for multiple tiles.
No
No
I think you should reread the posts...
Igilima
Igilima
"this assumes each tile is 1.0 units across (your texture can be any size in pixels, doesn't matter) basically because of texture wrapping, texturing from 0.0 - 1.0 is the same as 5.0 to 6.0."

So you are taking advantage of texture wrapping? I think I might understand now. So if you enable wrapping, using 1.0,1.0 in the upper left and 2.0,1.0 in the upper right of the tile is the same as using 0.0,0.0 in the upper left and 1.0,0.0 in the upper right? What you are saying is that you subtract the maximum multiple of 1.0 from each coordinate in each coordinate pair and that is what the effective coordinate will be when it maps.

If this is the way it works, then this is good because it eliminates the need for 4 vertices at each place where 4 tiles meet.

[edited by - Igilima on December 15, 2002 9:20:40 PM]
No
No
exact! Sorry I didn''t understand what you mean
Igilima
Igilima
Vertices:
[1]
x = 0.0
y = 0.0
z = 0.0
tu = 0.0
tv = 0.0

[2]
x = 1.0
y = 0.0
z = 0.0
tu = 1.0
tv = 0.0

[3]
x = 2.0
y = 0.0
z = 0.0
tu = 2.0
tv = 0.0

[4]
x = 0.0
y = 1.0
z = 0.0
tu = 0.0
tv = 1.0

[5]
x = 1.0
y = 1.0
z = 0.0
tu = 1.0
tv = 1.0

[6]
x = 2.0
y = 1.0
z = 0.0
tu = 2.0
tv = 1.0

Results in:
1--2--3

4--5--6

Tile A defined by 1, 2, 4, and 5 would reference the entire texture fine because left and top coords are 0.0 and bottom and right coords are 1.0

Tile B defined by 2, 3, 5, and 6 would reference an area equal to the texture just to the right of the texture because left coords are 1.0 and top coords are 0.0 but...

If you enable texture wrapping, it in effect creates an endless number of copies of the texture to the right and below the texture like an infinite checkerboard except all the squares on the checkerboard are the same texture. Therefore saying top left vertex tu = 1.0 and top right tu = 2.0 is the same as saying top left vertex tu = 0.0 and top right tu = 1.0. Same for tv.

One thing that concerns me is this... I''ve heard that you actually want to map textures using 0.1 or 0.01 or whatever for the top and left edges and 0.9 for the bottom and right edges. If you do that, doesn''t this cause trouble?

Chaucer, I would say just make your tu values equal to your x values and your tv values equal to your y values, use shared vertices as described above and you will see it all works out. The main problem now is to figure out the way to generate the index buffer correctly.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.