Shaders, textures, and packaging

Release and discuss things you've made, including mods.
Post Reply
User avatar
kharnov
Granger
Posts: 1851
Joined: Tue Mar 06, 2012 10:54 pm UTC
Clan: GT
Location: New York City

Shaders, textures, and packaging

Post by kharnov »

You might have wondered what a shader is, or how textures work. Today, let's go over both of them and observe how they are used. We will also take a look at how to make some simple texture modifications and get them into the game. You can then use these methods to package your modifications and distribute them.

First, some definitions. A shader is a script that provides a surface with its properties. This surface can be a model, or a part of a map. Some of the properties that can be provided to a surface include textures, as well as color changes and transparency, to name a few. Textures exist in several forms, all of which are various types of texture maps. Our engine utilizes diffuse, normal, specular, glow, and gloss maps. One model that uses all of these in conjunction is the human, as you can tell from the shader:

Code: Select all

models/players/human_base/armor
{
	qer_editorimage models/players/human_base/armour

cull none
diffuseMap models/players/human_base/armour_d.webp
normalMap models/players/human_base/armour_n.webp
specularMap models/players/human_base/armour_s.webp
}

models/players/human_base/helmet
{
	qer_editorimage models/players/human_base/helmet

diffuseMap models/players/human_base/helmet_d.webp
normalMap models/players/human_base/helmet_n.webp
specularMap models/players/human_base/helmet_s.webp
glowMap models/players/human_base/helmet_glow.webp
}

models/players/human_base/body
{
	qer_editorimage models/players/human_base/base

diffuseMap models/players/human_base/base_d.webp
normalMap models/players/human_base/base_n.webp
specularMap models/players/human_base/base_s.webp
}

models/players/human_base/head
{
	qer_editorimage models/players/human_base/head

diffuseMap models/players/human_base/head
normalMap models/players/human_base/head_n
specularMap models/players/human_base/head_s
}

This is the human.shader file. It's okay if it looks confusing at first, but take note of the general structure of the file. The shader is split into four segments, which are the armor, helmet, body, and head of the human. For each portion of the model, several shader keywords are used. You can look up a whole list of shader keywords on the Quake III Arena Shader Manual, which is mirrored here. Each segment of the shader file is closed off with curly brackets. This is very important and must be kept track of, as you'll run into errors if sections are not closed off properly.

Let's take a look at the textures that are applied to the helmet. First, the diffuseMap keyword provides it with a diffuse map, which is the base texture that provides color information. In older games like Tremulous, as well as in our vanilla renderer, you'll only be seeing diffuse maps on models. The helmet's diffuse map looks like this:

Image

The next shader keyword is normalMap for, of course, the normal map. A normal map provides a model with the appearance of extra detail without actually utilizing additional polygons on the mesh. The result is that a model with a tris count in the hundreds of thousands can be reduced to a low-poly model, and then given a normal map to appear like the high-poly version. Performance is greatly increased this way. For the helmet, the normal map looks like this:

Image

After that, we have the specularMap keyword. This is for a specular map, which determines the reflectivity of a surface. Brighter areas on a specular map make a surface shiny, while darker areas are more dull. The type of material you're trying to represent should be accounted for on a specular map. Here's the helmet's specular map:

Image

We then have the glowMap keyword, which specifies the glow map. This type of texture map determines the color and location of a glow, so that you can see lit portions of the model in dark places, in this case the human helmet's visor. A glow map does not exactly need additional detail, because any kind of glow blur will be handled by our renderer's bloom. The glow map looks quite basic:

Image

Lastly, while it is not specified here, there is another texture map type that we added support for recently, called a gloss map. It is not specified by the shader script, but rather through adding it to the alpha channel of the specular map image. A gloss map determines the roughness of a particular region's appearance. It works in conjunction with a specular map. This is what the helmet's gloss map looks like:

Image

Now that we know what everything is, how can we go about modifying things? The process itself is simple, but requires knowledge of where things are located in the asset folder hierarchy. At the present time, things are a bit messy because assets are spread out over a variety of pk3 files. A pk3 is nothing more than a zip under a different name, and in fact, you can simply alter the extension from .zip to .pk3 and vice versa. For now, you'll need to discover where things are located. However, this will become much simpler after we've merged all of our pk3 files together, so bear with us until then. For now, let's look at the human again. You can find the shader in /scripts/human.shader.

The official pk3 files are organized in alphanumeric order, from pak0 to pakH as of this time of writing. In addition to pk3 files themselves, you can use folders called pk3dirs to test out your modifications. These are simply unzipped versions of pk3 files, and they are loaded with priority. If I wanted to use a modified version of human.shader, I would put it into something that would be loaded with priority over the existing assets. So, let's make a pk3dir. In your asset directory, make a folder called human.pk3dir, although you can call it anything you wish as long as it ends in that suffix. Within that folder, add a folder called scripts, and inside of that one, add the human.shader file.

For an example, I will make the following modification to the helmet:

Code: Select all

models/players/human_base/helmet
{
	qer_editorimage models/players/human_base/helmet

diffuseMap models/players/human_base/helmet_d.webp
normalMap models/players/human_base/helmet_n.webp
specularMap models/players/human_base/helmet_s.webp
// glowMap models/players/human_base/helmet_glow.webp
}

Notice that I am using slashes. This comments out a section and prevents it from taking effect. No more helmet glow! It looks flat and lifeless and boring.

Image

Now, what if I want to make a direct asset change? Let's say that I want to make the entire human head glow for some silly reason. If you take a look at the shader file, you'll notice that each keyword shown above is pointing to a particular location. So, if you look in /models/players/human_base/, you'll see helmet_glow.webp. Recreate this folder hierarchy in your human.pk3dir folder. Then, place your new file there with the same name as the original, in this case helmet_glow.webp. Here is what I am using:

Image

A terrible green glow. He must have some sort of radiation poisoning. This is what he looks like:

Image

Now, I don't know why you'd want to share that with others unless you are severely artistically challenged, but let's say you completely lacked any sense of dignity. It's as simple as making a pk3 out of your pk3dir. Zip it, change the .zip to .pk3, and give it a name that gives it priority. For this case, you could simply use zz-human.pk3 and distribute it to your friends, who can slip it into their asset directories and observe your horrific art skills.

Hopefully all of this made sense and maybe I got some information across. If you have any questions or comments feel free to leave them in this thread.

User avatar
ViruS
Granger
Posts: 1020
Joined: Sun Mar 11, 2012 4:24 am UTC
Location: Antartica - West Australian Post shore
Contact:

Re: Shaders, textures, and packaging

Post by ViruS »

Thinking of which, what if we had a fullbright option? I know this effects gameplay by quite a lot, but what if?

observe your horrific art skills.

->

observe your awsome fullbright-ing skills

ImageImageYou[TubeImage

User avatar
Viech
Project Head
Posts: 2139
Joined: Fri Aug 03, 2012 11:50 pm UTC
Location: Berlin

Re: Shaders, textures, and packaging

Post by Viech »

ViruS, please stay on topic. Feel free to post your feature requests in a thread of their own.

Responsible for: Arch Linux package & torrent distribution, Parpax (map), Chameleon (map texture editor), Sloth (material file generator), gameplay design & programming, artistic direction

Post Reply