Difference between revisions of "An Advanced Terrain and Megatexture"

From Mod Wiki
Line 235: Line 235:
 
* The '''Distribution''' mask is made slightly darker where the sand '''Distribution''' is.  This will give good variation, as the Pebbles will blend in first (due to '''Distribution Pattern'''), making them appear to be on sand instead of mud.
 
* The '''Distribution''' mask is made slightly darker where the sand '''Distribution''' is.  This will give good variation, as the Pebbles will blend in first (due to '''Distribution Pattern'''), making them appear to be on sand instead of mud.
  
 +
 +
;Rock
 +
* A new '''Group''' is created under the '''Root''' node to keep the rock elements neatly together.
 +
 +
 +
;Rock Base
 +
* Rock should usually be created (distributed) near the start of making a megatexture, as rock usually effects where all other elements will be distributed.
  
 
=== Road Tool ===
 
=== Road Tool ===

Revision as of 16:03, 7 December 2007

This guide will show you step by step, on how to create a detailed Megatextured Terrain.

AdvMega Intro.jpg

Introduction

For this tutorial you must:

  • Have a modelling package that can export as LWO, ASE or OBJ
  • Have basic modelling skills
  • Have basic mapping skills, as in A Simple First Map

This tutorial covers:

  • Steps to create a detailed terrain mesh.
  • How to assign the Megatexture
  • How to add the terrain mesh to a map
  • How to make a Megatexture
  • How to compile a Megatexture
  • How to add Water to a map

Programs used in this tutorial are:

  • Mudbox
  • World Machine
  • Lightwave
  • Maya (only used briefly)

Other similar programs can be used instead of these, but wont be covered in this tutorial.

This tutorial does not cover in detail:

  • How to use Mudbox / ZBrush / World Machine / Blender / Lightwave / Maya / 3DSMax

If you already have a terrain mesh, and do not want to use Mudbox and World Machine, skip to Prepare Terrain for Megatexture .


Mudbox: Shape the Terrain

Mudbox Layers

These are the basic steps for sculpting a terrain in Mudbox.

  • Create a plane, and subdivide (but still keep a low tessellation).
  • Change any tools you use to have the edit Direction set to Y axis.
  • Create a new Layer, and sculpt the rough layout for the terrain.
  • Subdivide again to as detailed as you want (or can).
  • Create another layer, and sculpt more details into the terrain.
  • Export to OBJ.




Convert Mesh to Heightmap

This step is needed if you want to import your current terrain mesh into World Machine.

  • Firstly, rotate the terrain mesh. In Lightwave, rotate -90° around the X axis. For 3ds Max & Maya, rotate +90° around the X axis.
  • Cap any holes in the mesh, and triangulate. Using a machine with an nVidia graphics card, run the following command in the ETQW console to get the heightmap (where [model] is pointing to the relative path of the .lwo, .obj or .ase mesh):
RenderBumpFlat –floatHeightmap -size 2048 2048 [model]
  • An .r32 (raw 32-bit) heightmap will be saved into the same folder as your model, and this heightmap can be used in World Machine.


World Machine: Adding Flow

World Machine Device View
World Machine Heightmap
Flow Map

World Machine (World Machine Blog) is used to add erosion flow lines to the terrain. It's also useful as the flow maps can be exported to help create masks for texture distribution later in Terrain Editor. These are the basic steps made to build the World Machine device nodes.

  • Blend the heightmap made from the Mudbox mesh with perlin Noise to help the Erosion filters.
  • Use a snow filter around the rocks (mask used), so rocks look like they are sitting in soil.
  • Pass the heightmap through two Erosion nodes, which are set up differently, and combined give a natural flowing look. Both Erosion nodes are masked around the rocks, so they will keep their shape. The first Erosion node is setup as Channeled Erosion with an Inverse Filter, calving large flow lines into the terrain. The Second is a Channeled Erosion set with No Filter , adding finer detailed flow lines.
  • The heightmap output of the erosion is split so the heightmap can be saved (and later used to create a mesh), and further filters created (sediment and normal map) to help make masks for texture distribution later.
  • Flow and Deposition maps from the Erosion nodes are passed through Simple Transformation nodes that brighten the output saved.
  • The heightmap saved above is imported and rendered at a lower (usable) resolution to the Mesh Output node creating an OBJ mesh.



High to Low poly

Polygon Dags to Delete

This stage will briefly explain how the high poly mesh exported from World Machine, can be reduced down to the low poly game mesh.

  • Load the OBJ exported from World Machine into your preferred 3d Application.
  • Rotate so it's orientated correctly.
  • The outer mesh border will look like it's been dragged down (an artifact from the mesh being built from a heightmap). So remove this by selecting the mesh border polygons and delete.
  • Triangulate and save out as OBJ, so it can be loaded into Lightwave.
  • In Lightwave use a plug-in called qemLOSS3(once installed, found in the Utilities tab) to reduce the polygons to a reasonable amount (Enemy Territory : Quake Wars used around 32,000 polygons for the 32,768 unit width terrain). If you have trouble running qemLOSS3, apply a different material other than the default.
  • Fix edges that are triangulated in the wrong direction.
  • Smooth subdivide the mesh, and run your mesh through qemLOSS3 again (to the same polycount as before). This will give a smoother terrain, easier for gameplay. Reapeat until you're happy with the mesh smoothness.
  • Again fix edges that are triangulated in the wrong direction.
  • If you plan on having water, cut the mesh along the waterline. So no polygons are both above or below the water. This is so water fog has a clear line where to stop.



