Ground polygons (ASM tweak)
How to create ground polygons with GMax is an often asked question. This article will try to guide you through that process, as it takes some tweaking to get the correct results.
How to create your ground polygons is outside of the scope of this article. Basically you can just draw them like any polygon and then map the texture you want on it. The only difference is that the polygons are on the ground, so they have a z-coordinate of zero. If you want polygons with smooth corners, follow the instructions in the tutorial Ground polygons with Gmax - How to create the polygons.
Please note that if you want your ground polygons to be compatible with FSX (with the SP1 or later installed), you need to make sure that the vertices of your ground polygons are not further away from each other then 100 meters. So if you have a big polygon, you might have to split it into smaller pieces. If you keep this additional restriction in mind, you will not have trouble with the added earth curvation of FSX.
FS2002 gamepack
The first complication is that you need to use the FS2002 gamepack (Installing the FS 2002 Gmax-SDK). This is because the MDL format used by the FS2004 and FSX gamepacks is not really suitable for creating ground polygons. When using them you for example get flickering polygons and the shadow of other objects is also not displayed correctly on them. With the FS2002 gamepack we can apply some tweaks to prevent these trouble.
But you can not download the FS2002 gamepack from the internet, some files only came with the FS2002 Pro CD. So if you don't own that version of FS (anymore) you have a little problem. A work around is to use MDLCommander with the FS2004 gamepack and then run the X file that you saved through the FS2002 MakeMDL manually.
Be sure that you use the latest version of the FS2002 MakeMDL, as the initial version does not allow you to save the ASM source files that you need to tweak later on. For a basic introduction to saving and compiling ASM source, please refer to this article.
Tweaking the ASM code
So now that you have saved your ASM source files, it is time to start tweaking them. What we are going to change in the ASM file are a few commands that by default call your polygons as if they are a 3D object. But there is also another call for ground polygons, when this call is used the flickering and shadow problems are solved.
So open your main ASM file and look for the following lines of code:
OBJECT_0_START label word IFIN1 OBJECT_0_FAIL, image_complex, 2, 32767 ADDOBJ OBJECT_0_SCALE SHADOW_CALL OBJECT_0_SCALE OBJECT_0_FAIL label BGLCODE
In this code the ADDOBJ command is the one that is calling your polygons as a 3D object. So this is the one we will change in the ADDCAT command used for ground polygons. The ADDCAT command also has an additional parameter that sets the layer of your ground polygons. So this can be used to layer different ground polygons on top of each other. In this article we will set the layer to 8, it is common practice to use only layers that are a multiple of 4 (so 0, 4, 8, 12, 16, 20, ...).
We will also remove the SHADOW_CALL command, as ground polygons are not really able to cast a shadow on the ground. So after applying these two tweaks you are code should look something like this:
OBJECT_0_START label word IFIN1 OBJECT_0_FAIL, image_complex, 2, 32767 ADDCAT OBJECT_0_SCALE, 8 OBJECT_0_FAIL label BGLCODE
One final note. This change only works if your source only contains ground polygons. If you have a scene with both ground polygons and 3D objects, use the "Export selected..." feature from GMax to export the ground polygons and the 3D objects seperately from each other.
Complex example
In this last section I want to give a little more complex example. Assume you are making an airport that has different layers, how could you easily manage that? I will show you how I do that.
In GMax you create all polygons that you need. In this example I will assume that there are three different layers:
- photo
- noise texture
- aprons and taxiways
The noise texture is a layer I added to make the grass in the photo texture look less blurry when you are taxiing on it. It uses a transparent texture that adds random dots. Each of these three layers are exported separately from GMax. I used the following name:
- ehdr_photo.bgl
- ehdr_noise.bgl
- ehdr_aprons.bgl
Of course for each BGL file there were also two ASM files saved. What I did next is copy one of the main ASM files and then edit it so that all three layers are called from this single file. I made a copy (and renamed it ehdr_ground_layout.asm) so that the tweaks will not be overwritten the next time I export from GMax. All I have to do after such a new export, is compile the ehdr_ground_layout.asm file again. This is the ASM I use:
header label word dw 0001 ; 00 World set number dd 0005A174FH ; 02 North bound dd 0005A0E5BH ; 06 South bound dd 0045BEF71H ; 10 East bound dd 0045BEF6FH ; 14 West bound dw 20 dup(0) dd (offset OBJECT_DATA) - (offset header) dw 33 dup(0) OBJECT_DATA label word db 21 ;;LATBAND_REL dw 02D07h ;;lat min (inclusive) 512M units dw 02D0Ch ;;lat max (exclusive) dd (offset OBJECT_0) - (offset OBJECT_DATA) db 0 ;;EOL OBJECT_0 label BGLCODE db 12 ; NEAR_FAR_HUGE_OBJECT_HEADER dd 0005A12D5h,0045BEF70h ; latitude,longitude db 100 ; image power dd (offset OBJECT_0_END) - (offset OBJECT_0) OBJECT_0_START label word ADDCAT OBJECT_0_PHOTO, 8 ADDCAT OBJECT_0_NOISE, 12 ADDCAT OBJECT_0_APRON, 16 BGL_JUMP_32 OBJECT_0_END OBJECT_0_PHOTO label word SCALE_AGL OBJECT_0_RETURN, 20000, 1146, 131072, 0005A12D5h, 0E82Dh, 0045BEF70h, 0AD0Ah, 0, 0 BGL_JUMP_32 OBJECT_0_PHOTO_0 OBJECT_0_NOISE label word SCALE_AGL OBJECT_0_RETURN, 5000, 1146, 131072, 0005A12D5h, 0E82Dh, 0045BEF70h, 0AD0Ah, 0, 0 BGL_JUMP_32 OBJECT_0_NOISE_0 OBJECT_0_APRON label word SCALE_AGL OBJECT_0_RETURN, 10000, 1146, 131072, 0005A12D5h, 0E82Dh, 0045BEF70h, 0AD0Ah, 0, 0 BGL_JUMP_32 OBJECT_0_APRON_0 OBJECT_0_RETURN label word BGL_RETURN OBJECT_0_PHOTO_0 label word include ehdr_photo_0.asm OBJECT_0_NOISE_0 label word include ehdr_noise_0.asm OBJECT_0_APRON_0 label word include ehdr_aprons_0.asm OBJECT_0_END label word EOF
The first part is the BGL header and the data used to place your polygons at the latitude and longitude that you entered during the export. Just copy this and don't change it. Below that you will see that I placed three ADDCAT command below each other, each calling a label that calls the ASM file with the actually polygons that GMax created. The SCALE_AGL command after the label is the reference point, so you can just copy it around and use it for all your layers. Of course you need to copy it from your own ASM file and not from this example, as your polygons will end up on the wrong location else.
You might also notice that the code in the ASM file looks a little different from the main ASM file that MakeMDL made. This is because I cleaned it up as much as I could, removing all unnecessary code and calls. But hopefully this example still shows you how you can combine all your ground layers in one BGL file.