Gaming
 

Basic shader examples

From OpenArena

In quake III shaders are unrelated to programmable shaders found on GPUs or the directx shaders. QIII shaders aren't really a shading language used in modern games, but it has some opengl fixed functions to perform some basic operations such as alpha blends, alpha transparencies, scrolls or lightmaps.

textures/folder/name To better order your textures it's a good idea to sort them in a subfolder of the textures folder. Note that in radiant, textures are listed in groups of folders per shader file, no two levels deep subfolders. This name doesn't need to match texture's filename.

It's important to note that since these shaders here have no programmable functions, every texture property or parameter is fixed, static. QIII doesn't support dynamic shaders that affect / are affected by the world around, no realtime reliefs, no realtime shadow casting, no per pixel specularity / reflectivity or refractivity / bumps, etc. At best multiple pre-rendered textures could form an animated shader to simulate some dynamic effect.

To paste shader scripts without losing line breaks, replaced TAB indents with spaces, and add spaces before each line.

Contents

[edit] Basic sprites

textures/xxxxxx
{
   deformVertexes autoSprite
   surfaceparm trans
   surfaceparm nomarks
   surfaceparm nolightmap
   cull none
        {		 
        clampmap textures/xxxxxx.tga
        blendFunc blend
        rgbGen identity
        }
}

This works by using a cube brush with just one face textured with this shader, all other faces should be nodraw and non-solid.

This is a lens flare shader, but can be used on skyboxes to decorate it with sprites. Clampmap makes the texture scale like lens flare do, larger at distance, smaller when closer, but since skybox distance is fixed, the sprites scale stays fixed as well. blendfunc blend makes the black pixels of the texture's alpha channel invisible. The size of the sprite can be changed by changing the brush's size.

rgbgen identity can be removed.

[edit] A bright and non-lightmapped texture

textures/xxxxxxxxx
{
   qer_editorimage textures/xxxxxxxxxx.tga
   q3map_nolightmap
{
  map textures/xxxxxx.tga
  blendFunc GL_ONE GL_zero
}
}

This creates a texture that ignores lightmaps, but doesn't render as a black surface in game. Blendfunc gl_one gl_zero makes the texture brightness equal to 1 in game, while the lightmap of that face equal to zero, thus, ignored or invisible in game.

If the brush is a lamp or some 3D lightsource, add surfaceparm trans to make light not be blocked by the brush.

[edit] Translucent and lightmapped texture

textures/xxxxx
{
       surfaceparm nomarks
       surfaceparm trans
       surfaceparm water
       cull none
	{
            map textures/liquids/xxxx.tga
            rgbGen identity
            blendfunc blend
            alphaGen const 0.5
	}
  { 
  tcgen lightmap
  map $lightmap
  blendfunc gl_dst_color gl_src_color
  rgbGen identity
  }
}

It's possible to make glass or water surfaces that are both translucent and lightmapped, instead of just translucent and full bright.

surfaceparm trans make the texture invisible to lightrays, as a result it doesn't cast shadows.

tcgen lightmap this was copied from external lightmaps trick.

blendfunc gl_dst_color gl_src_color this is the how the lightmap is blended with the texture.

alphaGen const 0.5 this is a constant translucency factor.

Note: (taken from hydronex water shader). The lightmap stage should be last, after the transparency stage.

Some more specific details still missing.

[edit] Simple environment reflection

textures/xxxxxxxxx
{
   q3map_nolightmap
	{
		map textures/xxxxxxxx.tga
		tcgen environment
		rgbGen identitylighting
		tcmod scale -1 1
	}
}

This pick ups a screenshot, photo or texture and renders in game as a environment map, more or less like the reflection created by highly specular surfaces, or wet surfaces.

The distortion that occurs in game is vertex basead, a highly tesselated surface could render with less distortion.

rgbgen identitylighting changing this changes the overall brightness of the environment map.

tcmod scale x y this scales / flips the env map. The env map tga stretches a lot in game, missing information about how to control both the scale and the texture alignment...

This effect is cheap because it's not a realtime reflection, it's a reflection basead on a pre-taken screenshot or a simple texture.


[edit] Animated texture

textures/testes/1
{
   qer_editorimage textures/test/1.tga
   {
      animmap 1 textures/test/1.tga textures/test/2.tga textures/test/3.tga textures/test/4.tga textures/test/5.tga textures/test/6.tga textures/test/7.tga textures/test/8.tga
   }
}

Q3 animmap is limited to 8 frames, any other frame beyond that is ignored by the engine. The textures doesn't need to be numbered like the above example.

animmap x this controls the animation's frame rate. How many sequences are played per second.