This section is by no means complete, as the shader system has more options in it than I could cover in one document. In this section we’ll go over some basics with extra passes in the shader system.


What is an extra pass? Every time you open and close a shader entry in the same shader entry you’re writing a pass. Extra passes are any entries other than the diffuse, bump, height, specular, and imagemap entries.

Time: A unit of measure in game. When the game starts, the games begins counting, and stops when the level is disconnected, or is shut down. No one really knows what the unit is, but its assumed its 1 to 1, although I think it uses fuzzy logic.

Modulation: Changes the UV values of vertices on a surface. Usually the first number is the U or horizontal direction, and the second value is V or the vertical direction.

Tables: Tables are numeric strings that act as modulation over time. See the tables’ section for more info.

Scroll: Changes the UV values of vertices on a surface. Moves the textures across a surface. There are 2 entries, the first number is for the positive and negative horizontal while the second number represents the positive and negative vertical. (Example: scroll 1, 0.) The range can be controlled over time.

Scale: Scales occur to the lower left hand portion of the textures. 2 values, the lower the number the larger the image, so a ‘scale 3, 3 would be smaller than a scale .5, .5. Scale can be modulated over time.

Centerscale: Same rules apply as Scale, but it scales from the center. (Example: centerscale 1, 1.) Centerscale can be modulated over time.

Shear: skews the texture from its center. The 2 entries represent the amount of shear you want. A little goes a long way, I think 1 = a 45 degree increment. (Example: shear .5, .5) Shear can be modulated over time.

Rotate: spins the texture (0 to 1), 0 = 0 degree and 1 = 360 degrees. Can be modulated over time.

Color: Numerically modulate the existing texture. Can be modulated over time through an expression.

Colored: Pays attention to the parm 0 parm 1 and parm 2. Shortcut to use the parms. Breaks if you define color values.

RGB: Monochromatic. Applies modulation to the RGB value (meaning an entity) RGBA: Monochromatic with alpha. Same as above except includes alpha.

Blend modes: Blend modes have 2 entries: One is, what do I do with the thing I’m drawing right now (Source Blend Mode), and the second is what is happening to the values that are already there. (Destination Blend Mode). The first is the source blend and the second is the destination blend on the blend line. (example blend gl_one, gl_one)

Source Blend modes

GL_ONE: Add the color of whatever is in the buffer.

GL_ZERO: Don’t draw whatever is in the source.

GL_DST_COLOR: Draw the source only over areas that have positive RGB values.

GL_ONE_MINUS_DST_COLOR: Darken the colors based on the colors behind it. (If you invert the colors, it’s a way to make targas work without an alpha pass) re-write.

GL_SRC_ALPHA: Only draw areas based on the positive alpha

GL_ONE_MINUS_SRC_ALPHA: Only draw the inverse of the alpha source channel

GL_DST_ALPHA: Use the alpha from the surface you are drawing on.

GL_ONE_MINUS_DST_ALPHA: Use the inverse alpha from the surface you’re drawing the source on.

Destination Blend Modes

GL_ONE: Take whatever colors are already there, and add it into the scene.

GL_ZERO: Do not draw the images behind the color.

GL_SRC_ALPHA: Draw the background in, according the source alpha.

GL_ONE_MINUS_SRC_ALPHA: Draw the background in according to the inverse of the source alpha.

GL_DST_ALPHA: Draw the background based on the destination alpha.

GL_ONE_MINUS_DST_ALPHA: Draw the background based on the inverse of the background alpha

GL_SRC_COLOR: Draw the background based on the source color. (makes transparent, good for glass)

GL_ONE_MINUS_SRC_COLOR: Fill in whatever is not being used by the source color.


There are shortcuts. If you know you’re going to be writing a lot of these, or if you want to avoid the GL stuff, use these:

Blend add: GL_ONE, GL_ONE: typical glow pass. Draw the background and add the foreground onto it. Set up the file so that your colors are the glow pass and the black are dropped out.

Blend blend: GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA = Draw as much of your source as your alpha will allow and make up the rest with your background colors. Set up your .tga with an alpha.

Blend filter: GL_DST_COLOR, GL_ZERO : Drops out the White of the file, darkening to the degree of black in the image. Basic multiply parameter.

Blend None: Only when writing to the depth buffer… For MaskAlpha.

Shader Parameters: These options affect the whole shader entry, do not use these in individual shader passes. Its best to place these at the top of the shader after you open the initial pass. Nonsolid: Makes the texture or model surface non-solid. All shots and characters pass through it.

Noimpact: Makes the texture or model surface non-solid. All shots pass through the texture.

Noshadows: The texture or model will not cast a shadow.

Noselfshadows: The model will not cast a shadow on itself.

Playerclip: Texture blocks the player but nothing else.

Monsterclip: Texture blocks monsters but nothing else.

Unsmoothedtangents: This has to functions. The first thing it does is, average the normals during a _local.tga render. The second is, it must stay in the shader to mark it as using averaged normals. Used for animated or moving models.

Image Rendering

Clamp: Disables the tiling of a texture on a polygon. Used in stages

Zeroclamp: Same as Clamp, except a black border on of one pixel will be preserves on all mip levels. Used in stages.

AlphaZeroClamp: Same as Clamp, except a translucent white border on of one pixel will be preserves on all mip levels.

Smoothnormals: Effects the bumpmap line only. Can smooth the local and height, or local or height. Should be used sparingly, since it can drastically alter the normal. Example:

Bumpmap addnormals ((smoothnormals models/blah_local.tga), heightmap (models/blah_h.tga, 3)) This would smooth the local but not the height. 

Deforms: Deform Flare: Must be a quad. (2 tris) Creates new set of polygons around the original edges of the quad. Pushes them away from the corners, perpendicular to the camera, by the amount placed in the shader line. By default, the original polygon is assigned a white shader and the new border edges are mapped with a quadratic falloff. (Example: Deform flare 50)

Deform Sprite: Rotates the polygon to the camera. Must be a quad. (2 tris)

Deform Expand: Takes the polygons and scales them by the amount listed. They can be use a table and be modulated over time. (Example : Deform Expand 30) (On a table: deform expand sintable [time] )

Alpha: Alphatest: Hard edged alpha. Goes through each pixel and determines whether the alpha value is greater or equal to the number, and draws it. (Example AlphaTest .5) Bilinear filtering happens after the Alphatest. Example:

IgnoreAlphatest: Ignores Alpha test for that stage.

MaskAlpha: Current pass is not allowed to change the alpha values.

InverseAlpha: Inverts the previous alpha pass in this stage.

Some Common shader passes

Glow pass: (additive passes) The glow pass is the most common extra pass. Through this entry we can fake a lighting effect without adding a dynamic light in game.

                blend           add
                map             textures/stroyent/stroy_pillar2alight_add.tga

Hard edged Alpha In this pass, the diffuse map will need an alpha channel with just black and white.

                blend           diffuseMap 
                map             textures/terminal/t_floor_1a_d.tga
                alphaTest .5

Soft edged Alpha In this, you’ll need to make an alpha channel with shades of gray. White is opaque and black is transparent. All the ranges in between are viable.

                blend blend
                map textures/glass/dirty2_d.tga

Well…that’s all. There are a lot of different combinations of shaders you can use to get different effects. A lot of shaders have been written, so if there is something you’d want to try in a shader, nine times out of ten there are examples in the *.mtr files.

ArtReference Q4Shaders Extra Passes (last edited 2005-11-04 21:51:06 by MattVainio)