
This tutorial will
teach you about grate textures and their companion
shaders. Rather than just providing instructions, I
will also try to give you enough info to understand
how it works. If you are not interested in the
theoretical stuff, you can jump directly to the last
section.
What is an Alpha
channel
An RGB image (such as
a JPG, BMP or TGA) is usually stored with three
channels, one for each color. JPGs store 24 bits for
every pixel in the image, 8 bits for each color.
With 8 bits you can describe 256 different values,
or rather, one value between 0 and 255. (The number
of bits stored for each pixel is referred to as
'color depth'.) So, to describe a color with 24-bit
color depth we need three values between 0 and 255,
also known as an RGB triplet. If you dabble in web
design (don't we all?) you know this already. TGAs
can be stored with 24 or 32-bit color depth.
The 32-bit TGAs has
an extra channel, called an 'alpha channel'. The
alpha channel can be thought of as a grayscale
image, hidden in the RGB image. The alpha channel is
commonly used to set transparency in DTP or video
production. In Q3, a shader can use it for various
effects, like making grates or blending two textures
together.
About shaders
If you want to learn
about shaders, I suggest reading the official Q3A
Shader Manual. Here I will only explain as much as I
consider necessary to make a grate shader. If you
have messed around with shaders before, you can skip
the rest of this section.
A shader file is a
regular text file with the file extension '*.
shader'. They are placed in the scripts folder in
baseq3, or the corresponding folder of a pk3 file.
The shader file contains keywords that are
interpreted by the game engine. Id's official shader
doc says, "Shaders are short text scripts that
define the properties of a surface as it appears and
functions in a game world…". One file can
contain scripts for many shaders.
When you add a shader
to the scripts folder, you must also add its name to
the file shaderlist.txt. This file tells the editor
what shaders to load, and if yours is not in there,
you won't be able to use it in Q3radiant. There is
no need to distribute the shaderlist.txt with your
map.
The Shader
This is a basic grate
shader, as described by the shader doc.
__________________________________
textures/my_folder/shader_name
{
Cull none
qer_editorimage textures/my_folder/texture_name.tga
{
map textures/my_folder/texture_name.tga
blendFunc blend
alphaFunc GT0
depthWrite
rgbGen identity
}
{
map $lightmap
rgbGen identity
blendFunc GL_DST_COLOR GL_ZERO
depthFunc equal
}
}
__________________________________
The commands you may
need to edit are the first four.
Do a select all on
your image and copy it. Then select the alpha
channel again and paste your image into it. See to
that only the alpha channel is selected and visible.
The alpha channel should contain a grayscaled
version of your grate. Adjust brightness and
contrast until you have mainly completely black and
completely white areas.

Its quite possible to
use gradients, they will result in a semi
transparent surface. We have 8 bits at our disposal,
remember. Metal however, is rarely transparent.
The black parts of
the alpha image will be transparent. Invert the
image if you got it wrong. Save the image as a
32-bit TGA, and put in a folder under
baseq3/textures.
All that remains now
is to copy the script above into a text file.
Replace 'my_folder/texture_name.tga' with the name
and folder of your image. Give the script and
logical name and save it as mymap.shader. Add the
file name to shaderlist.txt so that Q3radiant can
find it. If you need more info on how to apply your
new texture go check out the grates tutorial.
The grate from the
examples can be had here
(19k), complete with alpha channel and script.
You have to put the files in the right directories
yourself though.
Good luck (_8(l)
Papa Bongo