# Smooth terrain rendering

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

-
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

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.

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.

-
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