This repository has been archived on 2022-05-12. You can view files and clone it, but cannot push or open issues or pull requests.
material-docs/ch05/pg5_1.htm

177 lines
11 KiB
HTML

<html>
<head>
<title>Vera Visions Material Manual: Stage Specific Keywords</title>
<link rel = "stylesheet" type = "text/css" href = "../styles/design.css">
</head>
<body>
<h1 class = "MsoTitle">Vera Visions Material Manual</h1>
<hr>
<h1>6 Stage Specific Keywords</h1>
Stage specifications only affect rendering. Changing any keywords or values within a stage will usually take effect as soon
as a <b>vid_reload</b> is executed. VMAP ignores stage specific keywords entirely.
<p>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.
<h2><a name = "shader">6.1 Shader specification</a></h2>
<div class = "subheading">6.1.1 program &lt;shadername&gt;</div>
Specifies the GLSL vertex/fragment shader program to use on this surface.
This needs to be first command within every stage.
<p><div class = "subheading">6.1.2 permu &lt;key&gt &lt;value&gt;</div>
Set a shader permutation for the above named <b>program</b>. This is effectively how you change parameters of some vertex/fragment shader programs. Which permutations each shader supports is up to the individual shader. Keep in mind that each unique combination results in another compile of said shader program and so comes at a price.
<h2><a name = "texmap">6.2 Texture map specification</a></h2>
<div class = "subheading">6.2.1 map &lt;texturepath/texturename&gt;</div>
Specifies the source texture map (a 24 or 32-bit TGA file) used for this stage. The texture may or may not contain alpha
channel information. There are special keywords that may be substituted in lieu of an actual
texture map name:
<ul><p><div class = "subheading">$whiteimage</div>
This is a white image generated internally by the game.
<p><div class = "subheading">$blackimage</div>
This is a black image generated internally by the game. It can be helpful too, similar to $whiteimage.
<p><div class = "subheading">$diffuse</div>
Refers to the image that was registered using the 'diffusemap' keyword at global scope.
<p><div class = "subheading">$normalmap</div>
Refers to the image that was registered using the 'normalmap' keyword at global scope.
<p><div class = "subheading">$cube:&lt;texturepath/cubemapname&gt;</div>
Refers to an actual skybox/cubemap series of images.
</ul><p><div class = "subheading">6.2.2 clampmap &lt;texturepath&gt;</div>
Dictates that this stage should clamp texture coordinates instead of wrapping them. In short: The texture does not tile.
<p><div class = "subheading">6.2.3 animmap &lt;frequency&gt; &lt;texture1&gt; &hellip; &lt;texture8&gt;</div>
The surfaces in the game can be animated by displaying asequence of 1 to 8 frames (separate texture maps). These animations
are affected by other keyword effects in the same and later shader stages.
<p><b>&lt;Frequency&gt;:</b> 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.
<br><b>&lt;texture1&gt; &hellip;&lt;texture8&gt;:</b> 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.
<p><div class = "tip"><b>Design Notes:</b> To make a texture image appear for an unequal (longer) amount of time (compared to other frames), repeat that frame more than once in the sequence.</div>
<p><pre class = "type">
// Vera Visions Material
{
qer_editorimage textures/sfx/b_flame7.tga
vmap_lightimage textures/sfx/b_flame7.tga
surfaceparm trans
surfaceparm nomarks
surfaceparm nolightmap
vmap_surfacelight 1800
cull none
{
animMap 10 textures/sfx/b_flame1.tga textures/sfx/b_flame2.tga textures/sfx/b_flame3.tga textures/sfx/b_flame4.tga textures/sfx/b_flame5.tga textures/sfx/b_flame6.tga textures/sfx/b_flame7.tga textures/sfx/b_flame8.tga
blendFunc GL_ONE GL_ONE
}
{
animMap 10 textures/sfx/b_flame2.tga textures/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.tga textures/sfx/b_flame1.tga
blendFunc GL_ONE GL_ONE
}
{
program unlit
map textures/sfx/b_flameball.tga
blendFunc GL_ONE GL_ONE
}
}
</pre>
<h2><a name = "blend">6.3 Blend Functions</a></h2>
Blend functions are the keyword commands that tell the renderer how graphic layers are to be mixed together.
<p><div class = "subheading">6.3.1 Simplified blend functions:</div>
The most common blend functions are set up here as simple commands, and should be used unless you really know what you are
doing.
<p><strong>6.3.1.1 blendFunc add</strong>
<br>This is a shorthand command for <b>blendFunc GL_ONE GL_ONE</b>. Effects like fire and energy are additive.
<p><strong>6.3.1.2 blendFunc filter</strong>
<br>This is a shorthand command that can be substituted for either <b>blendFunc GL_DST_COLOR GL_ZERO</b> or <b>blendFunc GL_ZERO GL_SRC_COLOR</b>. A filter will always result in darker pixels than what is behind it, but it can also remove color selectively. Lightmaps are filters.
<p><strong>6.3.1.3 blendFunc blend</strong>
<br>Shorthand for <b>blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA</b>. This is conventional transparency, where part of the background is mixed with part of the texture.
<p><div class = "subheading">6.3.2 Explicit blend functions:</div>
Getting a handle on this concept is absolutely key to understanding all shader manipulation of graphics.
<p>BlendFunc or "Blend Function" is the equation at the core of processing shader graphics. The formula reads as follows:
<p style = "font-weight: bold; text-align: center">[Source *&lt;srcBlend&gt;] + [Destination *
&lt;dstBlend&gt;]
<p><b>Source</b> 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.
<p><b>Destination</b> is the color data currently existing in the frame buffer.
<p>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 &hellip; one pixel of the bit map at a time.
<p>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 <b>Destination</b>. 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.
<p>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.
<p>A general rule is that any <b>Source Blend</b> other than <b>GL_ONE</b> (or <b>GL_SRC_ALPHA</b> where the alpha channel is entirely white) will cause the Source to become darker.
<p><div class = "subheading">6.3.3 Source Blend &lt;srcBlend&gt;</div>
The following values are valid for the Source Blend part of the equation.
<p><b>GL_ONE</b> This is the value 1. When multiplied by the <b>Source</b>, the value stays the same the value of the color information does not change.
<br><b>GL_ZERO</b> This is the value 0. When multiplied by the <b>Source</b>, all RGB data in the <b>Source</b> becomes Zero (essentially black).
<br><b>GL_DST_COLOR</b> 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.
<br><b>GL_ONE_MINUS_DST_COLOR</b> 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.)
<br><b>GL_SRC_ALPHA</b> The TGA file being used for the <b>Source</b> data <u>must have an alpha channel</u> 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 <b>Source</b>.
<br><b>GL_ONE_MINUS_SRC_ALPHA</b> 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)
<p><div class = "subheading">6.3.4 Destination Blend &lt;dstBlend&gt;</div>
The following values are valid for the Destination Blend part of the equation.
<p><b>GL_ONE</b> This is the value 1. When multiplied by the <b>Destination</b>, the value stays the same the value of the color information does not change.
<br><b>GL_ZERO</b> This is the value 0. When multiplied by the <b>Destination</b>, all RGB data in the <b>Destination</b> becomes Zero (essentially black).
<br><b>GL_SRC_COLOR</b> This is the value of color data currently in the <b>Source</b> (which is the texture being manipulated here).
<br><b>GL_ONE_MINUS_SRC_COLOR</b> This is the value of color data currently in <b>Source</b>, but subtracted from one(i.e.
inverted).
<br><b>GL_SRC_ALPHA</b> The TGA file being used for the <b>Source</b> data <u>must have an alpha channel</u> 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 <b>Source</b>.
<br><b>GL_ONE_MINUS_SRC_ALPHA</b> 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).
<p><strong>Doing the Math: The Final Result</strong>
<br>The product of the <b>Source</b> side of the equation is added to the product of the <b>Destination</b> side of the equation. The sum is then placed into the frame buffer to become the <b>Destination</b> 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.
<p><div class = "subheading">6.3.5 Default Blend Function</div>
<i>If no <b>blendFunc</b> is specified then no blending will take place.</i> That's just a fact of life.
<h2><a name = "depthfunc">6.4 depthFunc &lt;func&gt;</a></h2>
This controls the depth comparison function used while rendering. The default is "lequal" (Less than or equal to)
where any surface that is at the same depth or closer of an existing surface is drawn. This is used for textures with
transparency or translucency. Under some circumstances you may wish to use "equal", e.g. for light-mapped grates that are alpha tested (it is also used for mirrors).
<h2><a name = "depthwrite">6.5 depthWrite</a></h2>
By default, writes to the depth buffer when depthFunc passes will happen for opaque surfaces and not for translucent surfaces. Blended surfaces can have the depth writes forced with this function.
<p align = "center"><a href = "../ch04/pg4_1.htm">Back</a> | <a href = "../index.html">Home</a> | <a href = "../ch06/pg6_1.htm">Next</a>
</body>
</html>