Judith on 21/2/2008 at 01:03
IntroductionThis is tutorial for experienced T3ed users. I assume that you know the editor basics, already created some new materials and know how to use some image/photo editing software. All the dds. textures should be compressed in DXT3 format, unless stated expressly otherwise.
This technique uses cube mapping to simulate the reflective properties of a surface instead of mirroring environment nearby. Cubemap is a “light definition”, while the specular texture is a “surface definition”.
If you want to know more about cube maps please visit this page: (
http://en.wikipedia.org/wiki/Reflection_mapping) or (
http://udn.epicgames.com/Two/MaterialsEnvironmentMaps.html)
I've written a tutorial how to use classic cubemaps in T3ed as well, you can find it here: (
http://www.ttlg.com/forums/showthread.php?t=119705)
PreparationBefore we start, here's a list of things you'll need go through this tutorial:
1. T3editor install.
2. 3dsmax 5.1 install set up to work with the editor.
3. Image editing software with .dds files support (Photoshop, Gimp).
4. Crazybump (optional)
5. Patience
6. A spare evening.
Gimp is a free software so all examples will be based upon this application. You can download it here: (
http://www.gimp.org/) To open .dds files you'll need the plugin located here: (
http://nifelheim.dyndns.org/~cocidius/dds/). Crazybump is a very useful tool for creating nice normal maps and specular maps, you can grab it here: (
http://www.crazybump.com/). All the installation instructions are included in documentation attached to those files.
Preparing a cube mapFirst choose the surface do you need, pick one of your textures, whether it's metal, stone or wood, etc. Now you can make a simple cube map, defining the way the light is reflected along your surface. Create a new image with Gimp, make it 512 x 512, the color is unimportant. Choose the Gradient tool. Make sure that black is your background color, while the foreground color is gray (RGB= 128,128,128). Why not white? Because it makes the texture brighter than it was and such surface will generate the shiny effect even in the dark - and we want to avoid it.
Now you have to choose the shape of your gradient. If you have a very shiny surface, like metal then choose Radial. If it's stone or wood, the rectangular should be better. Actually there's still a lot to research into, so feel free to experiment with different gradients.
Start painting your gradient right from the middle of your image (x:255, y:255), press and hold your mouse button until you get to one of the edges of the texture (e.g. x:255, y:511). You should have a grey circle or a rectangle filling most of the surface, while the borders should remain black.
Go to filters, choose Map -> Make seamless. It will make the cube map look a bit more flat, and there will be no visible edges of a cube while looking at the surface.
A radial gradient should look this way:
(
http://www.putfile.com/pic/7711931)
Inline Image:
http://img2.putfile.com/thumb/2/5017532339.jpgAnd this is the rectangular gradient:
(
http://www.putfile.com/pic/7711932)
Inline Image:
http://img2.putfile.com/thumb/2/5017532317.jpgOk, this is basically what we need from a cube map. Duplicate this image layer five times and name them +x, -x, +y, -y, +z, -z. Gimp .dds plugin will now recognize this image as a cube map. Before you save it to file, scale the whole image down to 64 x 64 pixels. This is just a gradient, not a detailed image, so such size will be enough, trust me. What is important here -
do not compress this .dds file. DXT 3 or even DXT5 format results in ugly artifacts on grayscale gradients, besides, such cube map won't be bigger than 100 kb. Name the file cubemap_wet_stone.dds or something like that, so you'll easily recognize it later.
Editing the textureWe have our cube map, good. Now we need to define which parts of the image will be reflective or not. In order to do it we have to edit the alpha channel of our texture.
With your image opened in Gimp go to Layer -> Mask -> Add layer mask. In the dialogue window choose White (full opacity). Fine, now you're editing the alpha channel of your texture. Black means completely transparent areas, white - opaque. This way you're telling the Flesh engine how to reflect light on a surface, to what extent. Opaque areas are very reflective, while black won't reflect anything at all.
You can do it manually with any painting tools you like (brushes, pencils, airbrushes, etc.), but it will be much faster if you use Crazybump. Open your texture in this program. When all calculations are done close the preview window and click Specularity tab. Those settings are quite not balanced here so set Texture influence to 50 and decrease Enhance detail value to 50. What you'll get is basically a grayscale image of your texture with some strong contrast. Those settings should be fine for most of your surfaces, but feel free to experiment if you wish.
Note: instead of Crazybump you can use your image/photo editing software simply to create a grayscale version of your image, and copy it to clipboard.If you like your results, click the Save button and copy your specular to clipboard. Return to Gimp and go to “Layers, Channels, Paths” panel, switch to Layers tab. Select your main surface and press Ctrl+V to paste the specular into your layer mask. Your image should be transparent in some areas right now. RMB-click your main surface and choose Anchor layer (or press Ctrl+H). Repeat this step but now choose Apply layer mask. Save your image using DXT 3 compression. If you don't have a normal map for your material, make it now (with Crazybump or by other means).
Making a material definition in 3dsmaxRun 3dsmax. Open the material library and your .mat file, make a new material. Place your diffuse and normal map texture as usual. In Reflection field set the Reflection amount in the middle (5) and choose your cube map file. Finally set the material category, put it to library, save it and export to .mlb file. Put all your textures, cubemap and matlib file in proper directories, start T3ed and test it in your level.
What is most important for us here:a)
No additional performance consumption: this is not an additional specular layer, like in other engines, this is alpha channel of a diffuse texture which was already there from the beginning, but it was all white. We're just altering it :)
b)
No tons of additional space needed! While other engines need the specular to be saved in other file, here we just paste it in alpha channel. Diffuse texture size remains the same. You need only a few kilobytes more for very small (64x64) "cubemap specular" definition, which is multi-purpose, because you don't create it per texture, but per surface type: wet stones, wood, shiny metal, etc.
c)
No need to have extra backup textures: if you don't like the result and you just saved your image, don't worry. Open your texture in Gimp again, add layer mask but instead of
White choose
Transfer layers alpha channel. Select a paint bucket and choose white color as your foreground. Press Shift+LMB on your image to make it opaque again. Apply layer mask and save it.
Sorry, no demo this time (I guess I've been too busy) But I have some videos to show you how it works:
(
http://media.putfile.com/code.php?n=TDS---dirty-metal-surface-bloom-on)
(
http://media.putfile.com/TDS---wet-stone)
Abru on 21/2/2008 at 21:03
Nice tutorial. Thanks Judith!:thumb:
Flux on 22/2/2008 at 14:33
Thanks for the tutorial Judith.
I couldn't implement spec maps the usual way, this seems more efficient. Can you tell me, probably you've tried as well, why spec maps in spec maps slot don't work? I made a spec map from crazy bump, then added to spec map slot and it has S extension but in game the walls become like "jelly", some strange artifacts appear. I saved the spec map as dxt1.
Judith on 22/2/2008 at 16:14
Generally try not to save your textures as DXT1, use DXT3. You'll avoid problems with multiple surfaces and transparency.
To use specular field you need "specular definition", you can find it in PCTextures folder, GenSpec01 to 05, AFAIR. "Specular mask" is your proper specular texture. Still the whole thing seems to be buggy. I tried making my own specular definitions, and I succeeded, yet the effects were weird. Lights dissappeared when out of player view, and the way the lights were reflected was totally wrong. There's something wrong with specular definition from the beginning, which is basically two gradients, one in RGB and the other applied as a mask. One of those layers was responsible for light change when player was closing/moving away from the surface, the other was doing something with sides. Anyway it was so unpredictable, that I gave up after a few days (and nights) of testing.
str8g8 on 14/3/2008 at 11:30
Finally got around to trying this out properly (even less free time than usual recently).
It works pretty good. Especially for metal (and rusty metal where you can mask out the rust etc) results were good.
As you say, it's fake specular, in the sense that true specular reacts to lights and so on and so forth. For instance, say you make an object with specular and then use it in a very dark room where there are no lights etc. Or if you use it in a location with red lights, then you would expect the highlights to be red too. All this was way beyond engines at the time. If your game were set in during the day in outdoor locations, you could fake it no problem, but in thief environments it's noticeable. For this reason I think the devs left it out. For instance, trying to make a surface look wet wasn't really possible because of this.
Judith on 14/3/2008 at 12:19
Exactly. In most cases the surface with bright cubemap will look like a shiny metal, instead of wet surface, which can be seen in typical specularity example.
Actually everything looking wet is a curse of UEngine 3.0, precisely materials with multiple normal maps, or parallax maps (bump offset), where everything looks as if it was encased in ice or jelly ;)
str8g8 on 15/3/2008 at 15:38
I think sometimes the devs like to show off their shiny new shaders a bit too much. Incidentally, does Doom3 (released around the same time as DS) have "proper" specular or a similar fake specular? I don't have the game and it's hard to tell from screenshots ...
Judith on 15/3/2008 at 16:42
Yup, D3 has nice speculars created as usual, from grayscale images. What is interesting in UE 3.0: you actually don't need more than diffuse and normal map to create fully customizable materials. You can use separate colour channnels from your textures (R, G, B & A) and math operations on colours to get a specularity, displacement map, tweak brightness, contrast, adjust colours, etc. - all in material browser with realtime preview.
(
http://img99.imageshack.us/my.php?image=clipboard01yx2.jpg)
Inline Image:
http://img99.imageshack.us/img99/2486/clipboard01yx2.th.jpg
New Horizon on 15/3/2008 at 20:29
D3 also has some really neat things you can do with material shaders too. I love the way modern engines incorporate that stuff. I don't think there is any support for realtime updates in the D3 editor...but it's a feature I have wanted to add to the Dark Radiant feature request list.
Judith on 15/3/2008 at 21:05
Like multiple and animated normalmaps, perhaps? That's quite impressive thing I found out lately in UE 3.0 It would be cool to see it in DarkMod as well.