Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to render a smooth terrain with Direct3D. I've got a 50*50 grid with all y values = 0, and a set of 3D points that indicate the location on the grid and depth or height of the "valley" or "hill". I need to make the y values of the grid vertices higher or lower depending on how close they are to each 3D point. Thus, in the end I should have a smooth terrain renderer.

I'm not sure at all what way I can do this. I've tried changing the height of the vertices based on the distance to each point just using this basic formula:

dist = sqrt(a² + b² + c²)

where a, b and c are the x, y, and z distance from a vertex to a 3D point. The result I get with this is not smooth at all.

I'm thinking there is probably a better way.

Here is a screenshot of what I've got for the moment: https://dl.dropbox.com/u/2562049/terrain.jpg

share|improve this question
1  
For one thing, the formula you've given is for the distance squared, not the distance. It should be $dist = \sqrt{a^2 + b^2 + c^2}$. –  James King Sep 12 '11 at 21:39
1  
Your screenshot is broken. I'd suggest uploading it to imgur or something. –  Tetrad Sep 13 '11 at 15:55
add comment

2 Answers

up vote 4 down vote accepted

Is there something special about these 3D points because it sounds like you are just trying to render a heightmap. Doing a bunch of distance calculations to an arbitrary number of 3D points is not the best way of doing that.

Here is a simple DX9 tutorial on rendering a heightmap.

The basic concept is that you have a 2D image that represents displacement. So the pixel (X,Y) location corresponds to a vertex (X,Z) and the color of the pixel represents a height value (Y) for the vertex.

The nice part about using an image is that it's very intuitive for the developer to visually create and or modify the terrain.

EDIT: Looked at the screenshot. It seems to be working to me, I assume you aren't happy with the falloff of the effect? Smooth at the ground level and then a spike at your 3D point.

If you took any of your mountains/valleys and imagined them in 2D and cut them in half you'd see a curve that looks like the one on the left and I'm guessing you want one that looks like the curve on the right.

alt text

Instead of looking for the 3D distance to your 3D point I suggest look at the 2D distance ignoring the height. Then for every vertex within some predetermined falloff, apply the height to your vertices based on a ease in/out curve.

share|improve this answer
    
No, I'm not rendering a height map. I just have a few "height points", they indicate where the top of a hill or a valley might be, but there is not one height value for each vertex. I posted a screenshot, it might help. –  dotminic Dec 27 '10 at 23:44
    
Yeah I sorted that out on my own after I posted this question, using a Quartic curve from an AS3 tweening engine. I was still missing the predetermined falloff. Thanks alot for your help. –  dotminic Dec 28 '10 at 16:00
add comment

If you're looking to create smooth rolling hills you can use the box-filtering method. Be warned though, if you want sharp cliff edges, the method will just smooth those out.

Here's the link to it on GameDev.net: Box Filtering for Smooth Rolling Hills

The code assumes you're using a heightmap, but from your solution an easy change to make is just to iterate through the list of 3D points (mapping those 3D points to the appropriate vertex, as you are doing now).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.