roads on dynamic terrain. ideas ?

Started by
10 comments, last by HellRaiZer 16 years, 10 months ago
hi all,. I would like to add roads to the terrain in my game, I have thought about it and I would be sure I am not going in the wrong direction. Here follows the specs I have. 1/The terrain is generated from a heightfield image and is for now a regular grid (no mesh simplification). It is split in medium-sized square blocks for frustum culling. 2/The Terrain is dynamic, some objects have the ability to modify it. 3/The road are built (and destroyed) at runtime. They are a sort of decal and as such they follows the terrain curves... I see two path possible : - Multitexturing : i.e having texture stages dedicated to roads. But I am not sure I could have road continuity, without a lot of texture stages/layers. - Geometry : adding some quad and texturing them. due to difference of sampling between the terrain and the decals I may have to tesselate the quad to follows properly the terrain. (for example, one point of the terrain may be inside the road, if the point is a peak, the peak will be visible, the road won't cover it.) any ideas ?
Advertisement
Well the way I do it in my software Freeworld3d is I create a spline that follows the terrain, then specify how many 'sections' should be in between each point of the spline, then I simply loop through the start point to the end point and generate triangle strips to conform to the terrain. But as the road is laid down I also flatten any terrain vertices right underneath the road so I don't have the poking out problems you discussed.

My road geometry is laid out like this:

-------------------------\  /\  /\  /\  /\  /\  /| \/  \/  \/  \/  \/  \/ |-------------------------\  /\  /\  /\  /\  /\  /| \/  \/  \/  \/  \/  \/ |-------------------------


I found having 2 strips of triangle strips adjacent to each other worked best. Especially for conforming to slopes on the terrain. I believe Battlefield 2's editor does the same thing when generating the road geometry.
Author Freeworld3Dhttp://www.freeworld3d.org
Quote:Original post by Wagnerious
- Geometry : adding some quad and texturing them. due to difference of sampling between the terrain and the decals I may have to tesselate the quad to follows properly the terrain. (for example, one point of the terrain may be inside the road, if the point is a peak, the peak will be visible, the road won't cover it.)


Use the ideas of constrained Delaunay triangulation to insert the road edges/triangles into the terrain triangles.

(1) Given your already constructed triangle mesh, insert the road vertices into the mesh, adding new triangles as necessary.

(2) For each road edge, determine the triangles that contain it. You can build this set of triangles as a triangle strip. Remove those triangles from the mesh. The triangle edges shared by this set and the triangles not in this set form a polygon. The road edge cuts this polygon into two subpolygons. Triangulate each subpolygon.

As always, there are numerical issues to deal with.
first, thanks for your help!

@soccone:
your solution works only with flatten. but in my game, road cannot flatten the terrain, other objects can and i don't want to have road and this other type fight over which way to flatten an area (what could be good for one could be incorrect for the other).

@daveEberly:
This is what I was thinking about, but in a much more detailed manner. I will probably follow this path.




Quote:Original post by Wagnerious
first, thanks for your help!

@soccone:
your solution works only with flatten. but in my game, road cannot flatten the terrain, other objects can and i don't want to have road and this other type fight over which way to flatten an area (what could be good for one could be incorrect for the other).

@daveEberly:
This is what I was thinking about, but in a much more detailed manner. I will probably follow this path.


Well the problem with dave's method is its going to be very hard to calculate correct texture coordinates so that your road texture tiles and goes in the direction of the road.

My method does not require the terrain to be flat. Each vertice of the road geometry is placed on the terrain below it. And when I said I flatten the terrain, what I meant is that for each triangle in the road geometry, I flatten the terrain vertices right below that single triangle to conform to the triangle's plane. So if part of the road is at an incline, the terrain underneath will also be at an incline.

Texturing the roads using my method is extremely easy since you already know the direction of the road, and there's no special texture coordinate clamping or clipping that needs to take place.

If you want to see what it looks like, check out this page:
http://www.freeworld3d.org/tutorials/roadsystem.html
Author Freeworld3Dhttp://www.freeworld3d.org
What I'd do is make the road a mesh (or a series of meshes) that sticks out of the terrain. The height of the road surface would be set so that the terrain never pokes through, and there'd be "skirt" polygons extending down from the road edges into the terrain. So on a very flat surface, the road would be a thin "slab" but when it goes along a cliff face you'd get something that looks like a retaining wall on the downslope side. A bit like this photo: http://ghostdepot.com/rg/images/san%20juan%20branch/highline%20retaining%20wall%20mp469.9%201997%20tlhprn.jpg
Quote:Original post by soconne
Well the problem with dave's method is its going to be very hard to calculate correct texture coordinates so that your road texture tiles and goes in the direction of the road.


I did not say that my approach would be easy--it takes patience and time to get it right. I have already implemented a tool to do this, including dealing correctly with the road texture coordinates. It works well, which is why I suggested this direction in the first place...
Quote:Original post by Dave Eberly
Quote:Original post by soconne
Well the problem with dave's method is its going to be very hard to calculate correct texture coordinates so that your road texture tiles and goes in the direction of the road.


I did not say that my approach would be easy--it takes patience and time to get it right. I have already implemented a tool to do this, including dealing correctly with the road texture coordinates. It works well, which is why I suggested this direction in the first place...


Oh, I did not mean anything by it. Your solution does solve the z-fighting problem I sometimes experience with my solution if the terrain is not flattened correctly. I was just stating my own experience when I tried to implement what you said and decided against it because of the texture coordinate generation issue.
Author Freeworld3Dhttp://www.freeworld3d.org
Hi all,

soconne :
Your approach is similar to what Battlefield 2 does for the roads (if i'm not mistaken), and imo both implementations suffer from the same problems.
1) The road may intersect the heightmap, or the road floats in the air, when the road spline has steep slopes (not enough resolution for the heightmap to follow the road)
2) Even if the heightmap can follow the road, there may be z-fighting because vertices don't have the exact same height.
3) When the spline creates sharp turn (like a 'U') there are UV artifacts. I've searched about that and it looks like a problem on how the GPU is rendering quadrilaterals. Check this page by Cass Everitt for a description on the problem. Unfortunately the solution proposed by Everitt of using the q-coord doesn't solve the problem, because if you do it the road texture will repeat more time in the U direction (road's width) and you don't want that.

Dave :
What you describe sounds interesting and i really want to implement something like that. I have two questions though.
1)Is what you describe similar to this Real-time Rendering of Complex Vector Data on 3D Terrain Models What i want to know is, do you subdivide the road polygons or you change the heightmap in order for the road to fit in? Does the algorithm cares? Because if you are changing the heightmap like in the paper above, what happens with static LOD in terrain (e.g. geomipmaps)? On the other hand, if you are subdividing the road geometry, how can the algorithm guarantee that the correct diagonals (from heightmap quads) are used when creating road triangles?

