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.
4.1 Where do I put my material shaders? Since you will have the game loaded onto your personal computer and may not have a network, it’ll be a tad different from what we do here at Raven. You’ll need to create your materials locally. Meaning you’ll have to create them on your computer and then save them out in the appropriate directory inside the Quake4 game.
Through your computer’s Explorer, go into the Quake4 directories. (C:\Program Files\id Software\Quake 4)
Open the q4base folder and find the pk4 files.
Underneath the pk4 files, you’ll need to create a materials folder. Name it materials in all lower case letters.
Open notepad on your computer and write out your model’s or texture’s material to render your normal map from. It’s very important that the material paths need to point to the directories you saved your model in and where your normal and skin maps will be located.
After writing your material, name it and save it as an .mtr file in your newly created materials folder. Don’t save as a .txt file, but as an .mtr file. You can easily rewrite the suffix to .mtr.
4.2 Writing the shader for renderbump: This is the key to make your render work. So what do you do? Well the safest and easiest thing to do is to copy and paste a previous entry and change the path names. Here’s the breakdown using the above example:
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.
4.3 Double check your path: If the path is wrong pointing to the high poly model, it won’t render. The game will not allow spaces in the path name, so use an underscore ( _ ) in place of a space.
4.4 Check your spelling and don’t forget to save
4.5 Set up the shaders to see the model in game: At this point, you’ll need to take a look at your work. Set up temporary targas for the _d, _h, _s and put them on base with the _local in the correct directory. The renderline is not loaded into the game unless it’s called out, so leaving it there is ok. Load into ModView and see the magic. See the example below:
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 }