1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<HTML> 3<HEAD> 4<META http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5<META name="GENERATOR" content="Microsoft FrontPage 5.0"> 6<META http-equiv="Content-Style-Type" content="text/css"> 7<LINK rel="stylesheet" type="text/css" href="../../CSS/revolution.css"> 8<TITLE>GXSetTexCoordGen</TITLE> 9</HEAD> 10<BODY> 11<H1 align="left">GXSetTexCoordGen</H1> 12 13<H2>Syntax</H2> 14<dl><dd><pre class="construction"> 15#include <revolution/gx.h> 16 17void GXSetTexCoordGen( 18 <A href="../Enumerated_Types/GXTexCoordID.html">GXTexCoordID</A> dst_coord, 19 <A href="../Enumerated_Types/GXTexGenType.html">GXTexGenType</A> func, 20 <A href="../Enumerated_Types/GXTexGenSrc.html">GXTexGenSrc</A> src_param, 21 u32 <A href="../Enumerated_Types/GXTexMtx.html">mtx</A> ); 22</pre></dd></dl> 23 24<H2>Arguments</H2> 25<TABLE class="arguments" border="1" > 26 <TBODY> 27 <TR> 28<TH>dst_coord</TH> 29<TD><A href="../Enumerated_Types/GXTexCoordID.html">Name</A> of the texture coordinate to be generated. Accepted values are: <code>GX_TEXCOORD0</code>, <code>GX_TEXCOORD1</code>, <code>GX_TEXCOORD2</code> through <code>GX_TEXCOORD7</code>.</TD> 30 </TR> 31 <TR> 32<TH>func</TH> 33<TD><A href="../Enumerated_Types/GXTexGenType.html">Feature</A> used to generate texture coordinates. Accepted values are:<BR> 34 <TABLE class="arguments" border="1" > 35 <tr> 36<TD bgcolor="#C0C0C0">Name</TD> 37<TD bgcolor="#C0C0C0">Type of Texture Coordinate Generation</TD> 38 </tr> 39 <tr> 40<TH>GX_TG_MTX2x4</TH> 41<TD>Source attributes are converted into a 2x4 matrix.</TD> 42 </tr> 43 <tr> 44<TH>GX_TG_MTX3x4</TH> 45<TD>Source attributes are converted into a 3x4 matrix.</TD> 46 </tr> 47 <tr> 48<TH>GX_TG_BUMP0-7</TH> 49<TD>Embossed-style bump texture coordinates.</TD> 50 </tr> 51 <tr> 52<TH>GX_TG_SRTG</TH> 53<TD>R (red)/G (green) components from color channel output.</TD> 54 </tr> 55 </TABLE> 56 </TD> 57 </TR> 58 <TR> 59<TH>src_param</TH> 60<TD>Name of source attributes used to generate texture coordinates. 61 <TABLE class="arguments" border="1" > 62 <TBODY> 63 <TR> 64<TD bgcolor="#C0C0C0">Features</TD> 65<TD bgcolor="#C0C0C0">Specifiable values for <SPAN class="argument">src_param</SPAN> are:</TD> 66 </TR> 67 <TR> 68<TH>GX_TG_MTX3x4<BR> GX_TG_MTX2x4</TH> 69<TD><CODE>GX_TG_POS</CODE> (position coordinate)<BR> <CODE>GX_TG_NRM</CODE> (normal)<BR> <CODE>GX_TG_BINRM</CODE> (binormal)<BR> <CODE>GX_TG_TANGENT</CODE> (tangent)<BR> <CODE>GX_TG_TEX0-7</CODE> (input texture coordinates)</TD> 70 </TR> 71 <TR> 72<TH>GX_TG_BUMP0-7</TH> 73<TD><CODE>GX_TG_TEXCOORD0-6</CODE></TD> 74 </TR> 75 <TR> 76<TH>GX_TG_SRTG</TH> 77<TD><CODE>GX_TG_COLOR0</CODE><BR> <CODE>GX_TG_COLOR1</CODE></TD> 78 </TR> 79 </TBODY> 80 </TABLE> 81 </TD> 82 </TR> 83 <TR> 84<TH>mtx</TH> 85 <TD> 86 <TABLE class="arguments" border="1" > 87 <TBODY> 88 <TR> 89<TD bgcolor="#C0C0C0">Features</TD> 90<TD bgcolor="#C0C0C0">Specifiable values for <SPAN class="argument">mtx</SPAN> are:</TD> 91 </TR> 92 <TR> 93<TH>GX_TG_MTX2x4<BR> GX_TG_MTX3x4</TH> 94<TD><CODE>GX_TEXMTX0-9</CODE>, <CODE>GX_IDENTITY</CODE></TD> 95 </TR> 96 <TR> 97<TH>GX_TG_BUMP0-7</TH> 98<TD>Not used.</TD> 99 </TR> 100 <TR> 101<TH>GX_TG_SRTG</TH> 102<TD>Not used.</TD> 103 </TR> 104 </TBODY> 105 </TABLE> 106 </TD> 107 </TR> 108 </TBODY> 109</TABLE> 110 111<H2>Return Values</H2> 112<P>None.</P> 113 114<H2>Description</H2> 115<P>This function is used to specify how texture coordinates are generated. Output texture coordinates are usually the result of some transform of an input attribute, either for position, normal, or texture coordinates. You can also generate texture coordinates from the output color channel for vertex lighting calculations. This function also supports the embossed style of bump-mapping. In C-language syntax the texture coordinate generation function would look like this:</P> 116<P><SPAN class="argument">dst_coord = func(src_param, mtx);</SPAN></P> 117<P>The current vertex descriptor as set by the <A href="../Geometry/GXSetVtxDesc.html"><CODE>GXSetVtxDesc</CODE></A> function only describes the data input to the graphics processor. Using the <A href="GXSetTexCoordGen.html"><CODE>GXSetTexCoordGen</CODE></A> function, you can create new output texture coordinates from the input data. The <SPAN class="argument">dst_coord</SPAN> argument is used to give the output texture coordinate a name. This texture coordinate can be bound to a texture using the <A href="../Tev/GXSetTevOrder.html"><CODE>GXSetTevOrder</CODE></A> function. The <A href="GXSetNumTexGens.html"><CODE>GXSetNumTexGens</CODE></A> function specifies a consecutive number of texture coordinates, starting at <CODE>GX_TEXCOORD0</CODE>, that is available to the <A href="../Tev/GXSetTevOrder.html"><CODE>GXSetTevOrder</CODE></A> function.</P> 118 119 120 121<P>Input texture coordinates must <strong>always</strong> pass through the texture-coordinate generation hardware. Because, with the <CODE>GXInit</CODE> function, the input texture coordinates pass through the texture coordinate generation hardware with no change in their values, you call this function for initialization so that all texture coordinates are transformed by the <CODE>GX_IDENTITY</CODE> matrix.</P> 122<P>There are eight output texture coordinates that can be referenced in any of the 16 TEV stages. There are a maximum of eight input texture coordinates.</P> 123<P>The <A href="../Enumerated_Types/GXTexMtx.html"><CODE>GXTexMtx</CODE></A> enumerator defines a default set of texture matrix names that can be supplied as <SPAN class="argument">mtx</SPAN>. The matrix names are actually row addresses (four floating point digits per row) in the matrix memory that indicate the first row of a loaded matrix. Another memory map of matrix memory may be defined to suit user needs. Be aware, however, that modelview matrices (see the <A href="../Transform/GXLoadPosMtxImm.html"><CODE>GXLoadPosMtxImm</CODE></A> and <A href="../Enumerated_Types/GXPosNrmMtx.html"><CODE>GXPosNrmMtx</CODE></A> functions) and texture matrices share matrix memory.</P> 124 125<H3>Generating Texture Coordinates by Transforming an Attribute</H3> 126<P>The simplest type (<CODE>GX_TG_MTX2x4</CODE> and <CODE>GX_TG_MTX3x4</CODE>) of texture-coordinate generation transforms an input attribute (either position, normal or texture coordinate) and assigns the result to an output-texture coordinate. <CODE>GX_TG_MTX2x4</CODE> performs a 2x4 matrix multiply on the input attribute and generates S and T texture coordinates. <code>GX_TG_MTX3x4</code> performs a 3x4 matrix multiplication on the input attribute, and generates S, T, and Q texture coordinates. S and T are then divided by Q to produce the actual 2D texture coordinates.</P> 127 128<H4>Examples</H4> 129<BLOCKQUOTE><CODE>// generate texture coord 0 (S/T/Q) from transform of position (x,y,z)<BR> GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX0);</CODE></BLOCKQUOTE> 130<BLOCKQUOTE><CODE>// generate tex coord 2 (S/T) from transform of position (x,y,z)<BR> GXSetTexCoordGen(GX_TEXCOORD2, GX_TG_MTX2x4, GX_TG_POS, GX_TEXMTX5);</CODE></BLOCKQUOTE> 131<BLOCKQUOTE><CODE>// generate tex coord 0 and tex coord 1 (S/T) from input coord 0<BR> GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);<BR> GXSetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);</CODE></BLOCKQUOTE> 132<BLOCKQUOTE><CODE>// generate tex coord 3 (S/T/Q) from transform of the normal<BR> GXSetTexCoordGen(GX_TEXCOORD3, GX_TG_MTX3x4, GX_TG_NRM, GX_TEXMTX2);</CODE></BLOCKQUOTE> 133<BLOCKQUOTE><CODE>// generate tex coord 0 (S/T) from translation/rotation of input coord 0<BR> GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_TEXMTX1);</CODE></BLOCKQUOTE> 134 135<H3>Generating Texture Coordinates from Vertex Lighting Results</H3> 136<P>This type of texture coordinate generation can be used to create <A href="../../gx/list.html#Lighting">cartoon lighting</A> effects. One of the color channel results is converted into texture coordinates.</P> 137 138<H4>GX_TG_SRTG</H4> 139<P>The S coordinate is set equal to the 8-bit R (red) component of the channel. The T coordinate is set equal to the 8-bit G (green) component of the color channel. For cartoon lighting, the S coordinate will represent the light intensity and is input to an arbitrary 1D texture look-up to convert intensity to color. The T coordinate is used to represent material color, and is used to select a 1D table from a 2D texture. Texture coordinates generated using <CODE>GX_TG_SRTG</CODE> should be generated after all other coordinates. (See the <A href="#Functional Ordering Requirements">Functional Ordering Requirements</A> section below.)</P> 140<P>The texture which represents the array of 1D intensity-to-color tables must be constructed carefully. Each table (row) should be duplicated. Since the S and T coordinates are generated from 8-bit colors, a maximum texture of 256 x 256 can be used. For this texture size, there are 127 tables available. This is equal to ((256-1)/2).</P> 141<P>The rule for generating the G channel color which will create a T coordinate centered properly in the two-row table is as follows.</P> 142<BLOCKQUOTE><CODE>n = 1-D intensity lookup table index (0-126 for a 256x256 texture)<BR> rows = number of rows in the texture, multiple of 2<BR> if ((2*n +1) < ((rows-1)/2)) <BR> green = 2*n + 1<BR> else<BR> green = 2*n</CODE></BLOCKQUOTE> 143 144<H4>Examples</H4> 145<BLOCKQUOTE><CODE>// convert color0 to s,t for 2-D texture lookup, matrix not used<BR> GXSetTexCoodGen(GX_TEXCOORD2, GX_TG_SRTG, GX_TG_COLOR0, GX_IDENTITY);</CODE></BLOCKQUOTE> 146 147<H3>Embossed-Style Bump-Mapping</H3> 148<P>This type (<CODE>GX_TG_BUMP0-7</CODE>) of bump-mapping perturbs input texture coordinates based on normal and light direction information. Use the original and offset texture coordinates to look up texels from the height field bump map. You can subtract these values in the TEV to find the bump height, and then add this value to the final color of the pixel. In bump map calculations, <CODE>GX_BUMP0</CODE> indicates that light 0 will be used, <CODE>GX_BUMP1</CODE> indicates that light 1 will be used, and so on.</P> 149<P>The <SPAN class="argument">src_param</SPAN> for bump maps is a texture coordinate whose number is smaller than the target texture coordinate. For example, source texture coordinate = <CODE>GX_TEXCOORD0</CODE>, and bump offset texture coordinate = <CODE>GX_TEXCOORD1</CODE>. Since the source texture is one of the transformed texture coordinates (<CODE>GX_TG_MTX2x4</CODE> or <CODE>GX_TG_MTX3x4</CODE>), you can't use a bump map texture coordinate as source for another bump map texture coordinate. Bump map texture coordinates should be generated after coordinates generated from transforms (<CODE>GX_TG_MTX2x4</CODE> and <CODE>GX_TG_MTX3x4</CODE>). For more details, see the <a href="#Functional Ordering Requirements">Functional Ordering Requirements</a> section below.</P> 150 151<H4>Examples</H4> 152<BLOCKQUOTE><CODE>// source for a bump mapped coordinate, transformed by a matrix<BR> GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_TEXMTX3);<BR> // perturbed coordinate, offset from TEXCOORD0 above,<BR> // light 0. Matrix is not used.<BR> GXSetTexCoordGen(GX_TEXCOORD1, GX_TG_BUMP0, GX_TG_TEXCOORD0, GX_IDENTITY);</CODE></BLOCKQUOTE> 153 154<H3><A name="Functional Ordering Requirements">Functional Ordering Requirements</A></H3> 155<P>Texture coordinates must be generated in functional order: All transforms are first (<CODE>GX_TG_MTX2x4</CODE> or <CODE>GX_TG_MTX3x4</CODE>), followed by bump maps (<CODE>GX_TG_BUMP0-3</CODE>), followed by texture coordinate generation from lighting (<CODE>GX_TG_SRTG</CODE>).</P> 156<P>Texture coordinates must be generated using sequential texture coordinate numbers starting at <CODE>GX_TEXCOORD0</CODE>.</P> 157<P>The number of bump map texture coordinates should be equal to or less than three.</P> 158<P>Texture coordinate generation from lighting (<CODE>GX_TG_SRTG</CODE>) is slightly complicated in its ordering restrictions:</P> 159<UL> 160<LI>Texture coordinates which use <CODE>GX_TG_COLOR0</CODE> must come first, followed by those with <CODE>GX_TG_COLOR1</CODE>. 161<LI>Texture coordinates using only <CODE>GX_TG_COLOR1</CODE> cannot be used by themselves. There must be coordinates included which use <CODE>GX_TG_COLOR0</CODE>. 162<LI>You can't use the same source (either for <CODE>GX_TG_COLOR0</CODE> or <CODE>GX_TG_COLOR1</CODE>) for more than one texture coordinate. 163</UL> 164 165<H3>Indexed Texture Matrices</H3> 166<P>When generating texture coordinates using <CODE>GX_MTX3x4</CODE> or <CODE>GX_MTX2x4</CODE>, you may pass the matrix index per vertex, rather than using <CODE>GXSetTexCoordGen</CODE>. This feature is most often used with skinned (stitching) models. When the matrix index is passed per vertex, the value specified in <CODE>GXSetTexCoordGen</CODE> is overwritten, as indicated by the <A href="../Geometry/GXSetVtxDesc.html">current vertex descriptor</A>. In other words, <CODE>GXSetTexCoordGen</CODE> sets a current matrix index that will be replaced by each per-vertex index.</P> 167 168<H2>See Also</H2> 169<P class="reference"> 170<A href="GXSetNumTexGens.html">GXSetNumTexGens</A>, 171<A href="GXSetTexCoordGen2.html">GXSetTexCoordGen2</A>, 172<A href="../Geometry/GXSetVtxDesc.html">GXSetVtxDesc</A>, 173<A href="../Tev/GXSetTevOrder.html">GXSetTevOrder</A> 174</P> 175 176<H2>Revision History</H2> 177<P> 1782008/05/23 Touched up the text.<br>2006/03/01 Initial version.<br> 179</P> 180 181<hr><p>CONFIDENTIAL</p></body> 182</HTML>