This is an old revision of the document!


SHADERS: What are shaders ? Lava shader example

  • Author: Darth Arth
  • REQUIREMENTS:
  • Installed GTK - Radiant
  • any text editor, notepad , etc.

In this tutorial you can lern few basics about shaders and how you can create your own shaders.

What are shaders ?

The Q3 engine (ID Tech3) was designed that way, so the mappers have the direct control about texture properties. With shaders you are able to create many effects for your textures (transparency, glossiness, brightness, visibility, fluids, skyboxes, fog, model-skins, surface effects and many more).

Q3 shaders are stored in a plain text files with the .shader extension. The shader definitions are small scripts, which describe the texture effects and properties. Usually the shader files are named like the texture-set used by the mapper. It means if your map uses textures from maplanet folder, the shader should be named myplanet.shader

In Jedi Knight 2/3 the shaders are stored in “GameDate/base/shaders” folder.

The shader script contains a collection of renderings commands, which are grouped by ”{” und ”}” signs.

You need at least one textue as basis for the shader.

In this example we are using a lava texture.

Syntax and formatting example for a lava-shader:

Shader-Bestandteil: Beschreibung:
textures/mylava/lava_new name of the Shaders (it is not necessary to have a texture with this name)
{ shader - opening parenthesis
qer_editorimage textures/mylava/lava defines the texture, which will be shown in editor
surfaceparm lava set a lava properties to brush which uses this shader.
deformvertexes wave 100 sin 1 1 0 0.25 defines a vertex deformation for the surface with this shader added
{ opening parenthesis for the first shader layer
map textures/mylava/lava texture name for the first layer (must exist as JPG,TGA or PNG file)
blendFunc GL_ONE GL_ZERO defines blend effect for the texture
tcMod scroll 0.01 0.01 set a smooth scrolling effect to the texture
tcMod turb 1 0.1 1 0.005 add a turbulence effect to the layer, makes the lava look more realistic
tcMod stretch noise 1 0.01 0 0.05 add stretch noise effect to the layer
} end parenthesis for first layer
{ opening parenthesis for second layer
map $lightmap enables lightmap for this shader. It means the surface will cast shadows and light effects
blendFunc GL_DST_COLOR GL_SRC_COLOR defines a blend function for this layer
} closing parenthesis for the second layer
} closing parenthesis for this shader script

NOTICE: It is important to check the parenthesis signs are set correctly. There always must be a opening and a closing parenthesis for each shader and for each layer in the shader. If not, the shader wil not work, nor the shaders which are written after the flawed shader.

Usually you will write the script this way, so the layers are in a different text column as the shader main layer:

textures/mylava/lava_new
{
qer_editorimage textures/mylava/lava
surfaceparm lava
deformvertexes wave 100 sin 1 1 0 0.25
   {
   map textures/mylava/lava
   blendFunc GL_ONE GL_ZERO
   tcMod scroll 0.01 0.01
   tcMod turb 1 0.1 1 0.005
   tcMod stretch noise 1 0.01 0 0.05
   }
   {
   map $lightmap
   blendFunc GL_DST_COLOR GL_SRC_COLOR
   }
}

Because the shader files are plain text files, you can edit and create them with simple text editor like notepad. You can use any other text editor, but you must be shure to save the files as plain text or the shader will not work.

You can use the shader editor shipped with editing tools (gamedata/tools) if you have installed them, but this editor is hard to use and has few major bugs.

Ig you created your shader file and did write your shader script save the file to your base/shaders folder, in this case you can name it mylava.shader. Be shure you have the extension showing option in your system enabled or there may be a hidden ”.txt” extension in your shader file, which pervents it form working.

If you want to use your new shader in the radiant, you have to add it into your base/shaders/shaderlist.txt In your base/shaders search for the ”shaderlist.txt file”. Open it with a text editor and add your shader name (without extension) at end of the list.

Save the shaderlist.

Now start your map editor. You can find the new shader in “menu” (1.4 only) > “textures” > “mylava”.

NOTICE: If you want to test your new shader in multiplayer mode, you have to put the textures and the shader file into a pk3 file or disable the “sv_pure” in your server settings.

If you want to publish your new map, do not forget to put all the new textures and shaders into your pk3 file or people will not be able to see the textures.

DOWNLOAD OF THE TUTORIAL MAP:

mylava_test.zip

This ZIP achive “mylava_test.zip” contains:

mylava_test.pk3 = pk3-file with the shader for MP mode (copy it to your "base" folder)
mylava_test.bsp = Test-Map for the lava shader (copy to base/maps folder)
mylava_test.map = Test-Map source (copy to base/maps folder)
mylava.shader   = shader-file, copy to "base/shaders" folder (do not forget to add it to your shaderlist.txt!)
lava.jpg        = lava texture (copy to "base/textures/mylava" )
tutorials/shaders1_data/shaders1.1321299815.txt.gz · Last modified: 2011/11/14 20:43 by Pande
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki