Writing shaders for models is almost the same as texture shaders… in fact it is the same with the exception to the path of the targa files as well as a render line.

Setting up material shaders

This is the clincher, and the thing that most people get wrong. It’s easy to mess this up, so in this stage it’s essential to be patient and not to panic.

Some definitions: Materials: the actual file format. Shaders: the individual entries in the material.

Here’s a typical shader for a model, and we’ll be using it for an example:

models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low
{
        noselfShadow
        unsmoothedtangents

renderbump  -size 256 256 -trace .05 -aa 2 -mergehigh models/mapobjects/strogg/barrels_and_containers/barrels/barrel1_low_local.tga work/models/mapobjects/strogg/barrels_and_containers/barrels/barrel1_high.lwo

diffusemap              models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low_d.tga
bumpmap addnormals ( models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low_local.tga, heightmap ( models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low_h.tga, 1 ) )
specularmap             models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low_s.tga
}

The only thing we’re concerned with right now is the shader name and the render line. The rest of it is used to get the .tga files linked and in game.

The top line: models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low is the Shader title: this is what the game looks for when you activate a render. Think of it as an alias or a chapter title.

Unsmoothedtangents: Unsmoothed tangents are for animated models. If the model isn’t animated DO NOT use unsmoothed tangents.

Renderbump: This is the command the game looks for when you ask for a renderbump. If the shader doesn’t have this command in it, it won’t render.

-size 256 256: Size is pretty self-explanatory, this is the size of the final rendered Targa.

-trace .05: Trace is the height in which the model renders. Think of the low poly model as the surface in which the high poly is being drawn onto. If the high poly has a lot of floating geometry, you may need to render the model multiple times at different trace heights.

-aa 2: This is the anti-alias function. If this is set to 1 it renders your UV map 1 to 1. If it’s set at 2 it’ll render at 2 to 1. Leave it at 2 for now.

-mergehigh: You need this to merge the high poly model so it will render as one model. If you don’t have this in, it will render a partial model.

models/mapobjects/barrel/barrel1_low_local.tga: This is telling the game to write a targa named barrel1_low_local.tga to models/mapobjects/strogg/barrels_and_containers/barrels directory (remember these are path names, so each slash is a folder) to your game’s installation directory on your C drive.

Work/models/mapobjects/strogg/barrels_and_containers/barrels/barrel1_high.lwo: This tells the game to use this high poly model to create the normal map. You can keep your high poly models in a local directory separate from the Quake4 game on your computer. A high poly model should NEVER be on q4base.

Remember to open and close the shader using { and } so that the game recognizes it.

models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low
{
        noselfShadow
        unsmoothedtangents

renderbump  -size 256 256 -trace .05 -aa 2 -mergehigh models/mapobjects/strogg/barrels_and_containers/barrels/barrel1_low_local.tga work/models/mapobjects/strogg/barrels_and_containers/barrels/barrel1_high.lwo

diffusemap              models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low_d.tga
bumpmap addnormals ( models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low_local.tga, heightmap ( models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low_h.tga, 1 ) )
specularmap             models/mapobjects/strogg/barrels_and_containers/barrels/medium1_low_s.tga
}

ArtReference Q4Shaders Models (last edited 2005-11-04 21:39:05 by MattVainio)