Using Alpha-Splat Terrain Textures with PnP TerrainCreator

From Multiverse

Jump to: navigation, search

Contents

Requirements

To follow this tutorial, you must install the following free, third-party software:

  • PnP Terrain Creator
  • GIMP 2.0

Also, you will need:

  • A mosiac setup and working in Multiverse of a PnP heightmap
  • A terrain map in PnP Terrain Creator that has been textured.

Finally, you should be comfortable editing a shader (.cg) file.

Additional notes

  • Remember you can only have upto 8 terrain textures at the current time in Multiverse, so choose wisely what textures you want.
  • In a future release of Multiverse they will be updating the terrain texturing system, so this is only useful is you want cooler looking terrain now.
  • Using alpha-splatting terrain texturing causes your world to take longer to load (however it looks a lot better).

Choose 8 terrain textures you want to use and give them a number (so it's easier to keep track), for example:

  • GrassNoFlowers.dds – 1 (red channel)
  • GrassandFlowers.dd – 2 (green channel)
  • DirtGround.dds – 3 (blue channel)
  • Rock2.dds – 4 (alpha channel)
  • DyingGrass.dds – 5 (red channel)
  • DeadGrass.dds – 6 (green channel)
  • SandstonePath.dds – 7 (blue channel)
  • DarkDirt.dds – 8 (alpha channel)

Export from PnP Terrain Creator

Open your world in PnP Terrain Creator so you are at the screen where you can view all the sectors and can right click to get a list of actions to take on that sector.

Choose a sector to work with first, then right click and choose Export. From the Export window choose: TextureMap Exporters – Texture Splatting Alphamap Export.

Set the File Format as PNG, Smoothfactor 2, Patchsize 1024 (assuming that's what you used for your heightmap terrain size). Leave the two other checkboxes unchecked.

Choose OK, then select a directory to save the files to. Export them into an empty folder, perhaps one with a name to indicate what sector it is.

Create RGB texture maps

In this step, you will merge the black/white texture maps together to make two RGB texturemaps

Before starting, note that if a certain texture was never used in that sector, it won't be exported, and so you may not get eight texture maps. If this is the case, just skip out the following steps for the missing texture files (for example, if the red channel file is not there, don't worry about it and deal with the green/blue/alpha).

  1. Open up the first texturemap file (so the one that goes in the first red channel) in GIMP. Use the Select Regions by Color tool (on the top row) then select a white spot (and this will select all of the white spots). If the white spots are too small, select a black area then use invert selection.
  2. Select the Draw in Ink tool and set the size to 200. Set the foreground color so it is full red (so 255r, 0g, 0b). If you are doing this for the blue or green channels, make it full blue or green (to match).
  3. Cover all the white area in the new color so now you have a red and black texture image.
  4. Grab the next texture file (so if you just done the red channel, grab the green channel etc.) and open it in Gimp. Then copy the whole image and paste it over the image we were working on.
  5. Open the Layers Dialogue (Ctrl-L) and then right-click on the floating selection (Pasted layer) and choose New Layer. This causes the pasted image to be put in a layer on top of the previous one.
  6. Use the select by color tool and select the black area of the current image. Then right click on the texture and choose Edit – Clear. This deletes the black stuff so you can see the texture below.
  7. Right click again and choose Select – Invert. Then cover the area with the color this layer should be (so for me it will be green).
  8. If you still have the blue layer to do, just repeat the above steps where you paste it over the top and clear away the black stuff etc.

When that is all done you will have a RGB file that will contain red, blue and green spots to show where the texture that corresponds to that channel goes. You will now want to flatten the image and save the file.

Add the alpha channel to the RGB texturemap

Open up both the texturemap for the alpha channel and the RGB texture map that was created from the previous step.

Invert the alpha-map texture map so all the black areas are now white (and vice-versa). You can do this by choosing Layer – Colors – Invert.

Copy the whole texture and paste it over the RGB texture, then conver the floating selection to a new layer.

Now select by colour and select a white section then right click and choose Edit – Clear. Then invert the selection and then in the Layers Dialogue select the background layer. Then choose Layer – Mask – Add Layer Mask. From the options there choose Selection.

Now everything except the a few black areas will disappear! /shock. Well that is supposed to happen.

Finally, go Layer – Mask – Apply Layer Mask. Then select the layer that was pasted above and delete it. Now save the file as a png again and you are done for that 1 file (wow what a lot of work).

Downsizing the alpha-map (optional)

Due to the nature of alph-maps and textures, if you keep all your alpha splatting maps at 1024x1024, video cards with 128MB of memory or less will take a few minutes to load the world. So, for reasonable performance on low-end systems, downsize the files to 512x512.

To do so, just open up the file in GIMP again and choose Image – Scale Image. Set the size to 512x512 and MAKE SURE YOU SET THE INTERPOLATION MODE TO NONE!!!

Now save the image.

Create second alpha-splatting map

Repeat the following steps for the second alpha-splatting map:

Repeat the process to make the second alpha splat map.

Repeat for other world sectors

Repeat all the previous steps for each sector of your world.

Well I cheated a bit here, and just used blank black files for all the sectors of the world people can't get to yet, otherwise this would take ages. By just putting in a blank black texture it will make the texture show up weird in that sector, however no one will see it yet so it doesn't matter.

Set up the mosaic files

In this step, you will set up the .mmf files (you will need two).

Just copy the heightmap .mmf file and rename it (and then make sure the alpha-splat maps names match).

If you changed your alpha maps to 512x512, then change the following lines to reflect the size change:

#nPxlsX: 8324
#nPxlsY: 5120
#SubMapSize: 512
#HorizScale: 2

Normally mine would read:

#nPxlsX: 16384
#nPxlsY: 10240
#SubMapSize: 1024
#HorizScale: 1

Put the files in the right place

When you are ready to move on, move all the alpha-splatting files along with the .mmf files and the actual terrain texture files into the Textures folder of your asset repository.

Load in the Multiverse World Editor

Load your world in the Multiverse World Editor. Then in the tree view, expand the world node then click on Terrain. From there you can set the terrain texturing type. Change this to alpha-splat.

Under Terrain Display enter in the file names for your mmf files and the terrain textures you want to use. For the detail map use l3dt-detailmap.jpg (comes with the default MV assets).

Alter the shader to remove black and highlighted spots

In this final step you are going to alter the AlphaSplatTerrain.cg file (n the Sampleworld GpuPrograms folder) slightly.

If you got to this step in the tutorial and you have loaded the terrain in the world editor you will notice there are some spots where there are black spots on the terrain or bright yellowy spots. Due to the smoothing of the terrain texturing, some spots ended up with not enough texture coverage while others got too much. So the plan here was to alter the shader so it checks how much texture is being applied, then normalises it.

So basically open up the cg file in a text editor (I recommend PSPad) and scroll down to line 129 where the fragment shader starts:

float4 TerrainFP

Now after the following lines:

  alpha0 = alpha0 * alpha0Mask;
  alpha1 = alpha1 * alpha1Mask;

Paste in:

  if (alpha0.r + alpha0.g + alpha0.b + alpha0.a + alpha1.r + alpha1.g + alpha1.b + alpha1.a != 1.0) {
     float total = alpha0.r + alpha0.g + alpha0.b + alpha0.a + alpha1.r + alpha1.g + alpha1.b + alpha1.a;
     if (total < 0.3) {
         alpha0.a = 0.99;
     } else {
         alpha0.r = alpha0.r / total;
         alpha0.g = alpha0.g / total;
         alpha0.b = alpha0.b / total;
         alpha0.a = alpha0.a / total;
         alpha1.r = alpha1.r / total;
         alpha1.g = alpha1.g / total;
         alpha1.b = alpha1.b / total;
         alpha1.a = alpha1.a / total;
     }
 }

Now load up the terrain and the black spots and highlighted spots should be gone.

Personal tools