About : This third material tutorial focusses on teaching you a thing or two about the UE3 Material Editor by explaining a number of random examples. Learn by practical use rather than theoretical explanations.
Target Audience : Unreal Engine users - Intermediates
Platform : Unreal Engine 3
Last Update : January 2008 - Added Vertex Colors
Related links : Material Tutorial 1
Material Tutorial 2
Water Tutorial 1 - Outdoor
Water Tutorial 2 - Indoor
Material Expressions
Introduction
Instead of giving you complex, technical and theoretical explanations of every single property I'm convinced that you learn quicker by practice, therefore this tutorial simply provides you with examples of common materials and how they were made.
This third tutorial focusses on some of the more complex materials one can make, including embedding the Parallax Map into the Normal Map, Celshading, Instanced Materials, and materials that responds to distance.
The Examples
Material Instances
Material Instances are nifty things that can be used to make a quick and easy variation of an existing material setup without having to duplicate the entire setup. A Material Instance becomes a child of the original parent material. The biggest advantage of this approach is that when you have the need to modify or polish the original material, all children will also change along without any additional work.
Setting it up is pretty simple. Create a regular material and set it up like my example.

A TextureSample that is multiplied with a solid color to get a blue variation of the original texture. The special thing however is that I did not use a regular Constant3Vector expression, but a Vector Parameter expression. All the Parameter expressions are expressions that can be accessed and changed by Instanced Materials. Regular expressions cannot.
The Vector Parameter has a ParameterName set ("tutorialexamplename") and it has a default color assigned, in this case blue. Once that's set up you can close the material and create a MaterialInstanceConstant in the Generic Browser (rightclick an empty space in the browser -> New MaterialInstanceConstant).
Double click it to get to its properties and configure it as shown in my example.

Point the Instance to the Parent Material and add a new item to VectorParameterValues. In that new item you need to set the ParameterName, in this case that was "tutorialexamplename" and from then on you can modify the color as many times as you want.
As you can see there is also a ScalarParameter and a TextureParameter, they work likewise.
Blending textures by using the Vertex Colors
Just like UE2, UE3 too supports blending textures by making use of the Vertex Colors assigned to the Staticmesh. How to set up Vertex Colors in Max can be read in my Vertex Color tutorial. Also note, in the picture I use two Constant3Vectors instead of two textures, just for the sake of the example, and I linked the whole setup to Emissive, undesirable in practical use. Also, if the material also has normal and specular maps, duplicate the entire setup for those.


A material that responds to distance
By using the PixelDepth expression, one can make a material that fades out the closer the camera, or the other way around. This is ideal for certain effects as well as for things like detailtexturing and macrotexturing. The material in the example was Unlit and had a Translucent renderstate.

Faking distance fog through a material
Along the same line, it is possible to fake distance fog using a Destdepth expression. The color of the distance fog is determined by the Constant3Vector. The Constant that is multiplied with DestDepth controls the distance. This is a great trick to use on a watersurface, especially if it's water players can't get into.
The material in the example was Unlit and had a Translucent renderstate.

Deriving Specularity of a Diffuse Texture
It is possible to derive the Specularity from the texture used for Diffuse without a lot of additional work. Often, artists import a separate Specularity texture, thus increasing the file and memory size, while this isn't really necessary. Especially not if its concerning a tiling texture.
It is perfectly possible to turn the regular Diffuse texture into a well working Specularity texture with the right material setup.
This technique can be used to create both black and white specularity textures as colored ones. I personally use something in between, a semi desaturated texture. The example setup also shows this.

The Diffuse texture is multiplied by itself to raise contrast, it is desaturated and finally it is multiplied with a constant to raise contrast even further. If that still doesn't give a satisfactionary result it is also possible to alter contrast even further with a Power or Level expression.
Saving Memory By Embedding The Parallax Map - Technique by Aevirex
Usually the parallax map is either embedded as a alpha map into the normal map, or is imported as a separate texture. Both approaches will put additional strain on the memory by having it load in more content. At the expense of some GPU power it is possible to get rid of this extra step and embed a parallax map into the RGB channels of the Normal Map, thus having no need for a separate and third texture for the material, or for having to use the memory intensive alpha channel of a Normal Map.
By placing the grayscaled Parallax Map into the Blue channel of the normal map texture in Photoshop, you can use the Blue channel to BumpOffset the texture in the editor. That leaves you without a blue channel for your Normal Map though, you will have to reconstruct it in the editor to get your original Normal Map back again, or at least something that comes close to it. By modifying the Red and Green channels and blending them together it is possible to more or less recreate the original Blue channel. The combination of Red and Green recreates the info that was on Blue channel.

If you are desperate to save some memory and diskspace, and you should because no one will download a custom level of 300 MB, this technique in combination with the derivation of specularity from diffuse, as described in my second material tutorial, can dramatically cut the filesize of a custom art intensive level. Instead of requiring 4 full resolution textures, it would only need 2, halving filesize!
CelShading - Technique by Aevirex
Celshading is quite complex to set up. The material is basically created by two large groups of expressions. The idea is that it will use the environment's lighting information (position) and harden its edges according to that information. As such the material will only show up in a lit viewport.

Also note, for best results you should set LightingModel to MLM_NonDirectional in the End Node.







