Need simple 3D terrain render with big texture map

by zetar   Last Updated July 16, 2016 08:05 AM

I have a 1000 x 700 height map enter image description here

I have a 1000 x 700 texture map enter image description here

I did something very similar about 8 years ago: enter image description here

Using XNA. Unfortunately, when I bring up this old project and convert it to Visual Studio 2010 it will no longer compile and just throws tons of errors.

I'm looking for something very simple. Is there a 3D terrain single texture XNA example floating around out there that I can convert? I haven't touched XNA since about 2009 or 2010 and none of my old code will run anymore (I have no idea what's going on).

I need to do a 3D terrain proof of concept where the terrain texture is stretched over the height map. Nothing fancy. Maybe XNA.

Any ideas?



Answers 2


A basic height map can be produced as follows:

Generate a set of vertices that form a grid made of triangles in a regular pattern like

 A -- B -- C -- ...
 | \  |  / | \
 |  \ | /  |  \
 D -- E -- F -- ...
 |  / | \  |  /
 | /  |  \ | /
...  ...  ...

Each of A, B, C, et cetera represents a vertex in the grid. It also represents a point on the height; read the height value from the map at the appropriate point and use that times some scalar factor to set the Z coordinate of the vertex.

You can generate the UVs at each point by stepping by (1 / number of cells) in either dimesion; this will let you easily map your texture onto that geometry as well.

Then render the geometry with your color map.

Josh
Josh
July 15, 2016 22:33 PM

I have been able to do this using the 3d modeling software Blender. I used UV mapping to map the texture and the displacement modifier to apply the height map. If you need some form of XNA code for this, I cannot supply it. Here it is as a 3d terrain. Surprisingly, it worked best on a uniformly square mesh.

The steps required to create the terrain like i did in blender:

  1. Download blender for your operating system from here.
  2. Install and open blender.
  3. Delete the default cube by right clicking on it and hitting Del then Enter.
  4. Press shift-a and select Mesh->Plane from the dialogue box that pops up and press Enter.
  5. Scale it up a bit by pressing s and dragging your mouse towards the corner of the screen. Then press Enter.
  6. At the bottom of the window, towards the left, you will see a dialogue box that says Object Mode. Change that to Edit Mode.
  7. Make sure the whole plane is selected. The edges, vertices and faces will be highlighted in orange if it is selected. If it is not, press a to select all of the mesh.
  8. Press w and select Subdivide from the dialogue box that appears. Do this about 5 times.
  9. On the far left towards the bottom of the screen, you will now see a new section appear with one field being called number of cuts. Change it from 1 to 8 or whatever resolution you want for your terrain.
  10. Now with the whole plane selected, press u and select unwrap from the dialogue box. This will take more time if you did more subdivisions.
  11. On the center top of your screen, select the dropdown menu that says Blender Render and change it to Cycles Render.
  12. On the middle right hand side, you will see a window section with small buttons that look like a camera, a photo, some primitive shapes, a globe, etc. Click on the button that looks like a tiled sphere.
  13. Click on the button that says New. You have now created a new material. To apply the image to your plane, on the section that says Surface, go to the field called Color and click on the small dotted box next to the color. From the popup box, under Texture select Image Texture.
  14. Navigate to your image and select it.
  15. Now, making sure you are in Edit Mode, select the whole plane and press u and select Unwrap from the dropdown menu. This may take your computer anywhere from 10 seconds to 2 minutes and the program may freeze depending on how many subdivisions you did.
  16. Navigate back to the window with all the buttons and look at the top left of that window. You should see a symbol that looks like two pills with up and down arrows next to it. Select it and select UV/Image Editor from the dropdown menu.
  17. At the bottom of the UV/Image Editor window, you should see a button that says Open. Select it and navigate to your texture again. That should do it for texturing.
  18. If the orange rectangle (your mapped mesh) doesn't perfectly fit the rectangle of the texture, scale the rectangle in the UV/Image Editor window with s. Then press x for x axis scaling or s and then y for y axis scaling. And move it with g and x for x axis translation and g and y for y axis translation. Press enter each time you finish a transformation/scale. Try to fit the rectangle as well as you can to the image. Otherwise, just leave it as is.
  19. Navigate back to the button you clicked at the top left of the window (it is now on the bottom left) where the pills were previously and now the UV/Image Editor icon (looks like a photo of a sunset) is and select Properties (the pill icon) from the dropdown menu.
  20. Now from the buttons, select the one that looks like a wrench. Select the Add Modifier dropdown and select the Displace option from the dropdown menu.
  21. Where you see the Texture section of the Displace modifier, click the New button.
  22. Where the tiled sphere, primitive shape, wrench, etc are, select the one that looks like a tiled square.
  23. From the dropdown box where it says Image Texture select Displace - Texture instead.
  24. In the Image section, select Open and find your height map and select it.
  25. Click on the Image Mapping section and select Clip.
  26. Switch to Object Mode and see how the displacement map worked out. If there's a section that looks too straight on the edge either going straight up or dipping down, go back to edit mode, select your plane with a, and scale it up or down a tiny bit with s. Keep doing this until it's fixed.
  27. Go back to the wrench and in the Displace modifier, change the strength to something like .2
  28. Now to view the model textured, next to the Object Mode dropdown, there is a sphere dropdown. Select texture instead of solid.
  29. As one final step, there is a window on the top left with a section called Shading. Click on smooth. And you should get something like the results below.

enter image description here enter image description here

Orren Ravid
Orren Ravid
July 15, 2016 22:56 PM

Related Questions



Diamond square texture: too-diamond-ish?

Updated November 20, 2017 07:13 AM

Heightmap, how can i prevent bad odd numbers

Updated August 03, 2015 14:05 PM