will be all about shaders. Making reflective
metal is mostly texture/image work though.
Layout of a shader
A shader can be
divided in to two major parts. Surface properties
and 'stages'. I use the word properties here though
I have not seen it used anywhere else. In my
definition, the surface properties include all 'surfaceparm'
and 'q3map_' keywords, as well as a few others like
'cull'. In short, all keywords that are not stage
specific. The compiler uses this part of the shader,
so if the shader is edited, the map must be
recompiled for the changes to take effect.
A 'stage' is
something that happens once per frame, and with the
stage specific keywords the designer can control how
the surface is rendered. A shader can have plenty of
stages, but every stage means an extra rendering
phase before the frame can be displayed, and thus
affect the frame rate. The stages are loaded with
the texture and used in real-time, so all that is
required to see the effect of changes is to do a 'vid_restart'
from the console. Most of the stage keywords affect
how and what is sent to the frame buffer, more on
that later in the next tut.
Metal Shader
I'm sure you have
seen the reflective metal textures in some q3a
levels. I'm also sure you have wondered what on
earth the little screenshots in textures/effects are
for. Well, these screenshots are what is being
reflected in the reflective surfaces. Unlike mirrors
that (actually mirror the world), most shiny
appearing surfaces in q3a are made with shaders
similar to the one below. A special texture, usually
tinfx.tga is stretched way out, and then alpha
blended with a second texture.
___________________________________
textures/papas_stuff/dark_metal
{
qer_editorimage textures/papas_stuff/dark.tga
{
map textures/ papas_stuff/lscape.tga
tcGen environment
rgbGen identity
}
{
map textures/papas_stuff/dark.tga
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
rgbGen identity
}
{
map $lightmap
blendFunc GL_DST_COLOR GL_ONE_MINUS_DST_ALPHA
rgbGen identity
}
}
___________________________________
This shader has three
stages. The first maps lscape.tga to the
environment. This makes it behave like a farbox in a
sky shader. It is stretched out and centered on the
player. This is where the images in the effects
folder usually go. Like tinfx.tga in the zinc_shiny
shader.
The second stage
loads the texture dark.tga and blends it with the
one already in the frame buffer. This blend function
uses the alpha channel of dark.tga, so with the
alpha channel we can control how reflective
different parts of the texture should be. This blend
func is written as an explicit blendfunc, but
actually it is the same as we used for the grates,
i.e. 'blend'.
The last stage loads
the light map and does an explicit blend with the
background. In this case I believe the blend func
applies the lightmap to the same degree that the
texture was applied in the previous stage. This
means that the parts of the surface that are
reflective will not be lightmapped. The func
retrives the alpha channel from the image in the
frame buffer and applies the lightmap with this as a
template.