News Design Materials Articles
 Phong Shading - How do you create it?  Page 2 of 3
Process Phong Shading is a compiler only feature which is enabled via special shader commands. In order to have certain brushwork use Phong Shading the relevant surfaces must use a shader.

A Phong shader should contain special commands for the compiler and also point to the correct texture which will be used on the brushwork surfaces. The shader is stored in a shader file located in the 'scripts' directory. All shader files are stored in a plain text format and can be edited by any text editor.

The compiler checks each brush surface in the map for shaders. If the compiler finds the relevant special compiler commands inside of a shader then Phong Shading is enabled on the brush surface edges.
 Phong Shader
The following example is a Phong Shader with the special compiler commands. Directly after the sample shader is an explaination of what each line does. If you want further information on what Q3 Shaders are and how they work, then please have a look at the online Q3 shader manual.

(01) //========================================================
(02) // myrock.shader
(03) //========================================================
(04) textures/myrock/wall01
(05) {
(06) 	q3map_nonplanar
(07) 	q3map_shadeangle 60
(08) 	qer_editorimage textures/myrock/wall01_phong.tga
(09) 	{
(10) 		map $lightmap
(11) 		rgbGen identity
(12) 	}
(13) 	{
(14) 		map textures/myrock/wall01.tga
(15) 		blendFunc filter
(16) 	}
(17) }
  • Lines 1-3 : are just comments which can be ignored for the moment.

  • Line 4 : is the name of the shader and is applied to all brushwork surfaces which use this shader. Always use the full path when referring to shaders in the editor.

  • Line 5,17 : The Q3 shader language is very strict on layout. The curly brackets are used to specify where a section starts and finish and needs to be used in pairs. If you use an open curly bracket to start something, then a closed curly bracket will be required to finish it.

  • Line 6 : lets the compiler know that its OK to merge triangles that don't lie in the same plane. (ie not at the same angle to each other) The default settings for the compiler is to not merge triangles in different planes. Once the triangles are merged together the shadows can be cast correctly across the edges.

  • Line 7 : specifies the triangle edge angle at which the light will be diffused. ie. The larger the specified value the more smooth all the triangles will appear as it affects more edges. (Brushwork is always broken down into triangles by the compiler)

  • Line 8 : is the image used to represent this shader in the editor. (2d, 3d and texture preview panel) It is not used by the engine and often contains useful information for the Level Designer only.

  • Line 9-12 : is the light stage of the shader. If not specified the shader will not have any light information (shadows) drawn.

  • Line 13-16 : is the base texture used on the brushwork. Should always specify TGA file format in Shaders regardless if the file exists or not. If the engine cannot find a TGA file it will search for a JPG version instead.
 Where do all the bits go?
Everything has to go in a certain place in order for Phong Shading to work correctly. Here is a quick list of things you need to create and where to put them:

  • The organic texture needs to be put into the textures directory and stored in a sub-directory with a unique name. Often the sub-directory is named after the map it is being used in so that it does not conflict with anyone else's work.

    ie. textures \ myrockmap \ myrock.tga

  • The Phong shader needs to be created and stored in the scripts directory. Take the example shader listed above and change lines 4, 8 and 14 to point to the texture above. Save the shader in a shader file and name it after the map in which it will be used. (Like the sub-directory for the texture)

    The file must have the correct extension of '.shader' so that it is recognised by the compiler and engine as a valid shader file.

    ie. scripts \ myrockmap.shader

  • Every scripts directory has a text file which contains a list of all the other shader files used by the game. This file is usually called 'shaderlist.txt'. Open this file up and add the name of your new shader file to the list. Save the changes back to the original file.

    The file 'shaderlist.txt' is unique to your game / editor setup and does not need to be distributed with your final work.
Mememe
Articles 
General -
Terrain Blending -
 2  3  4  5  6  7  - Pg  
Rockwall Corridors -
 2  3  4  - Pg  
Rockwall Detail -
 2  3  4  - Pg  
2 Point Clipping -
 2  3  4  - Pg  
Phong Shading -
 2  3  - Pg  
RTCW -
Scripted Doors -
Basic Lift -
Advanced Lift -
Links 
Places -
Crytek -
Func_Msgboard -
Level Makers -
..::Lvl Maps -
Mememe -
Q3 World -
Raven Software -
Splashdamage -
People -
Ken Beyer -
Chad Bordwell -
Nicolas Bouvier -
Matthew Breit -
Ford Dye -
Fred Hooper -
Randy Reddig -
Benoit Stordeur -
Tom Waters -
Andrew Weldon -
Pat Williams -
Info -
LinkedIn -
Moby Games -
Garage Profile -
Facebook -
Archive 
Aug - Dec 2008 -
Jan - Jul 2008 -
2007 -
2006 -
2005 -
2004 -
2003 -
2002 -
Firefox 3 Valid HTML 4.01 Transitional
Mememe