January 5th, 2008
So far it was pretty straightforward. There were few choices but i always took the most simple route and got what i wanted. Now is the time to add some textures to the terrain. To look more real, surface must be covered with more then one textures. Different terrain types like water, grass or rocks are different textures. Multitexturing can be done in more ways and I’m not sure which way is best.
In XNA, recommended method is to use HLSL. I explored for some time and found out that this is the only way. That’s good. As Python developers said: there should be only one, most obvious way to do things. It’s not really obvious but it’s a good way. It require relatively new hardware (new as from year 2002) because of pixel and vertex shader techniques.
Alternative way to do multitexturing is to blend textures using CPU power while loading terrain before passing them to graphics card. Since CPU is bottleneck and GPUs are designed for such tasks it’s not reasonable to use a CPU.
Without blending, terrain can be generated using tiling. Every tile then can use one texture. Problematic part is terrain transitions. They must be created as a textures and and placed over bordering terrain types. It can be done and it will produce nice, retro look. But it’s probably not worth to use 2D techniques in 3D world. That way you’ll pick up problems from both styles while avoiding to use any advantages each of them can provide.
To use shaders, instead of BasicEffect we need to use custom effects which are written in HLSL. It’s awkward to leave friendly VS environment with autocomplete and keyword coloring and use plain text file and write with C++ syntax. Especially because i was hoping that XNA will make things easier. I’m sure the code in effect file could be auto generated, not only for basic effects but also for multitexturing. If somebody really need to mess with every vertex to pixel conversion let them open this generated code and change it later.
Fortunately there isn’t really too much about shaders to write. Once i got the theory right, I’ll managed to write one from scratch, trying to use only necessary features. In addition, there is no vertex structure with multitexture support, I’ve added one also.
I’ll work with four textures. In a game there should be some map editor to decide terrain types locations. To speed things up I’ll decide terrain type by tile height. Zero level is water, then some sand beaches, grass plains and snow on hills.
Resulting images:
with more interesting textures

