=================================================================================== Importing a Skybox from Terragen, By Jason Otto 11/22/2004 =================================================================================== Starting babble Terragen is a free program available at http://www.planetside.co.uk/terragen/ which is capable of creating realistic terrains for a variety of uses. This tutorial will cover the steps needed to convert an environment in Terragen into a usable skybox for the Dark Engine. This tutorial will assume that you've got a basic handle on the operation of Terragen. Information regarding its use is available at the above URL. =================================================================================== Step One: Create an environment in Terragen, an important consideration is the sun position, which will effect the lighting steps in DromEd. Note the longitude and latitude of the sun in Terragen for future reference. =================================================================================== Step Two: First set the image size to 256x256 and the detail level to high. Also set the camera zoom to one. Place the camera at the middle of your environment, 4000/4000/0 works nicely. Then point the camera at 4000/0/0 which is due south, render an image. Then point the camera at 4000/8000/0 which is north and render an image. Then point the camera at 0/4000/0 which is west and render an image. Next point the camera at 8000/4000/0 which is east and render an image while still pointing east change the pitch of the camera to +90 and render an image, this is the top. Finally point the camera pitch to -90 and render an image, this is the bottom. =================================================================================== Step Three: Open an image editing program, open the six images collected previous. these images are 256x256 true color bitmaps. create a new 1024x768 true color bitmap. into this new large image past each of the images collected, west, north, east, south through the middle, then above east paste top, and below east paste bottom. The images should appear in a sideways t shape. This allows a quick check of the fit of the seams and a common palette to be created. =================================================================================== Step Four: Decrease the color depth to 256 colors, this may take several attempts to achieve a color scale that is satisfactory. Edit the palette, change index 0 to bright pink and then with the color replacement tool change all the bright pink to the color in the palette nearest the original index 0 color. =================================================================================== Step Five: With the common palette created you can now save the palette for later use. Cut the individual images from the larger image naming the west image NskyW.pcx, the north image NskyN.pcx, the east image NskyE.pcx, the south image NskyS.pcx, the top image NskyT.pcx and the bottom image NskyB.pcx. Each of these images should be using the same palette that was created earlier. Now select any file and save as full.pcx to create the full palette file for the family. These seven images are saved in the folder fam/skyhw. =================================================================================== Step Six: In DromEd select Editor>Mission Parameters>Sky Rendering Mode>Textures. In the command box type the command load_sky nsky. This will load the sky that was created into the editor. =================================================================================== Step Seven: The sun light source. If there is a sun visible in the distant art it can be a source of light for your level. Remembering the longitude and latitude of the sun in Terragen the source of the sun light is known. Under Editor>Mission Parameters>Rendering Parameters set the hue 0-1, saturation 0-1 and brightness 0-1023 for the sun. The position of the sun is calculated by the x,y,z values which are vectors denoting the direction the sun points. =================================================================================== Step Eight: Time for some trig. The 3D world of the Dark Engine is layed out with the following conventions. North to South is the X axis West to East is the y axis Top to Bottom is the z axis South is 0 degrees, +1 East is 90 degrees, +1 North is 180 degrees, -1 West is 270 degrees, -1 Top is 0 degrees, +1 Bottom is 180 degrees, -1 To calculate a sun light source determine the position of the sun in the world if the Dark Engine conventions are followed. Sun light is a vector, the sum of an x,y and z component. Thus if the sun is directly overhead the vector is 0,0,-1. Things get tricky at unusual positions. For example a sun light source at a heading of 70 degree and an altitude of 5 degrees in Terragen is the same as a sun light source at 110 of longitude and 85 degrees of latitude in the Dark Engine. To light this the x,y,z components must be determined. In the Dark Engine the sun in this position is 20 degrees north of the west-east line and 5 degrees above the north,south,east,west plane. To determine the vectors assume that the sun source is one unit from the origin. Then the vectors are all simple tangent functions. The x angle in this instance is 20 degrees, the tangent of which is 0.364. The y component can be determined from the x component by the pythagorean theorem. (1^2-.363^2)^(1/2)=0.932. The z component can be determined like the x, the tangent of 5 is 0.087. Then it is essential to determine the direction. In the example the sun is pointing to the southwest from above the ground, thus the x vector is pointing south and is thus positive, the y vector is pointing west and thus negative and the z vector is pointing down, ths is negative (as nearly all z vectors will be in the Dark Engine). =================================================================================== Step Nine: The sun light can not be shown in DromEd until objcast lighting has been done. =================================================================================== Results: The result is a nice looking distant scenary with a light source, the light is directional, adding light only to one side of a building and casting shadows from the other like a real sun would do. The only drawback is that the 256 color palette restriction can make some beautiful true color skyboxes look poor in game. =================================================================================== Application: Any mission with large outdoor areas that are visible, there is no need to set up a sun light source in Terragen, so distant hills and mountains could surround your mission at night as well. Skyboxes are the preferred method for distant art in large outdoor areas, the newsky setting in DromEd are better suited to tight streets where its hard to see anything but whats above.