Here are some basic definitions for shaders, using the example.

The first thing we need to do is define the basics:

  1. A Material is a file format (.mtr) that the game reads.

  2. A Shader is an entry in the material file. Shaders combine all of the source files (_d, _h, _s, _local plus extra passes) so the games lighting can be used properly.

  3. Spaces between shader commands and path names are used to begin and end strings and commands.

  4. Path names are used to point to a file. The directory paths on Q and the paths in the shaders are the same.

  5. // = Comment out. If you want the game to ignore a line in a shader, put this in front of the line and the game will ignore it. Using this is essential for troubleshooting. You can comment out blocks of entries by placing a /* before the area you want to have commented out and a */ after the area that you want commented out. The areas between these are commented out.

  6. Defaults: the game loads from q4base, so you won’t need to write q4base in the shader path names.

Example:

1)      models/monsters/iron_maiden/base
2)      {
3)              noselfshadow
4)              unsmoothedtangents

5)              renderbump  -size 512 512 -trace 0.07 -aa 2 models/monsters/heavyhovertank/hh_lo_b_local.tga work/models/monsters/heavy_hover_tank/hh_hi_14.lwo
                
6)              materialImage   models/monsters/iron_maiden/base_hit.tga

7)              diffusemap      models/monsters/iron_maiden/base_d.tga
8)              bumpmap         addnormals ( models/monsters/iron_maiden/base_local.tga, heightmap ( models/monsters/iron_maiden/base_h.tga, 2 ))
9)              specularmap     models/monsters/iron_maiden/base_s.tga

10)             {
11)                     blend add
12)                     map models/monsters/iron_maiden/base_g.tga
13)             }

14)     }

What we’ll do is define all of the shader line by line.

  1. The shader title (models/monsters/iron_maiden/base) This is probably one of the most used lines in the game. This is the name of the shader that the game looks for when it’s used by an entity or brush in the game.

    1. For Textures this is the name that appears in the editor. It also serves as a path name, so if you’re looking for a texture in medlabs and the name of the shader is textures/medlabs/wall1, the texture would be in the same directory. The last entry in the line is the texture name and the previous entries (textures/medlabs) are organizational directories in the editor

    2. For Models, the shader title needs to be added as a surface on the model itself. When the model is loaded into the game, it sees the shader name and loads the texture as projected by the UV map. You can have multiple shader titles on the same model. All you’d need to do is select the geometry in your 3d package and assign the shader name to it.

  2. The Open bracket ({ ) begins the first pass of the shader. ALL SHADERS NEED TO HAVE AN OPEN AND A CLOSE BRACKET. If not, the game will either crash or break a long list of other shaders following it. Think of the shader title as a chapter title and the open and close brackets are the beginning and the ending of a chapter.

  3. Shader Parameters are attributes that are applied to the whole shader.

  4. Another Global Shader Parameter option
  5. The Render (bump) line is used ONLY in models. This line is NOT used in game for viewing a set of targas. Activating a model for rendering a normal map uses this line, otherwise it’s dormant string.

  6. The MaterialImage is an option that allows for a texture or a model to have multiple hit impacts, by using a color coated Targa. If you use this option you must point it to a targa by writing a path name to the file. So if you were to shoot the Iron Maiden in the above example, the impact would change depending on where you hit it. (The MaterialImage targa has colors for flesh, solidmetal, hollowmetal, and gelatinous fluids) MaterialType is a command that assumes that the whole testure or skin has one attribure (all flesh, all rubber) it does not load a TGA, it uses a script so we save on texture memory!

  7. Diffusemap is a shortcut option that creates a rendering stage for the diffuse targa (base colors of the texture or skin) This line needs a path name to the file (.tga) being used. In this case (models/monsters/iron_maiden/base_d.tga) All diffuse targas should have an _d suffix.

  8. Bumpmap is a shortcut option that creates a rendering stage for the Height targa and Local targa. In this case you need an additional command addnormals to this string, this allows for the height targa and the local targa to be loaded in unison. This line needs a path name to the files (.tga) being used.

    1. The Bumpmap uses the _local targa. This file allows the texture or model to take light correctly. The _local files are generated in game by either renderbumping a texture or a high poly model to a low poly model.

    2. Heightmap is used to call out the targa used as a surface for the shader. This is usually a black and white image where white is a positive change (up) and black is a negative change (down). The number after the path name is the degree in which you want the range to occur.

    3. Because this is using addnormals you need to separate the files by using parentheses, you’ll need to open and close them like using a shader pass. Make sure you separate the heightmap line with a comma, then the number otherwise it won’t know to attach it to the previous path.
    4. If you need to write a bumpmap without the height remove the height line and the parentheses.
    5. The local map targa should always have an _local suffix, while the height map targa shouls have an _h suffix.
  9. The Specularmap is a shortcut option that creates a rendering stage for the specular targa. This file adds reflectivity to the texture or model. This is a pretty sensitive file so they tend to be pretty dark. This line needs a path name to the file (.tga) being used. In this case (models/monsters/iron_maiden/base_s.tga) All specular targas should have an _s suffix.

  10. Extra passes also need opened and closed brackets. Why add an extra pass? Well if you want a glow pass, modulation or anything other than the base of the model, then you’ll need an extra pass. Remember, every extra pass is a hit to the processing speed. Some shaders don’t use the above render options, these are specialty textures used for various reasons. (fx, guis, glass, water, fire etc)

  11. Blend Add is a blending option. In this case blend add is short hand for blend GL_ONE, GL_ONE. This is an additive pass, and is the option for glow passes. This needs a path name to a targa file.

  12. Path name to the glow support targa.

  13. The Close Bracket ( } ) is used to close a shader pass. This close bracket closes the first extra pass, the glowing pass.

  14. Another Close Bracket ( }) This closes the shader out, and the game is happy. This close bracket is attached to the top Open Bracket.

ArtReference Q4Shaders Definitions (last edited 2005-11-04 21:36:57 by MattVainio)