UV Layout

UV the Terrain

This process is written for Maya, other 3d packages will have to modify the process.

  • To achieve relaxed UV borders use a mel script called worldSpaceUVLine - it can be found on Highend3D. Copy the .mel into your My Documents\maya\#.#\scripts folder and run by typing worldSpaceUVLine; in the Maya command line.
  • Snap all 4 corners to the UV 0-1 square. Select all the edge uv for one side, and in the worldSpaceUVLine tool select the corresponding UV layout direction (U for horizontal, V for vertical), and press the align UV’s on selected line button. Repeat for each side.
  • Make sure all holes in the mesh are capped, and run the Relax UVs tool, with the option Edge Weights set to World Space, and Pin UV Border selected. Keep repeating Relax UVs until you see no more UV movement.




Low Poly Mesh with Local Map
Perturbate Image (Tangent Space Local Map)

Perturbate Image (Normal Map)

The Perturbate Image is an image that is applied to the megatexture, and corrects the low poly mesh normal to match that of the high poly.

  • Load the high and low poly mesh into your preferred 3d Application.
  • Surface sample the high poly normals onto the low poly, with normals set to tangent space.
  • You Probably will need to fix the normal map channels (red and green) as the 3D Application use normals maps differently to the Game. Make sure the green channel has white facing down, and red has white facing right.

Convert World Machine masks to UV space

All the masks created created in World Machine (flow, deposition...) wont match the new game mesh UV's

  • Load the high and low poly mesh into your preferred 3d Application.
  • Duplicate the game mesh and apply a planar UV projection.
  • Apply the masks created in World Machine to the planar mapped mesh.
  • Surface sample the diffuse from the planar mapped mesh, onto the game UV mesh.

Also render the mesh normals (world space) to an image. The blue channel will become useful when creating distribution masks, as it represents how vertical a polygon is.


Prepare Terrain for Megatexture

Now the mesh is nearly ready for the game, just a couple more steps.

Prepare the Mesh

  • Scale the game mesh to the correct size, as after converting from a heightmap it probably isn't the right size. This tutorial mesh is a small 8,192 x 8,192 unit mesh (again the Enemy Territory : Quake Wars terrains were 32,768 x 32,768.
  • Rename the material to megatextures/sdk/terrain_mesh_sdk (megatextures/<map_name>). Maya will have problems with this naming convention.
  • Set the Mesh normals to be smooth.
  • Save the mesh to base/models/terrain/sdk/terrain_mesh_sdk.lwo (<map_name>.lwo or .obj to base/models/terrain).

Setup the Material

  • Create base/materials/megatextures_sdk.mtr
  • Add the following text, to create the material, and save:
material megatextures/sdk/terrain_mesh_sdk	{ useTemplate megatextures/default_ambient< "sdk/terrain_mesh_sdk" > }


Construct the Megatexture

This section will cover the step by step creation of the megatexture using Terrain Editor (an inspector tab in EditWorld). For Detailed explanation on feilds and setting not discussed here, check out the Terrain Editor

