Tutorials @ chrisholden.net

 UDK Documentation: Material Editor


 UDK Documentation: Material Editor

First of all, READ THE OFFICIAL DOCUMENTATION! As you'll see in the Material Editor, there's a LOT of things you can do with materials. What I'll be demonstrating is the tip of the iceberg. Remember to look at Epic's demo levels, such as DM-Deck, the GDC features level, example map and so on. They are there to show you examples of what you can do, so never limit yourself to what you know or what you see in a tutorial. There's always more to learn.

I can't stress this enough. Look at this page from the official documentation. It covers many incredible features you can implement into your materials

A standard game material may include a diffuse, specular, and normal. You can get fancy and include glow, paralax, and so on. For this tutorial, we'll stick to generally making things look good. This tutorial assumes you have knowledge of creating these material, and some basic UDK editor knowledge.

For this new parent material, the first consideration is reuseability. For example, stone, bricks, concrete and so on can use the same material setup with different textures, where as metal, windows, water, etc. might be different materials. We want to setup a PARENT material for our base stone (brick walls, sidewalks), and setup parameters for scalability. This way, we can plug the parent materials into a MaterialInstanceConstant for each reuse, and the game only has to build one shader for the original parent.

Quick Tip: Content Browser
View > Browser Window > Content Browser OR, click this button.




Let's jump into UDK. Right click in the Content Browser and click New Material. This brings up the Material Editor. I've given this is temporary naming for this example. If you haven't already imported a diffuse and normal map textures, go ahead and do so.



 Diffuse
1) Select your diffuse texture in the content browser and go back to the material editor. Normally, you can use a TextureSample (T + right Click) to drop in any texture, but for this example, we'll be using a Parameter called TextureSampleParameter2D. By setting this as a PARAMETER in the PARENT, when it's used as an instance, we'll be able plug any texture we want into that parameter as opposed to building a whole new material just for the differet texture.

2) Always name your parameters! This one I'll call 'diffuse' as that's simply what it is. This will come in handy later when setting up material instances.

Note: if you're simply presenting a single piece, and have no reason to reuse a material, do not worry about using Parameters.

3) Click drag the black box in the left side of the Diffuse texture to the one next to Diffuse. This creates a link between the intructions, telling the material what to do. As you build a material, you must link all instructions or they won't be active. Additionally, the colored boxes on the left side of the texture represent it's color channels, and the white one the alpha channel.

Alt + Click to break any connection.

4) At this point, you may have noticed the greyed out check has changed green. This changes green any time a change has happened within the material. Click this icon to save the material. It will then update within the level and any instanced materials. And always remember to save the package when doing any work. This is now a working material. Besides plugging a constant into the diffuse, this is about as simple as it gets.





 Normal
Now, let's plug in that normal map, and get this basic material working. You can repeat the exact step for the diffuse for the normal texture OR you can select the diffuse in the material editor and click ctrl + W to duplicate it. This will duplicated EVERYTHING you have selected in the material editor, and will save us many steps later in development. Change the Parameter name to 'Normal'.

If you click the green arrow it'll apply what is every selected in the Content Browser (for this case, the normal texture).


Plug this into the Normal slot, click the green check, and you should have a working diffuse and normal material.



 Specular
If you want to make custom specular textures that's great. You can plug them into specular same as explained in the diffuse or normal textures, and you don't have to read this next section. However, it presents a basic technique for saving an additional texture file from having to be created.

For this example, I'm going to use my diffuse texture to generate my specular using a technique similar to the one presented in the UT3 Bonus dvd videos. Again, it's probably cheap if you can dig it up, and their tutorials are still an excellant base.

You can plug your diffuse directly into the specular slot, and get a result. You can also use just the red, green, blue or alpha information if you please.

In MATH, there's a lot of great options. Add and Multiply are a couple we will use later, but for now, it's POWER! The diffuse will plug into the base. If you 'M' click you'll get a Multiply, and 'A' click adds an add.

Now we need a CONSTANT (second from top of list). A Constant is a 0 to 1 value with plenty of decimal places for accuracy. A constant is the red channel of red, green, blue, alpha (see texture channels in Photoshop), but in this case can represent brightness, opacity, and so on. There are also Constants 2, 3 and 4 Vectors. These represent the channels beyond red (green, blue, alpha). When it comes to basic material setup, the Constant and Constant3Vector are most popular since Constant - brightness/opacity and Constant3 = Color. You can also hold on your keyboard, 1, 2, 3, 4 and click in the material editor to place one instantly.

Plug in the constants as shown, and you'll get a nicer looking specular material.

NOTE: any constant can be replaced with a Scalar or Vector Parameter for a controllable constant in the Material Instance, but I do not suggest it here, as each of these parameters will cost you down the road.

Ok, If you click the Eyeball, you get realtime updates in the material editor, but this can hog your system so use realtime expressions at your disgression.


