A stage can specify a texture map, a color function, an alpha function, a texture coordinate function, a blend function, and a few other rasterization options.
Proper Alignment: When using clampTexCoords make sure the texture is properly aligned on the brush. The clampTexCoords function keeps the image from tiling. However, the editor doesn't represent this properly and shows a tiled image. Therefore, what appears to be the correct position may be offset. This is very apparent onanything with a tcMod rotate and clampTexCoords function.
AvoidingDistortion: When seen at a given distance (which can vary, depending onhardware and the size of the texture), the compression phase of a stretchfunction will cause a "cross"-like visual artifact to form on the modified texture due to the way that textures are reduced. This occurs because the texture undergoing modification lacks sufficient "empty space" around the displayed (non-black) part of the texture (see figure 2a). To compensate for this, make the non-zero portion of the texture substantially smaller (50% of maximum stretched size -- see figure 2b)than the dimensions of the texture. Then, write a scaling function (tcScale) into the appropriate shader phase, to enlarge the image to the desired proportion.
The shaders for the bouncy pads (in the sfx.shader file) show the stretch function in use, including the scaling of the stretched texture:
Example: UsingclampTexCoords to control a stretching texture
textures/sfx/metalbridge06_bounce { //q3map_surfacelight 2000 surfaceparm nodamage q3map_lightimage textures/sfx/jumppadsmall.tga q3map_surfacelight 400 { map textures/sfx/metalbridge06_bounce.tga rgbGen identity } { map $lightmap rgbGen identity blendfunc gl_dst_color gl_zero } { map textures/sfx/bouncepad01b_layer1.tga blendfunc gl_one gl_one rgbGen wave sin .5 .5 0 1.5 } { clampmap textures/sfx/jumppadsmall.tga blendfunc gl_one gl_one tcMod stretch sin 1.2 .8 0 1.5 rgbGen wave square .5 .5 .25 1.5 } // END }
<Frequency>: the number of times that the animation cycle will repeat within a one second time period. The
larger the value, the more repeats within a second. Animations that should last for more than a second need to be expressed as decimal values.
<texture1> …<texture8>: the texture path/texture name for each animation frame must be
explicitly listed. Up to eight frames (eight separate .tga files) can be used to make an animated sequence. Each frame is
displayed for an equal subdivision of the frequency value.
Example: AnimMap 0.25 animMap 10textures/sfx/b_flame1.tga textures/sfx/b_flame2.tga textures/sfx/b_flame3.tgatextures/sfx/b_flame4.tga would be a 4 frame animated sequence, calling each frame in sequence over a cycle length of 4 seconds. Each frame would be displayed for 1 second before the next one is displayed. The cycle repeats after the last frame in sequence is shown.
textures/sfx/flameanim_blue { // ************************************************* // * Blue Flame * // * July 20, 1999 Surface Light 1800 * // * Please Comment Changes * // ************************************************* qer_editorimage textures/sfx/b_flame7.tga q3map_lightimage textures/sfx/b_flame7.tga surfaceparm trans surfaceparm nomarks surfaceparm nolightmap cull none q3map_surfacelight 1800 // texture changed to blue flame.... PAJ { animMap 10 textures/sfx/b_flame1.tgatextures/sfx/b_flame2.tga textures/sfx/b_flame3.tga textures/sfx/b_flame4.tgatextures/sfx/b_flame5.tga textures/sfx/b_flame6.tga textures/sfx/b_flame7.tgatextures/sfx/b_flame8.tga blendFunc GL_ONE GL_ONE rgbGen wave inverseSawtooth 0 1 0 10 } { animMap 10 textures/sfx/b_flame2.tgatextures/sfx/b_flame3.tga textures/sfx/b_flame4.tga textures/sfx/b_flame5.tgatextures/sfx/b_flame6.tga textures/sfx/b_flame7.tga textures/sfx/b_flame8.tgatextures/sfx/b_flame1.tga blendFunc GL_ONE GL_ONE rgbGen wave sawtooth 0 1 0 10 } { map textures/sfx/b_flameball.tga blendFunc GL_ONE GL_ONE rgbGen wave sin .6 .2 0 .6 } }
6.2.1.1 blendfunc add
This is a shorthand command for blendfunc gl_one gl_one. Effects like fire and energy are additive.
6.2.1.2 blendfunc filter
This is a shorthand command that can be substituted for either blendfunc gl_dst_color gl_zero or blendfunc gl_zero gl_src_color. A filter will always result in darker pixels than what is behind it, but it can also remove color selectively. Lightmaps are filters.
6.2.1.3 blendfunc blend
Shorthand for blendfunc gl_src_alphagl_one_minus_src_alpha. This is conventional transparency, where part of the background is mixed with part of the texture.
BlendFunc or "Blend Function" is the equation at the core of processing shader graphics. The formula reads as follows:
[Source *<srcBlend>] + [Destination * <dstBlend>]
Source is usually the RGB color data in a texture TGA file (remember it's all numbers) modified by any rgbgen and alphagen. In the shader, the source is generally identified by command MAP, followed by the name of the image.
Destination is the color data currently existing in the frame buffer.
Rather than think of the entire texture as a whole, it maybe easier to think of the number values that correspond to a single pixel, because that is essentially what the computer is processing … one pixel of the bit map at a time.
The process for calculating the final look of a texture in place in the game world begins with the precalculated lightmap for the area where the texture will be located. This data is in the frame buffer. That is to say, it is the initial data in the Destination. In an unmanipulated texture (i.e. one without a special shader script), color information from the texture is combined with the lightmap. In a shader-modified texture, the $lightmap stage must be present for the lightmap to be included in the calculation of the final texture appearance.
Each pass or "stage" of blending is combined (in a cumulative manner) with the color data passed onto it by the previous stage. How that data combines together depends on the values chosen for the Source Blends and Destination Blends at each stage. Remember it's numbers that are being mathematically combined together that are ultimately interpreted as colors.
A general rule is that any Source Blend other than GL_ONE (or GL_SRC_ALPHA where the alpha channel is entirely white) will cause the Source to become darker.
GL_ONE This is the value 1. When multiplied by the Source, the value stays the same the value of the color information does not change.
GL_ZERO This is the value 0. When multiplied by the Source, all RGB data in the Source becomes Zero (essentially black).
GL_DST_COLOR This is the value of color data currently in the Destination (frame buffer). The value of that information depends on the information supplied by previous stages.
GL_ONE_MINUS_DST_COLOR This is nearly the same as GL_DST_COLOR except that the value for each component color
is inverted by subtracting it from one. (,i.e. R = 1.0 - DST.R, G = 1.0 - DST.G, B = 1.0 - DST.B, etc.)
GL_SRC_ALPHA The TGA file being used for the Source data must have an alpha channel in addition to its RGB channels (for a total of four channels). The alpha channel is an 8-bit black and white only channel. An entirely white alpha channel will not darken the Source.
GL_ONE_MINUS_SRC_ALPHA This is the same as GL_SRC_ALPHA except that the value in the alpha channel is inverted by subtracting it from one.(i.e. A=1.0 - SRC.A)
GL_ONE This is the value 1. When multiplied by the Destination, the value stays the same the value of the color information does not change.
GL_ZERO This is the value 0. When multiplied by the Destination,all RGB data in the Destinationbecomes Zero (essentially black).
GL_SRC_COLOR This is the value of color data currently in the Source (which is the texture being manipulated here).
GL_ONE_MINUS_SRC_COLOR This is the value of color data currently in Source, but subtracted from one(i.e.
inverted).
GL_SRC_ALPHA The TGA file being used for the Source data must have an alpha channel in addition to its RGB channels (four a total of four channels). The alpha channel is an 8-bit black and white only channel. An entirely white alpha channel will not darken the Source.
GL_ONE_MINUS_SRC_ALPHA This is the same as GL_SRC_ALPHA except that the value in the alpha channel is inverted by subtracting it from one. (i.e. A=1.0 - SRC.A).
Doing the Math: The Final Result
The product of the Source side of the equation is added to the product of the Destination side of the equation. The sum is then placed into the frame buffer to become the Destination information for the next stage. Ultimately, the equation creates a modified color value that is used by other functions to define what happens in the texture when it is displayed in the game world.
GL_ONE, GL_ONE
GL_DST_COLOR, GL_ZERO
GL_ZERO, GL_SRC_COLOR
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA
Cards running in 16 bit color cannot use any GL_DST_ALPHA blends.
The most common reason to use rgbGen is to pulsate something. This means that the VERTEXCOLOR will oscillate between two values, and that value will be multiplied (darkening) the texture.
If no rgbGen is specified, either "identityLighting" or"identity" will be selected, depending on which blend modes are used.
Valid <func> parameters are wave, identity, identityLighting, entity, oneMinusEntity, fromVertex, and lightingDiffuse.
<func> Waveforms and their effects:
Sin: color flows smoothly through changes.
Triangle: color changes at a constant rate and spends noappreciable time at peaks and valleys.
Square: color alternates instantly between its peak and valley values.
Sawtooth: With a positive frequency value, the color changes at aconstant rate to the peak then instantly drops to its valley value.
Inversesawtooth: An inverse sawtooth wave will reverse this, making the ascent immediate (like a square wave) and the decay fall off like a triangle wave.
<base> Baseline value. The initial RGB formula of a color (normalilzed).
<amp> Amplitude. This is the degree of change from the baseline value. In some cases you will want
values outside the 0.0 to 1.0 range, but it will induce clamping (holding at the maximum or minimum value for a time period)
instead of continuous change.
<phase> See the explanation for phase under the waveforms heading of Key Concepts.
<freq> Frequency. This is a value (NOT normalized) that indicates peaks per second.
<base> = base texture coordinates from the original art.
<lightmap> = lightmap texture coordinates
<environment> = Make this object environment mapped.
S coordinates correspond to the "x" coordinates on the texture itself.
T coordinates correspond to the "y" coordinates on the texture itself.
The measurements are in game units.
Example: tcGen vector (0.01 0 0) (0 0.01 0)
This would project a texture with a repeat every 100 units across the X/Y plane.
tcMod scale 0.5 0.5
tcMod scroll 1 1
Then the texture coordinates will be scaled then scrolled.
Example: tcMod scale 0.5 2 would cause the texture to repeat twice along its width, but expand to twice its height (in which case half of the texture would be seen in the same area as the original)
Example: tcMod scroll 0.5 -0.5 moves the texture down and right (relative to the TGA files original coordinates) at the rate of a half texture each second of travel.
This should be the LAST tcMod in a stage. Otherwise there maybe popping or snapping visual effects in some shaders.
<base>: A base value of one is the original dimension of the texture when it reaches the stretch stage.
Inserting other values positive or negative in this variable will produce unknown effects.
<amplitude>: This is the measurement of distance the texture will stretch from the base size. It is
measured, like scroll, in textures. A value of 1 here will double the size of the texture at its peak.
<phase>: See the explanation for phase under the deform vertexes keyword.
<frequency>: this is wave peaks per second.
Wave Functions <func>
Sin wave: the texture expands smoothly to its peak dimension and then shrinks smoothly to its valley dimension in a flowing manner.
Triangle wave: The textures stretch at a constant rate and spend no appreciable time at the peak or valley points.
Square wave: The texture is shown at its peak for the duration of the frequency and then at its valley for the
duration of the frequency.
Sawtooth: the texture stretches like a triangle wave until it reaches a peak, then instantly drops to the valley, as in a square wave.
Inversesawtooth: this is the reverse of the sawtooth wave.
S' = s * m00 + t * m10 + t0
T' = s * m01 + t * m11 + t1
This is for use by programmers.
Applies turbulence to the texture coordinate. Turbulence is a back and forth churning and swirling effect on the texture.
The parameters for this shader are defined as follows:
<base> Currently undefined.
<amplitude> This is essentially the intensity of the disturbance or twisting and squiggling of the texture.
<phase> See the explanation for phase under the deformvertexes keyword.
<freq> Frequency. This value is expressed as repetitions or cycles of the wave per second. A value of one
would cycle once per second. A value of 10 would cycle 10 times per second. A value of 0.1 would cycle once every 10
seconds.
blendFuncGL_DST_COLOR GL_SRC_COLOR
This is also the simple blend function: blendfuncfilter
And the average intensity of the detail texture itself must be around 127.
Detail is used to blend fine pixel detail back into a base texture whose scale has been increased significantly. When detail iswritten into a set of stage instructions, it allows the stage to be disabled by the c_var console command setting "r_detailtextures 0".
A texture whose scale has been increased beyond a 1:1 ratio tends not to have very high frequency content. In other words, one texel can cover a lot of real estate. Frequency is also known as "detail." Lack of detail can appear acceptable if the player never has the opportunity to see the texture at close range. But seen close up, such textures look glaringly wrong within the sharp detail of the Quake III Arena environment. A detail texture solves this problem by taking a noisy "detail" pattern (a tiling texture that appears to have a great deal of surface roughness) and applying it to the base texture at a very densely packed scale (that is, reduced from its normal size). This is done programmatically in the shader, and does not require modification of the base texture. Note that if the detail texture is the same size and scale as the base texture that you may as well just add the detail directly to the base texture. The theory is that the detail texture's scale will be so high compared to the base texture (e.g.; 9 detail texels fitting into 1 base texel) that it is literally impossible to fit that detail into the base texture directly.
For this to work, the rules are as follows:
An example (non-existent) detailshader is as follows:
Example: Texture with Detail
textures/bwhtest/foo { // draw the lightmap first { map $lightmap rgbGen identity } // modify the lightmap in the framebuffer by // a highly compressed detail texture { map textures/details/detail01.tga blendFunc GL_DST_COLOR GL_SRC_COLOR // YOU MUST USE THIS!! detail // for the detail to be disabled, this must be present tcMod scale 9.1 9.2 } // now slap on the base texture { map textures/castle/blocks11b.tga blendFunc filter } }
Both alpha testing and normal alpha blending can be used to get textures that have see-through parts. The difference is that alphaFunc is an all-or-nothing test, while blending smoothly blends between opaque and translucent at pixel edges. Alpha test can also be used with depthwrite, allowing other effects to be conditionally layered on top of just the opaque pixels by setting depthFunc to equal.