Set up the Map

  • Load EditWorld, and create a new map.
  • Bring up the Terrain Editor inspector.
  • RMB in the left blank (white) area. In the pop-up menu select New | Tree...
  • On the Root node set the model field to base/models/terrain/sdk/terrain_mesh_sdk.lwo, and also set the ST Model to the same model. If you have holes in your mesh (holes cut for buildings), you'd need to make a separate ST Model version with no mesh holes.
  • Seal the map up by Creating a Caulk Hull. Make sure the origin of the terrain mesh is inside this hull.
  • For the area to be lit by the sun, create a brush inside the caulk hull, textured with 'editor/outsideportal'.
  • To set the atmosphere create an Atmosphere entity and set atmospheredecl to Valley01 (or what ever atmosphere you're using).

Detail Textures

Also on the Root node is where the detail textures are assigned. In each of the layers created, you assign which of these 4 detail textures to use. Detail Textures need to be a greyscale 512x512 texture (preferably saved in base/textures/detail/).

Detail Texture 0 textures/detail/temperate_dirt.tga
Detail Texture 1 textures/detail/temperate_grass.tga
Detail Texture 2 textures/detail/temperate_gravel.tga
Detail Texture 3 textures/detail/temperate_rock.tga

Image Sources

Here we'll start to create the texture layers that build up the Megatexture.

Ground_Base
  • Create a Group node, RMB and with the pop-up menu select New | Group. In the right field you can enter a name for the Group, we'll name this one Ground_Base.


Dirt
  • Now we'll create a base Image Source node. RMB over the Group node, and create an Image Source node, this should create it as a child to the Group. If you accidently created the Image node under the Root, don't worry as you can drag and release over the Group node to make it a child. Name the Layer Dirt, same way as the Group node.
  • Apply a Diffuse texture by selecting Diffuse on the right hand panel of the inspector, then selecting the File Name field and press the ... button to choose a texture. For this layer we'll use textures/megagen/temperate/dirt_06_d.tga
  • Repeat the same process for the Local image by selecting Local on the right, and applying the texture textures/megagen/temperate/dirt_06_local.tga
  • As this is the base layer, the Distribution needs to cover the whole map. So apply a full white image the same way as above but to the Distribution.
  • This layer is a dirt layer so I'll set the the Detail Texture Type to 0, to match the number for the dirt detail texture.
  • Also as this layer is dirt I'll set Sur Type Properties | Type to dirt. For a full list of usable surface types, check the Surface Type section.
  • The diffuse texture has the dimensions 1024 x 1024, while the map covers 8192. To keep the correct texture ratio, set Texture Properties | Scale to 8 8.
  • Texture Properties | Rotation is set to 270 to keep the to match the texture lighting to that of the atmosphere.


Blend with Distribution Pattern
Sand
  • Sand will settle along the flow lines, as it's been washed down with the weather.
  • Create this layer in the same way as the Dirt layer. The Diffuse and Local can also be set up in the same way except choosing temperate/dirt_07 as the textures.
  • This layer will require a unique Distribution image. The flow masks (UV corrected) created from World Machine were used to help create textures/megagen/terrain_mesh_sdk/masks/masks_sand.tga which is applied as the Distribution.
  • To make the blend more fitting and unique set the Distribution Pattern to textures/megagen/temperate/dirt_06_mask_inverse.tga. This will blend the Sand into the cracks of the Dirt before the peaks (stones).
  • Ramp Width is changed to 0.5 so the blend will become tighter.
  • Distribution Pattern Texture Rotation and Scale Should match that of the Dirt layer, as it's using a Distribution Pattern that matches the dirt.
  • Set the Detail Texture Type to 0 (dirt, as it's the best matching of the four), and the Surface Type Properties | Type to sand.


Gravel
  • To give the look off loose stones being scatter from the road.
  • Create in the same way as above. Was created after the Road Layer being placed.
  • The Distribution Pattern image for this layer will match it's own gravel diffuse, so the Rotation and Scale for the Diffuse and Distribution Pattern images should be the same.
  • Set the Detail Texture Type to 2 (textures/detail/temperate_gravel.tga), and the Surface Type Properties | Type to gravel.


Dry_Dirt
  • Gives a dried up cracked earth appearance, were standing water would have once been.
  • Slight transparency given so layer blends smoother over light sand and darker dirt, Alpha set to 0.75
  • Ramp Width set to 0.25 making the blend even tighter (sharper).


Sticks
  • Helps the grass blend in with the dirt.
  • Created after the grass, then layer moved above by dragging and releasing between the layers Grass_Outer and Dry_Dirt.
  • Ramp Width set to 0.75 so the blend can be softer.


Grass_Outer
  • Texture used is of a patchy grass, good for grass on the edges of a grass clump.
  • Distribution Pattern texture carefully made so the dirt parts of the diffuse blend in last.
  • Texture Rotation set to 300, this is to break up the look of textures tiling in the same direction.
  • The Detail Texture Type is set to 1 (textures/detail/temperate_grass.tga), and the Surface Type Properties | Type to grass.


Grass_Inner
  • Dense Grass, blended to cover the dirt of the patchy grass texture (Grass_Outer), where the mask become more solid (white).
  • Uses the same Distribution mask as Grass_Outer, as the Distribution Pattern texture is made so that it is never stronger than that of the patchy grass.
  • Texture Rotation and Scale needs to match that of Grass_Outer as the Distribution Pattern textures of both grass layers work together, with the same Distribution.


Stones
  • Create the Stone Distribution after the solid rock layers, as the rock will look better when it blends to the stones.
  • As well as being concentrated around the solid rock sections, stones should flow down the surrounding slopes.
  • Make the Stones more dense around rocks.
  • The Distribution Pattern texture has been created so the stones will blend in one by one.


Ground Base Layers
Pebbles
  • Pebbles in Mud works well around the waterline.
  • The Distribution mask is made slightly darker where the sand Distribution is. This will give good variation, as the Pebbles will blend in first (due to Distribution Pattern), making them appear to be on sand instead of mud.


Rock
  • A new Group is created under the Root node to keep the rock elements neatly together.


Rock Base
  • Rock should usually be created (distributed) near the start of making a megatexture, as rock usually effects where all other elements will be distributed.

Road Tool

Projector

Compile the Megatexture

Setup Renderlight

Stamps

Add Water

Water Mesh

Water Volume

Water Fog