By seapegasus on Feb 02, 2010
So yeah well... I didn't submit my tutorial to the jME documentation contest after all (I was on an island without wifi -- don't ask), and nobody else submitted anything either, quite sad. The whole event happened at quite short notice and over the winter break, maybe nobody felt inspired to work. ;)
Anyway, here is my Terrains, Heightmaps, and Texturing article. I haven't fully written the section about terrain texturing yet, I'm still looking for the optimal combination of settings (texture units + texture size + procedural textures). But the tutorial already covers heightmaps and terrain generation and loading.
When I worked with terrains the first time, I kept adding translation constants and shifted and scaled them, all to get an intuition for how big they were, and where they would be rendered, compared to smaller models I loaded. Some terrains ended up being rendered smaller than expected, others bigger; some looked clear and smooth, and others blurry and angular; some were floating "in mid air" and others stuck to the "floor" (the x/z plane) or in a faraway corner. No details in the javadoc either. How mysterious. (Note to self: Get developer permissions and add javadoc!)
So I sat down and tried to find out: How does the terrain's heightmap size map onto world units? I have to scale every terrain (you will notice that, by default, they are too steep), is there maybe one obvious factor I can apply that makes them look more natural? What is the default position and size for a freshly loaded terrain anyway? And what is it after scaling? And lastly, how do I calculate the right values for the texture intervals in a procedural texture?
Since it's impossible to judge distances in the empty space of a 3D-scenegraph, lots of trial and error ensued: I created long white boxes (1\*1\*256) around the origin, to mark the x/y/z axes. I also marked points such as (128,128,128), (255,255,255), (0,0,255), etc with AxisRod objects. Finally, when looking at the terrain rendered next to these markers, the pattern behind heightmap values and world units became clear. When I now create a landscape with a water surface, I can predict which part of the terrain will be under water, and adjust the procedural texture accordingly. No blooming meadows on the sea floor anymore! :)
Next stop: Decreasing the blurriness of my terrain textures. Am I supposed to use the same detail texture on the whole terrain, or can I have several? If you have any best practices regarding jME texturing, please leave a comment. :)