Materials are a method of making textures simulate real-life... materials. A texture on a flat surface can give you the look of, for example, leather, but it can't give you everything. What other properties does leather have? It's shiny, but not reflective, and slightly bumpy. All these effects and more are controlled by the material.
It's important to note at this point that we are not referring to Blender or Cycles materials. These are ignored by SuperTuxKart. Instead, use our own materials system to apply materials to textures.
Several other features, including special effects and physics properties also piggyback on SuperTuxKart's materials system. These reside in the "Interaction" section of the SuperTuxKart Image Properties panel, and are discussed in other articles. This article only discusses the "Display" section.
If you used textures from the media repository, you don't have to worry about materials. The materials are already configured in
materials.xml in the
textures folder of the
stk-assets repository and will not be configurable through the SuperTuxKart Image Properties panel.
Textures not from the media repository will have to be configured in the SuperTuxKart Image Properties panel. There are several options to configure.
If you're having trouble making your textures appear in the SuperTuxKart Image Properties panel, make sure they are in the the same folder as your Blender file.
- 1 Shader
- 1.1 Generic (solid) Shader
- 1.2 Cutout Transparency
- 1.3 Blending Transparency
- 1.4 Additive Transparency
- 1.5 Unlit (solid)
- 1.6 Vegetation
- 1.7 Reflection (Sphere Mapping)
- 1.8 Splatting
- 2 Alpha Mask
- 3 Colorization
- 4 Backface Culling
- 5 Texture Clamping
- 6 Texture mirroring in reversed races
Shaders are little programs that control how things are rendered in the scene. They can do all sorts of things, so picking the right one is important. The shader is selected using the drop-down "Shader" menu in the "Display" section of the SuperTuxKart Image Properties panel.
Generic (solid) Shader
This shader is used for most textures. It supports a number of options to enhance the look of textures and is recommended for most special effects. The solid shader also supports colorization (see Colorization below).
The gloss map is what lets you simulate a shiny surface. However, there are multiple factors to shininess. To take these all into account, the red, green, and blue channels of the gloss map image each correspond to a separate part. Making and testing a gloss map can be very time consuming, especially since you need to reload the game each time you try out a new gloss map. If you are good at Blender, however, you may find this useful.
- The red channel controls specularity. This is how concentrated the light is that reflects off the surface. At too high of a value, this has the effect of creating very bright dots on a very dark texture.
- The green channel controls diffusion. This is how much influence the texture has on the appearance of the material when rendered. When the green channel is 100%, the color of the texture itself will be invisible and the material will behave like a mirror; i.e. as if it had no intrinsic color.
- The blue channel controls emission. The more blue present, the more the material will emit light. However, this light is only localized and does not brighten the surrounding area. Usually it's used to make a fake glow effect on e.g. neon lights or lamps without the computational cost of a true point light.
If you have trouble with making your gloss map changes take effect in-game, try disabling texture compression in the game options.
Normal maps allow you to reduce poly while still getting the cool visual effects of a bumpy or wavy surface. Many textures from the media repository already have normal maps, so you don't need to create your own if you're using textures from the media repository. (In fact, you can't, although you may be able to help by making normal maps for textures that don't have them.)
To apply a normal map, simply enter the filename into the "Normal map" box.
Creating the Normal Map
This tutorial assumes that your textures are square. It actually doesn't matter if they aren't, but you'll have to do a little more work with editing the UV mapping and subdividing. Square textures work easily because a square plane will unwrap perfectly on top of them by default and a subdivide will create square quads which can correspond to pixels.
If the texture is, for example, 256 × 512, you will have to make the plane twice as long in a certain direction, with an edge in the middle so that when you perform subdivisions, you are subdividing squares.
Start in an empty Blender scene. Delete the default cube, light, and camera. Then, create a plane. In Edit Mode for the plane, with all four vertices selected, do a series subdivisions (shortcut: w > Subdivide) depending on the resolution . This might cause a bit of lag.
|Texture Resolution||Number of Subdivisions|
|256 × 256||8|
|512 × 512||9|
|1024 × 1024||10|
|2048 × 2048||11|
With all vertices selected, unwrap the the plane (shortcut: u > Unwrap). This will probably again cause some lag, but don't worry. In the UV/Image Editor window, you should see your plane. Open the texture you want to create a normal map for and enable "Textured solid" in the 3D View window properties panel (shortcut: n).
Now, switch the 3D View window to Sculpt Mode instead of Edit Mode. Several options will appear in the toolshelf at the left. Most important, however, is to turn off mirroring. To do this, deselect the "X" button below the "Mirror" section in the "Symmetry/Lock" section of the toolshelf.
Adjust the settings in the toolshelf for the sculpting brush as needed, and sculpt the plane in a way that you think would be realistic and fitting for the texture.
When you have finished sculpting, switch to Edit Mode, select all vertices, and, in the UV/Image Editor, click the "x" next to the texture filename to unlink the datablock.
Switch to object mode and create a new plane of exactly the same size and shape at exactly the same position as the one you sculpted.
Switch to Edit Mode, select all vertices of the flat plane, and unwrap it (shortcut: u > Unwrap). In the UV/Image Editor, click the "New" button to create a new image. Set the dimensions to the same as those of the original texture. Switch to Object Mode now; you should see that your flat plane is black if you have "Textured solid" enabled.
It is very important that at some point you have selected all the vertices of the flat plane in edit mode and have the blank texture open in the UV/Image editor. This assigns the texture as a face texture, which is needed for baking.
Remember how I said above to ignore Blender materials and the "Texture" section of the Properties window? Well, here's a rare exception, because we're using Blender's own tools to create the normal map. Make sure that you have "Blender Render" selected as the rendering engine in the Info window. In the "Materials" section of the Properties window, with the flat plane selected, click the "New" button. Leave the settings as they are right now.
In the "Texture" section of the Properties window, with "material textures" selected, and still with the flat plane selected, click the "New" button. Set the following properties:
- Set the name of the texture to the same name that you gave your new blank image in the UV/Image editor.
- Make sure "Type" is set to "Image or Movie".
- Under "Image," click the photograph icon and select the new blank texture you just created.
- Under "Mapping," set "Coordinates" to "UV."
- Click in the "Map" field underneath "Mapping" and select "UVMap."
Select the sculpted plane. Switch to the "Render" section of the Properties window. Under "Bake", check "Selected to active." Switch "Bake mode" from "Full Render" to "Normals." Make sure "Bake from multires" is unchecked and "Normal Space" is set to "Tangent."
Now, in object mode, first select the sculpted plane, then select the flat plane. Click the "Bake" button in the "Render" section of the Properties window. If you watch the blank image in the UV/Image editor, you'll see Blender draw a lot of purple and blue.
To save the normal map, go to Image > Save As Image in the UV/Image Editor window. The normal map can now be applied.
Sorry, this is a mistake. The solid shader doesn't support alpha masks.
The cutout transparency shader is best for things like vegetation (when you do not want it to move—otherwise, use the vegetation shader). It performs "alpha testing", to make pixels of a texture either 100% solid or 100% transparent. However, it doesn't have all the features of the solid shader, so avoid using it for solid textures. If your texture is mostly solid with a few transparent sections, you should use a separate texture. Cutout transparency supports alpha masks and colorization; see Alpha Mask and Colorization below.
The blending transparency ("alpha blend") shader is used for translucent textures, like windows. The colors of the objects seen through these textures will be blended with the colors of the translucent parts of the texture. Blending transparency supports alpha masks; see Alpha Mask below.
Blending transparency can only make objects darker, not lighter. Be aware that very darkly tinted transparent sections could greatly reduce the visibility of objects behind them.
The additive shader works the same way as the alpha blending shader, but instead of darkening colors when mixing, colors are lightened. This is useful for things like light beams or fire, to lighten objects behind the texture.
Textures using the unlit shader will always be at full brightness, in spite of lights or shadows. This shader does not support transparency.
The vegetation shader performs alpha testing, just like the cutout transparency. However, it additionally animates objects that have the texture applied, making them wave as if blowing in the wind. Using vertex painting, (see Texturing#Vertex Coloring for a tutorial) paint in black vertices to remain stationary, and leave white parts of the mesh that will wave. Paint vertices in shades of gray to make them move a shorter distance. The vegetation shader also provides two other options for control:
- Waving speed: How fast the vegetation will move back and forth
- Waving amplitude: The distance, in Blender units that the vegetation will wave
The vegetation shader supports colorization; see Colorization below.
Reflection (Sphere Mapping)
Warning! Deprecated! Don't use this shader, use the solid shader with a gloss map instead!
This shader simulates a chrome appearance by simply reflecting anything nearby. Because of this, it is really not the most realistic and doesn't provide all the details of the solid shader with a gloss map. However, if you're desperate and don't have a lot of time, you can use this shader to get an easy chrome effect.
Splatting allows you to "draw" up to four textures together using another texture and mix the textures together, creating a smooth transition between different textures. However, it can be quite costly in terms of video RAM. If possible, consider vertex coloring first.
Creating a Fallback UV Map
Since splatting requires so much video RAM, it's important to have a fallback for it for when players don't have such graphical capabilities enabled. Mark any seams and unwrap your mesh. You can assign a different texture to each face to be able to at least show multiple textures, although this will not create a smooth transition.
To make painting the splatting map easier, be sure that you have not marked seams where you want a smooth transition with splatting enabled.
Creating a Splatting Map
Red, green, blue, and black will each correspond to a different texture. In the Properties window, under Data, under UV Maps, click the plus (+) button to add a new UV map. (Note that this UV map must be the second map listed. The first one should be the fallback.) Create a new image in the UV/Image Editor window.
Don't try to change the UV coordinates for the second UV map—it won't export. Instead, the splatting map will be simply assigned to the first UV map. This is because Irrlicht only supports one UV map per mesh.
Be sure to use as close to pure red (RGB 255, 0, 0) for red, RGB 0, 255, 0 for green, RGB 0, 0, 0 for black, etc. as possible. If you don't use a pure color, other textures might be mixed in where you don't want them.
Decide what colors you want to correspond red, green, blue, and black. Switch to Paint mode in the UV/Image Editor window and select a color in the toolshelf (shortcut: t). You can also change various painting options for the brush in the toolshelf. Paint whatever pattern you want on the texture, blending colors wherever you want textures to be blended. If you have Textured solid enabled under Shading in the 3D View window properties panel (shortcut: n), you will be able to see your painting appear on the mesh in real-time.
Don't forget to save your splatting map as a file! In the UV/Image Editor window, go to Image > Save as Image and put it in the same folder as your your .blend file.
Configuring Splatting Textures
Now you can assign textures to each color you painted on the splatting map. In the SuperTuxKart Image Properties panel, select your splatting map, and set the Shader property to Splatting (if you haven't already). Set the names of texture files for the Red Texture, Green Texture, Blue Texture, and Black Texture properties.
Alpha masks allow for making a solid image transparent, either partially or fully. It is a grayscale image in which white represents full opacity and black represents full transparency. To make one, simply make a copy of your texture, use a tool like fuzzy select in GIMP or Krita to select a part that should be solid, and color it white, and select the parts that should be transparent and color them black. Use different shades of gray for different levels of translucency. Type its filename in the "Mask image" field for Alpha Test or Alpha Blending shaders in the SuperTuxKart Image Properties panel.
Note: customizable colorizing currently is only available for library nodes! If your objects aren't library nodes, you might want to consider vertex coloring.
Colorizing is a great way to reduce the need for multiple models of an object. Using a set of hues you provide, the shader can pick a random hue for each instance of a material, much like vertex coloring. However, colorizing can color each instance of a library node differently, while vertex coloring cannot.
When we say "hue", think "hue-saturation-value." Hue does not mean the same thing as color in this case. Hue corresponds to the frequency of visible electromagnetic waves, or light. But hue in this case does not include saturation (the difference in strength between the various colors of light) or value (the total amount of light).
Colorizing is also used to mark teams in soccer mode. Karts on the "red" team will be colorized red, while karts on the "blue" team will be colorized blue.
To enable colorization for a material, check the "Colorizable" box in the SuperTuxKart Image Properties panel. This opens up three options:
- Colorization factor: This is the amount that the shader will increase saturation on colorized instances. This is useful for textures with low saturation, so that a change in hue will be noticeable enough.
- Colorization mask: The colorization mask controls which parts of the texture will be colorized. Transparent sections will be colorized, while black sections will not be. (See images below.) As of STK 0.9.4, you can now simply use the alpha channel of your main texture for the colorization mask, since colorization only works with the generic solid shader anyway. Separate colorization masks are still supported, however, and may be easier to use.
- Hue settings for colorization: The numbers in this box control the hue palette the shader can pick from. Separate hues by spaces. A table of values is provided below for reference.
|Red||0.001 or 1.0|
Leave "Hue settings for colorization" empty on karts! Kart colorization is controlled by soccer team for soccer mode and setting this property will cause problems!
Backface culling makes planes only visible from one side—the side the normal is on. Disable it to allow them to be seen at any view angle.
Texture clamping prevents textures from being repeated over an object. You can control this for both the U (horizontal) and V (Vertical) axes of the texture. Check either or both of the boxes
- Clamp texture horizontally
- Clamp texture vertically
in the SuperTuxKart Image Properties panel for your texture.
Texture mirroring in reversed races
You can set a texture to be mirrored when playing in reverse mode. This is useful for textures like arrows to show the way. Select one of the two options from the drop-down menu for the "Mirror in reversed races" option of the SuperTuxKart Image properties panel.