2) Is it real-time? Can this be used in an editor where you can alter the spline in real-time in order to form the roads? I haven't searched much on the subject but i will definitely do so, so forgive my questions.

One last note on the UV problem when rendering arbitrary quadrilaterals. I've found this paper (Correcting Texture Mapping Errors Introduced by Graphics Hardware) which proposes an adaptive subdivision algorithm in order to eliminate stretching. What do you think about that? Is there any other method this can be done? It seems really easy to do, but i was wondering if the extra triangles worth it.

I hope the above makes some sense :) Forgive my English.
Thanks for reading this.

HellRaiZer
HellRaiZer
Original post by HellRaiZer
soconne :
Your approach is similar to what Battlefield 2 does for the roads (if i'm not mistaken), and imo both implementations suffer from the same problems.
1) The road may intersect the heightmap, or the road floats in the air, when the road spline has steep slopes (not enough resolution for the heightmap to follow the road)


That is why when I create the road, I edit the terrain vertices that lie within each road segment and force them to intersect with the bottom of each triangle's plane.

Quote:
2) Even if the heightmap can follow the road, there may be z-fighting because vertices don't have the exact same height.


I compensate for this by making the terrain vertices height equal to the road's height minus some epsilon value, such as 0.01 or something similarly small.

Quote:
3) When the spline creates sharp turn (like a 'U') there are UV artifacts. I've searched about that and it looks like a problem on how the GPU is rendering quadrilaterals. Check this page by Cass Everitt for a description on the problem. Unfortunately the solution proposed by Everitt of using the q-coord doesn't solve the problem, because if you do it the road texture will repeat more time in the U direction (road's width) and you don't want that.


The road is not made up of quadrilaterals, but triangle strips. I also do not suffer from the uv problem because the texture coordinates are no calculated per triangle, but rather by distance from the previous vertex. So the first vertex is given a u-coordinate of 0.0. Then the next one is given a u-coordinate of the distance it is from the first vertex. After this has been done for every vertice in the road, I then scale ALL the values down by some user-specified value.

Quote:
One last note on the UV problem when rendering arbitrary quadrilaterals. I've found this paper (Correcting Texture Mapping Errors Introduced by Graphics Hardware) which proposes an adaptive subdivision algorithm in order to eliminate stretching. What do you think about that? Is there any other method this can be done? It seems really easy to do, but i was wondering if the extra triangles worth it.


You could always try my road implementation in my software to see if you think its worth it. http://www.freeworld3d.org/downloads.html
Author Freeworld3Dhttp://www.freeworld3d.org

This topic is closed to new replies.

Advertisement