Featured contribution

Top  Previous  Next

Multi terrain / sunlight shader

 

This time we are going to examine a shader that blends the terrain texture (its 1st skin) with 3 different bitmaps (grass, road and sand) according to the bitmap (the mask) that's stored as the second skin of the terrain. The shader needs a VS / PS 2.0 card or a better one.

 

aum56_shader1

 

This is what you are going to see when you run my demo; press the "zero" key if you want to move the camera around. The textures blend nicely, but you don't take my word for it - see for yourself:

 

aum56_shader2

 

How can you use this great looking shader in your own projects? Follow these simple steps:

 

1) Create a terrain and use your base texture (the dark grey texture in my pictures) for the first skin;

2) Add another skin to the terrain and paint it using the following colors: black (transparency), red (grass), blue (sand), green (road);

 

aum56_shader3

 

3) Use the bitmaps that come with this demo for the detail map, grass, sand and road or create your own bitmaps;

4) Include multirgb.wdl in your main script file, place the terrain in the level and attach it the action named multi_terrain. That's all!

 

Want to test my demo? Copy the \multiterrain folder inside your 3DGS folder, open multirgb.wmp, and then run it using main.wdl. That's it!

Wait a few (10-20) seconds to see the effect of the sunlight and then press the "F" key to toggle the fog on / off. Examine the script files to see what can be tweaked and how.

 

Special thanks go to Thorsten Kunze, who has created this shader, and to Ello, who has added the sunlight code to it.