You can also use a Utility > Desaturate if you don't want the specular color.


We've got the basics setup. Fantastic, let's move on.





 MaterialInstanceConstant
Let's look at all this MaterialInstanceConstant nonesense I've been blabbering about.

The value of instanced materials is; different objects does not require a unique material shader. The more custom shaders in a level, the longer shader building time increases. When working on a small scene this might not be a problem, but can add up to hours to a large level load time.

Right click in the Content Browser and under New Material is New MaterialInstanceConstant, and name it however you see fit. You'll see a lot of options here depending on how elaborate the parent is, but first off, select the parent material we just made, and plug it into the Parent tab

We've only setup TWO parameters in the parent right now, these are the Diffuse and Normal textures. If you click the check boxes next to them in the Texture Parameter Values, you can change the textures this material instance uses.

Create PARENT MATERIALS for SPECIFIC TASKS such as stone material, metal material, metal with opacity, and so on. Additionally, if you're an artist setting up an environment piece, it is much easier to setup parents and plug the textures into instants for quick results.





 Parameters
Back to our Parent Material, let's setup a variety of parameters for all sorts of options within our instance!

For this part, we'll be adding a lot of vector and scalar parameters as well as add and multiply. I like to start by putting a these in so I have them to copy them around when necessary.

Diffuse Power: Plugging a Scalar parameter into this works like gloss, but on the diffuse texture. (adjust the way lighting works, useful, but lots of tweaking required)
Diffuse Color: Multiply a Vector on the diffuse to control it's color.
Specular Power: Plugging a Scalar parameter into this increases the gloss of the specular texture. (tightens the highlight)
Specular Color: Performing the same setup for diffuse color can do this

Normal Multiply: Because of how normals work, this needs a Vector parameter. When adjusting this parameter, only modify the blue channel. With this multiplier, 0 is the strongest, 1.0 is unmodified, and anything above 1.0 decreases the normal map's strength.

The named boxes around them or COMMENTS are easily made by selecting a group of instructions, right click and COMMENT. Commenting is very useful for organization, and I urge you to use this for your parent materials, kismet, etc.

With what's setup here, you have a lot of power over your textures, but there's still so much more you can do.



 Color Mask
A common practice for materials that aren't using their alpha channels for opacity is to be the specular, color mask or emissive. At this point, you could use the alpha channel as a COLOR MASK for a wall or car material, then change it's vector parameters to get unique colors for on specific locations of materials.

This example shows the Color Mask in action. Taken from the alpha, it's multiplied with the color of your choice and added to the Diffuse.



 Detail Maps
Detail maps add that extra close level of detail to materials so they don't appear blurry up close. Various tiling bumps are perfect to stock up on for detail maps, but for this example we'll be duplicating the normal since it tiles.

In Coordinates, we need TextureCoordinate. This can scale up or down a texture across our material. The is applied to the UVs of the Detail tesxture. In this example the U and V tiling is set to 8. You can also experiment with diffuse and normal overlays setting the UVs to decimal coordinates for larger unique materials to break tiling.

Like with the Normal Multiply, the blue channel is imporant here, but in this case we have to remove it completely. Add a Constant3Vector (3 Click), set the red and green channels to 1, leaving blue at 0 for a yellow constant. Without the blue channel, it can be added to the normal without any problems. When setup as a parameter, the Detail Multiply's Red and Green channel begin increased strengthens the detail normal.



 Fresnel
Fresnel is one of my favorites. You may have heard it called Rim Lighting or saw it all over Mario Galaxy. Either way, it's a great touch to the right materials. You can set a parameter to control it.

Speaking of Parameters, the more of these you have the more they can eat resources. I'm presenting a lot of options, and most of which I don't need in my own development. So I suggest you experiment and learn from them, but remove the ones you don't use when actually applying them to a real project.



 Cube Maps
Cube Map (if you ever want something to look shiny, reflective, or metal look good, this is what you need) Right click in the Content Browsers, and make a New TextureCube. Scrolling down in this, you'll see all the Face Neg and Pos X, Y, Z textures that should be plugged in accordingly for making an accurate cube map. But for this example, I plugged one texture into them all for a speedy result. With that saves and in place (sometimes you need to restart the editor to get a cube map to fully updated). For more information on Cube Map creation, see the official doucmentation and your favorite search engine.

Back in material editor, place a TextureSampleParameterCube and plug in that cube map, and under Vectors (at the bottom of the list alphabetically) is a ReflectionVector. Once you've got these two setup, the cube map will work, but it needs to be toned down ( the 0.05 constant), and possibly given a parameter to control it.

This is all plugged into EMISSIVE.



 Conclusion
Here is the final material, and an example of a material instance constant with some wacky colors.







 
Tutorials @ chrisholden.net