fps.gif (3966 bytes)
Textures3

transparent.gif (893 bytes)FPSNews Up

Up
Texture1
Textures2
Textures3
Textures4
Textures5
Textures6
Starfeild Shader

Qworkshop3 Tutorials

Custom Textures 3, Grates.

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.

textures/my_folder/shader_name

This specifies the name of the shader, as well as under which folder you will find it in Q3radiant. Name your shader wisely and place it in the same folder as the texture it uses. This does not refer to a file, so don't put any extensions on it.
{ This signals the start of the actual script.
Cull none Normally the game engine would not attempt to draw the texture onto the back of a surface since it would be inside a brush. But since the rest of the brush will have the 'nodraw' texture on it, we turn 'culling' off. If we don't, the brush will only be visible from one side.
qer_editorimage textures/my_folder/texture_name.tga This defines what image Q3radiant will display for this shader. It does not have to be one used in the script (as you may have noticed with the sky shaders). It is apparently not always necessary add this line, but I always do to make sure I get the image I want. The image will appear in the folder specified above.
{ This signals the start of a processing stage. The statements above are properties of the shader. The ones below controls the actual rendering of the image.
map textures/my_folder/texture_name.tga This is the image to be used when the light map is rendered. Type in the name of your grate texture here. This should be a 32-bit TGA.

 

Making the grate

Now, I'm using Photoshop which handles alpha channels really well. I know that Paintshop pro is capable of generating alpha channels, but I don't know how. Here is how you do it with Photoshop.

Draw your grate like you would a normal texture. Use a single color for background, preferably black. Add a channel. You can do this by selecting the channels tab of the window where you usually have the layers, and clicking the little button at the bottom of it. Click on the RGB channel to select it. All the channels except for the alpha channel should go green if they weren't already

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

 

 

Hit Counter

 

Bill Brooks © 1999
email contact: Bill Brooks