Hints, tips and tutorials for 3D modelling & content creation
|
KatsBits
Creating 3D models, meshes &
game content
3D modelling & meshing, level editing and textures makingHints, tips and tutorials for 3D modelling & content creation [back]The principles of texture blending - terrainResourcesUseful Commands
Contents
What's this all about? ^The tutorial below covers the principles used when texture blending in Doom 3 powered games (currently Doom 3 itself and Quake 4), how models need to be set-up, how blending works and a rundown of the special material (shader) file the Doom 3 engine needs so it can work everything out. The tutorial won't however, go into the specific details on how you work with a 3D app to produce the model, or indeed D3Edit, so it's assumed you know at least the basics of modelling objects in 3D, how to prep them for Doom 3, as well as understanding how to get them into the game itself. The process described below is relative to the use ASE format models. Similarities to Quake 3 texture blending ^If you've done terrain or texture blending in any game powered by the Quake 3 engine then you will have used the same principles as Doom 3 texture blending employs. The Doom 3 process actually has more in common with Q3Map2's 'alphaMod' blending process than it does with the original Q3Map terrain shaders, but in either case, if you've ever used or looked at one or the other processes then you should find the Doom 3 method slightly easier in comparison. Working with ASE models ^The image below is what we'll be working with. It's a section of a larger terrain model that has to be split away from the main object to allow for slightly better control over what textures get blended and where. Because of the way the blending system works it results in a limitations regarding the number of textures you can physically apply to any given mesh. More on this later
![]() A section of terrain shown textured in a 3D application. 'Wireframe' overview is enabled to highlight the distribution of polygons over this mesh object. Mesh density and texture blending quality ^As with texture blending for the older Q3 technology the quality of the results depend a great deal on the density of the mesh where blending occurs; the more polygons the better the blend. However, it's not a good idea to simply add polygons to the model by doing a straightforward subdivision of the mesh 'as is'. Instead, polygons need to be placed with more thought and consideration; where a good level of detail is required for the texture blending the poly count can be increased; where blending doesn't occur or is not needed the polycount can be kept as it was originally or even reduced slightly to compensate for the increase in other areas.
Tiling textures and UVW maps ^As we're using a 'tileable' texture similar to that used on brushwork - it's not a texture that's been created specifically for the model - it's possible to be a little more 'generous' with the UVWmap layout (see below). ![]() Texture ratio between UVWmap shown over the top of the terrain texture A decision has to be made at this point regarding the relationship between the texture repeat - tiling, and texture resolution - how pixelated it looks in game; achieved by scaling the UVW map relative to the textures physical size. Exactly how much you do this depends on the physical size of the texture and how much pixelation you're happy to see in game when viewing it close to. The relative size of the UVW doesn't effect texture blending, it just effects the resolution of the textures used.
Vertex painting ^The actual control element of texture blending in Doom 3 powered games is done by the use of vertex paint. This is a method by which colour can be 'painted' onto the vertex points of a mesh. The mesh 'remembers' the vertex painted data when it's exported, which the game then makes use of to physically blend the textures based on the vertex paint data stored in the mesh and the material information defined by the text in the games *.mtl file (more on this later). The amount of texture blend in game is based on two things;
As mentioned above, attention needs to be given to the distribution of polygons based on the texture blend effect you're trying to achieve; if you need a 'detailed' blend in terms of the 'shape' the blend line follows (the level of detail the edge of a winding path has for example) then you'll need to increase the amount of polygons over that area to allow for better 'shape' control. By default vertex paint is generally 'white' (100%). For creating content for the Doom 3 engine, we basically only have access to two colours - 'black' or 'white'. The strength or amount of opacity is directly related to the 'strength' of the texture blend in game; so the darker or more opaque the black or white, the stronger the texture blend will be in game.
![]() Model section shown with 'vertex painting' visible - for texture blender black and white only If you've been mindful of the design of your mesh object you will have constructed it in such a way as to increase the polygon density where you want to blend and decrease it where you want either one or the other texture to appear (none blend). When you vertex paint the mesh you're taking advantage of this, the example mesh in this tutorial for instance, is slightly more dense where the black colour has been painted so in game blending creates nice strong edges and blended texture distribution in those areas. ![]() Vertex painting shown over the top of the terrain texture in a 3D application window Obviously what areas you paint depends on the textures you're using and the topology of the (in this case terrain) objects. The black areas above indicate a worn gravel 'path' and the gathering of the same gravel in low lying areas of the ground surface.
Exporting ASE models ^At this point - before the mesh is exported - you'll have a fully UVWmapped model with a placeholder texture applied via the 3D application (a temporary texture used just to allow the correct UVWmapping of the mesh objects). The mesh will also be triangulared and have 'smoothing' applied to it. Also, as mentioned in the section above, the mesh should also have vertex painting where necessary for texture blending and you need to make sure when the model is exported that the vertex colour information is kept in the file; although ASE and LWO files save the same data in different ways, the end result should be the identical.
Once you've 'prepped' the mesh it can then be exported to ASE (or LWO). After exporting, if you have a 3rd party model viewer, it's a good idea to give the model a quick once over to make sure it's exported correctly. Depending on what the viewer supports, vertex colours may or may not display when doing this. It's at this point that the mesh now needs to have a game specific material (shader) applied to it so it appears in game properly textured with blended images. Basic materials ^The actual 'control' that tells the game engine what texture needs to go where is done via the material file ( the *.mtr) located in [x]base/materials/. Generally speaking, materials work in a similar way to Quake 3's 'shaders' and for the most part follow some of the same principles; i.e. the use of 'stages' or 'layers' allowing a material to have several sections relative to the desired in game effect. A standard material for Quake 4 (Doom 3 etc.) looks like the following and only deals with a single texture set; in most cases that holds information for just the diffuse and normal map images.
file/path/image (1)
For texture blending we need a special material that can handle two sets of textures, each set being applied to one or the other of the vertex colours that were assigned to the mesh in the 3D application. Texture blend materials ^Now depending on what sort of visual effect you're trying to achieve texturally, you can do a couple of things with the texture sets;
A typical material file for blending textures uses method '1' (using two distinct texture 'sets') above and looks similar to the following;
file/path/image As you can see from the above the material contains 3 'blocks'; '(A)', '(B)' and '(C)'.
Generally speaking, in terms of their structure, the different stages of a blended material aren't that different to single texture set material except in two significant areas;
These two parameters are the 'instructions' that informs the game this particular material uses blended textures and that it should distribute each material layer accordingly; each one is assigned to one or the other of the two vertex colours painted onto the mesh, 'black' or 'white', and the difference in opacity between them determines the strength of the texture blend. Applying materials to ASE models ^As we're using ASE models for this texture blending example it usually means doing a little bit of extra tweaking to the file because of the way ASE files are saved from 3D programs; usually the physical path to the images used during production are saved out with the model. Open the ASE file into NotePad or similar text editor.
Once the file has opened into your text editor you need to search for a line in the ASE called '*BITMAP'; there may be more than one instance of this word depending on how many sections your model is composed of, but generally speaking it will look similar to the following;
The file path is the bit were interested in as that needs to be replaced with the material file reference which holds the texture blending information. In the sample material file above that's simply;
Or in other words it'll most likely be something similar to; models/terrain/cliffs/rock1 Once you've got your material reference it then needs applying to the ASE file so it replaces the initial path saved with the file (shown above). Generally speaking Doom 3 powered games use material paths in the same way except in one instance; the location of the 'main' game content folder; with Doom 3 that's 'base', but with Quake 4 it's 'q4base' (the other upcoming Doom 3 powered games like Prey and Quake Wars may use yet different folder names; 'qwbase' for Quake Wars for example). Go back to the ASE file and find the *BITMAP path again; it needs changing to the following for Quake 4; *BITMAP "//q4base/models/terrain/cliffs/rock1" And to the following for Doom 3; *BITMAP "//base/models/terrain/cliffs/rock1" Note the difference between each 'base' description, as explained above, this is important.
Once this has been done the ASE model is ready for the next stage of development; getting the model in to the game. Getting the ASE model into game ^Now by this point you'll be ready to import the model into the editor where you can do the initial real-time render to check everything appears OK. Make sure the model and it's assets are saved to a location associated with the material and files path therein referenced - not doing this is a common cause of models either not appearing or not being textured correctly in game. If everything has been done correctly when you press F3 (rebuild 'F7') you should see something similar to the image below; a correctly textured and rendered version of the mesh. As you can see below, the two textures referenced in the material are blended exactly where they need to be based on the placement and distribution of the vertex painting applied to the raw mesh back in the 3D app used. ![]() Texture blending section rendered in game ![]() Close-up of the blend between the 'grass' and 'gravel' textures used in the test map ![]() Mid ground view of texture blending Error checkingWhat sort of problems will be encountered? Thankfully not that many and the one that do happen tend to be related to 'user' error rather than a game error. The following list are some of the most common errors that happen when working with custom models in Doom 3 and Quake 4; Material and texture rendering problems ^Generally speaking when any one of the errors below happens it normally means the material file info isn't being referenced correctly, usually a simple typo or spelling error or putting the wrong file path in place. Click here for more details about editing ASE files for use in game.
Polygon and texture placement problems ^Generally speaking the errors mentioned below are usually due to there being some physical problem with the mesh or UVWmaps. Correcting them requires reediting the mesh to fix wayward UVWmaps or gaps between polygons.
Anything else I should know? ^You can't blend textures over brushwork. Texture blending can't be done over brushwork because the system makes use of vertex colouring, something that can't be done in QeRadiant. Consequently modelled objects are the only way to use the vertex blending, so providing you can output to ASE or LWO files, both of which the Doom 3 engine can read 'natively', you should be able to create objects in game that have some degree of texture blending. |