News Design Artwork Photos Articles
Creative Commons All use of my digital work is covered by this Creative Commons Deed.
Please do not use any of my work for commercial purposes, thank you.
 Creating Terrain (2 of 7) Previous Page Next Page
Textures The DotProduct2 shader uses 2 textures which will be referred to by this article as primary and secondary.

Next find some big seamless general purpose material textures which have the relevant alpha channel setup. Note: Only the secondary textures require an alpha channel if you are wanting to save memory / pk3 space.

The terrain blends are not visible in the editor (only in the game) so it is worthwhile creating clearly marked editor textures for the DotProduct2 shaders.
 DotProduct2 shader explained    
The DotProduct2 shader may seem complex at first but it is essentially just a collection of special compiler commands, 2 textures (one alpha blended) and 1 lightmap. Below is an example taken from the sample map with descriptions of what each line does.

01
02
03
04
05
textures/terrain_example/ter_mossmud { qer_editorimage textures/terrain_example/ter_mossmud.tga q3map_nonplanar q3map_shadeAngle 120

Line 1 the name of the shader prefixed with a ter_ to help with sorting in the texture window.
Line 3 is the editor only image used for this shader, which needs to be the same X,Y size as the final game image. The only exception to this rule is if the shader uses the q3map_tcGen command. (see note 6 below for more details)
Line 4 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 5 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.
It is always recommended to start with a low value and then work upwards if needed. Be warned high values can destroy nice crisp shadows and eventually make the surface look like liquid due to very smooth shadows. See link for more details.

06 q3map_tcGen ivector ( 256 0 0 ) ( 0 256 0 )

Line 6 specifies precisely how the texture will be projected in 3D space. Please note that the system only uses 2 axes because the actual texture is 2D and flat.

The DotProduct2 shader may seem complex at first but it is essentially just a collection of special compiler commands, 2 textures (one alpha blended) and 1 lightmap. Below is an example taken from the sample map with descriptions of what each line does.

The parameters used in this example (X Y Z)(X Y Z) are referring to the XY axes (essentially the height and width) of a texture. This means that  this example shader will only work with a top down projection. (floor based terrain) Other axes combination are valid if a different texture projection are required.

Please note: The spaces around the parentheses () in the q3map_tcGen ivector command line are required. The values specified must be in the form of ( X Y Z )( X Y Z ).

The Q3 engine generally uses a scale of 0.5 (as default) for all textures. If the terrain shader needs to match up with existing textures in the map then the scale has to be similar. For example a 512x512 terrain texture would use a parameter value of 256, while a 256x256 terrain texture would use a 128 value instead.

Please note: If the shader is using a different texture projection to the example above then the parameter value will be in a different positions on the command line.

If this command is present in a shader all editor texture alignment values will be ignored. This command can be useful if wanting to align several DotProduct2 terrains together and not have to worry about texture alignment.

Please note: If manual texture alignment is wanted in the editor then remove this line from the shader. This does not mean alpha blending will be displayed in the editor, only that the texture alignment can be adjusted visually in the editor.

07 q3map_alphaMod dotproduct2 ( 0.0 0.0 0.75 )

Line 7 is the DotProduct2 command which specifies how the alpha channel of the secondary textures will be faded in or out over the top of the primary texture.

Please note: The spaces around the parentheses () in the q3map_alphaMod dotproduct2 command line are required. The values specified must be in the form of ( X Y Z ).

To properly understand what the DotProduct2 command does, an explanation of what vertex normals are and how they are affected by the compiler is required first.

A brush is made up from several faces. Each faces is then turned into a collection of triangles by the compiler. Each brush face lies in a plane, with a distinct normal (facing direction), which is propagated to the vertexes of each of the triangles created from that face.

Vertex normals Before merging vertex normals After merging
Vertex Normals Before merging Vertex Normals After merging

The images above show what the vertex normals look like at each point on the terrain before and after they are optimized by the compiler. The compiler commands q3map_nonplanar, q3map_shadeAngle and a high enough shadeAngle will take an average of all the vertex normals at each point and merge them together.

Sometimes the perimeter of a DotProduct2 terrain can have strange alpha values and this is because of the average / merge process. If the alpha blend is wrong on the side of the terrain, either create more brushwork flush with the terrain edges or use an Alpha Fade brush to set the alpha manually.

Each vertex (in the above screenshots) is multiplied against the DotProduct2 parameters and finally squared to create the alpha value at each point on the terrain.

Maths used by DotProduct2: Vertex (A B C), DotProd2 (X Y Z), (A*X + B*Y + C*Z)^2 = Alpha Value.

An Example:

A vertex normal on the terrain (0 0 1) which is facing upwards is multiplied against the DotProduct2 parameters (0 0 0.75) and the final results is squared. The alpha value at that vertex point is 0.5625 which is a good mix of both textures.

Maths: (0*0 + 0*0 + 1*0.75) = 0.75^2 = 0.5625

08
09
10
11
{ map textures/terrain_example/ter_moss1.tga // Primary rgbGen identity }

Lines 8-11 specifies the primary texture used and will also affect the colour tone of the overall terrain image displayed in game. This is because the DotProduct2 system basically fades in and out the secondary texture on top of the primary texture. If the primary texture is very dark in colour tones, then the overall terrain image will be darker too.

12
13
14
15
16
17
18
{ map textures/terrain_example/ter_mud1.tga // Secondary blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA alphaFunc GE128 rgbGen identity alphaGen vertex }

Lines 12-18 specifies the secondary texture used. This is the only texture which requires an alpha channel as the primary texture is always drawn. The values for the alpha channel are controlled via the DotProduct2 and not via this stage.

19
20
21
22
23
24
{ map $lightmap blendFunc GL_DST_COLOR GL_ZERO rgbGen identity } }

Lines 19-24 is the Lightmap stage for the shader. If vertex light is required, remove this stage and change all rgbGen statements to vertex instead.

Prev Page Next Page
Mememe
Articles 
Level Design -
GameDev Advice -
Creating Terrain -
Terrain Blending -
Rockwall Corridors -
Rockwall Detail -
2 Point Clipping -
Phong Shading -
3D Puzzle Scripting -
Triggerable Shaders -
RTCW Scripting -
Scripted Doors -
Basic Lift -
Advanced Lift -
Cooking -
Apple Crumble -
This site has been cobbled together by Simon O'Callaghan
Contact Information: Simon O'Callaghan
All content is Copyright © 2000-2024
Hosted by ApisNetwork