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<H2>C Specification</H2>
13<DL>
14  <DD>
15  <PRE><CODE>#include &lt;revolution/gx.h&gt;</CODE></PRE>
16  <DD>
17  <PRE><CODE>void 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> );</CODE></PRE>
22</DL>
23<H2>Arguments</H2>
24<TABLE border="1" cellpadding="3" cellspacing="0.1">
25  <TBODY>
26    <TR>
27<TD width="120" valign="top" bgcolor="#ffffe8"><EM><STRONG><CODE>dst_coord</CODE></STRONG></EM></TD>
28<TD width="520">the <A href="../Enumerated_Types/GXTexCoordID.html">name</A> of the texture coordinate to be generated <BR>Accepted values are: <code>GX_TEXCOORD0</code>, <code>GX_TEXCOORD1</code>, <code>GX_TEXCOORD2</code>, ..., <code>GX_TEXCOORD7</code>.</TD>
29    </TR>
30    <TR>
31<TD width="120" valign="top" bgcolor="#ffffe8"><EM><STRONG><CODE>func</CODE></STRONG></EM></TD>
32<TD width="520">the <A href="../Enumerated_Types/GXTexGenType.html">feature</A> used to generate texture coordinates <BR>Accepted values are:<BR>
33      <TABLE border="1" width="500" cellspacing="0.1">
34
35          <tr>
36<TD width="150" bgcolor="#C0C0C0">Name</TD>
37<TD width="350" bgcolor="#C0C0C0">Type of Texture Coordinate Generation</TD>
38          </tr>
39          <tr>
40<TD width="150"><code>GX_TG_MTX2x4</code></TD>
41<TD width="350">source attributes are converted into a 2x4 matrix</TD>
42          </tr>
43          <tr>
44<TD width="150"><code>GX_TG_MTX3x4</code></TD>
45<TD width="350">source attributes are converted into a 3x4 matrix</TD>
46          </tr>
47          <tr>
48<TD width="150"><code>GX_TG_BUMP0-7</code></TD>
49<TD width="350">embossed-style bump texture coordinates</TD>
50          </tr>
51          <tr>
52<TD width="150"><code>GX_TG_SRTG</code></TD>
53<TD width="350">R (red)/G (green) components from color channel output</TD>
54          </tr>
55
56      </TABLE>
57      </TD>
58    </TR>
59    <TR>
60<TD width="120" valign="top" bgcolor="#ffffe8"><EM><STRONG><CODE>src_param</CODE></STRONG></EM></TD>
61<TD width="520">the name of source attributes used to generate texture coordinates
62      <TABLE border="1" width="500" cellspacing="0.1">
63        <TBODY>
64          <TR>
65<TD width="150" bgcolor="#C0C0C0">Functions</TD>
66<TD width="350" bgcolor="#C0C0C0">Specifiable values for <CODE>src_param</CODE> are:</TD>
67          </TR>
68          <TR>
69<TD width="150"><CODE>GX_TG_MTX3x4<BR> GX_TG_MTX2x4</CODE></TD>
70<TD width="350"><CODE>GX_TG_POS (position coordinate)<BR> GX_TG_NRM (normal)<BR> GX_TG_BINRM (binormal) <BR> GX_TG_TANGENT (tangential)<BR> GX_TG_TEX0-7 (input texture coordinates)</CODE></TD>
71          </TR>
72          <TR>
73<TD width="150"><CODE>GX_TG_BUMP0-7</CODE></TD>
74<TD width="350"><CODE>GX_TG_TEXCOORD0-6</CODE></TD>
75          </TR>
76          <TR>
77<TD width="150"><CODE>GX_TG_SRTG</CODE></TD>
78<TD width="350"><CODE>GX_TG_COLOR0<BR> GX_TG_COLOR1</CODE></TD>
79          </TR>
80        </TBODY>
81      </TABLE>
82      </TD>
83    </TR>
84    <TR>
85<TD width="120" valign="top" bgcolor="#ffffe8"><EM><STRONG><CODE>mtx</CODE></STRONG></EM></TD>
86      <TD width="520">
87      <DIV align="left">
88      <TABLE border="1" width="500" cellspacing="0.1">
89        <TBODY>
90          <TR>
91<TD width="150" bgcolor="#C0C0C0">Functions</TD>
92<TD width="350" bgcolor="#C0C0C0">Specifiable values for <CODE>mtx</CODE> are:</TD>
93          </TR>
94          <TR>
95<TD width="150"><CODE>GX_TG_MTX2x4</CODE><BR><CODE>GX_TG_MTX3x4</CODE> </TD>
96<TD width="350"><CODE>GX_TEXMTX0-9, GX_IDENTITY</CODE></TD>
97          </TR>
98          <TR>
99<TD width="150"><CODE>GX_TG_BUMP0-7</CODE></TD>
100<TD width="350"><CODE>not used</CODE></TD>
101          </TR>
102          <TR>
103<TD width="150"><CODE>GX_TG_SRTG</CODE></TD>
104<TD width="350"><CODE>not used</CODE></TD>
105          </TR>
106        </TBODY>
107      </TABLE>
108      </DIV>
109      </TD>
110    </TR>
111  </TBODY>
112</TABLE>
113<H2>Return Values</H2>
114<P>None.</P>
115<H2>Description</H2>
116<P>This function is used to specify how texture coordinates are generated.&nbsp;Output texture coordinates are usually the result of some transform of an input attribute, either for position, normal, or texture coordinates.&nbsp;You can also generate texture coordinates from the output color channel for vertex lighting calculations.&nbsp;This function also supports the embossed style of bump-mapping.&nbsp;In C-language syntax the texture coordinate generation function would look like this:</P>
117<P><CODE><EM><STRONG>dst_coord = func(src_param, mtx);</STRONG></EM></CODE></P>
118<P>The current vertex descriptor as set by <a href="../Geometry/GXSetVtxDesc.html"><code>GXSetVtxDesc</code></a> only describes the data input to the graphics processor.&nbsp;Using <a href="GXSetTexCoordGen.html"><code>GXSetTexCoordGen</code></a>, you can create new output texture coordinates from the input data.&nbsp;The <code>dst_coord</code> argument is used to give the output texture coordinate a name.&nbsp;This texture coordinate can be bound to a texture using <a href="../Tev/GXSetTevOrder.html"><code>GXSetTevOrder</code></a>. The function <a href="GXSetNumTexGens.html"><code>GXSetNumTexGens</code></a> specifies a consecutive number of texture coordinates, starting at <code>GX_TEXCOORD0</code>, that are available to the <a href="../Tev/GXSetTevOrder.html"><code>GXSetTevOrder</code></a> function.&nbsp;</P>
119<P>Input texture coordinates must <strong>always</strong> go through the texture-coordinate generation hardware.&nbsp;<a href="../Management/GXInit.html"><code>GXInit</code></a> initializes the hardware (by calling this function) so that all texture coordinates are transformed by the <code>GX_IDENTITY</code> matrix in order to appear as if input coordinates are passed unchanged through to the texture hardware.</P>
120<P>There are eight output texture coordinates that can be referenced in any of the 16 Texture Environment (TEV) stages.&nbsp;There are a maximum of eight input texture coordinates.</P>
121<P>The <a href="../Enumerated_Types/GXTexMtx.html"><code>GXTexMtx</code></a> enumeration defines a default set of texture matrix names that can be supplied as <code>mtx</code>. 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.&nbsp;Another memory map of matrix memory may be defined to suit user needs.&nbsp;Be aware, however, that modelview (see <a href="../Transform/GXLoadPosMtxImm.html"><code>GXLoadPosMtxImm</code></a> and <a href="../Enumerated_Types/GXPosNrmMtx.html"><code>GXPosNrmMtx</code></a>) and texture matrices share matrix memory.</P>
122<H3>Generating Texture Coordinates by Transforming an Attribute</H3>
123<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.&nbsp;<code>GX_TG_MTX2x4</code> performs a 2x4 matrix multiply on the input attribute and generates <EM>S</EM> and <EM>T</EM> texture coordinates.&nbsp;<code>GX_TG_MTX3x4</code> performs a 3x4 matrix multiply on the input attribute and generates <EM>S</EM>, <EM>T</EM>, and <EM>Q</EM> coordinates.&nbsp;<EM>S</EM> and <EM>T</EM> are then divided by <EM>Q</EM> to produce the actual 2D texture coordinates.</P>
124<H4>Example</H4>
125<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>
126<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>
127<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>
128<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>
129<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>
130<H3>Generating Texture Coordinates from Vertex Lighting Results</H3>
131<P>This type of texture coordinate generation can be used to create <A href="../../gx/list.html#Lighting">cartoon lighting</A> effects.&nbsp;One of the color channel results is converted into texture coordinates.</P>
132<H4>GX_TG_SRTG</H4>
133<P>The <EM>S</EM> coordinate is set equal to the 8-bit R (red) component of the channel.&nbsp;The <EM>T</EM> coordinate is set equal to the 8-bit G (green) component of the color channel.&nbsp;For cartoon lighting, the <EM>S</EM> coordinate will represent the light intensity and is input to an arbitrary 1D texture look-up to convert intensity to color.&nbsp;The <EM>T</EM> coordinate is used to represent material color, and is used to select a 1D table from a 2D texture. Texture coordinates generated using the <code>GX_TG_SRTG</code> function should be generated after any coordinates. (See the <a href="#Functional Ordering Requirements">Functional Ordering Requirements</a> section below.)</P>
134<P>The texture which represents the array of 1D intensity-to-color tables must be constructed carefully.&nbsp;Each table (row) should be duplicated.&nbsp;Since the <EM>S</EM> and <EM>T</EM> 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>
135<P>The rule for generating the G channel color which will create a <EM>T</EM> coordinate centered properly in the two-row table is:</P>
136<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) &lt; ((rows-1)/2)) <BR> &nbsp;&nbsp;&nbsp; green = 2*n + 1<BR> else<BR> &nbsp;&nbsp;&nbsp; green = 2*n</CODE></BLOCKQUOTE>
137<H4>Example</H4>
138<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>
139<H3>Embossed-style Bump-mapping</H3>
140<P>This type (<code>GX_TG_BUMP0-7</code>) of bump-mapping perturbs input texture coordinates based on normal and light direction information.&nbsp;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.&nbsp;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, etc.</P>
141<P>The <code>src_param</code> 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 coordinate should be 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>
142<H4>Example</H4>
143<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>
144<H3><A name="Functional Ordering Requirements">Functional Ordering Requirements</A></H3>
145<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-7</code>), followed by texture coordinate generation from lighting (<code>GX_TG_SRTG</code>).</P>
146<P>Texture coordinates must be generated using sequential texture coordinate numbers starting at <code>GX_TEXCOORD0</code>.</P>
147<P>The number of bump map texture coordinates should be equal to or less than three.</P>
148<P>Texture coordinate generation from lighting (<code>GX_TG_SRTG</code>) is slightly complicated in its ordering restrictions:</P>
149<UL>
150<LI>Texture coordinates which use <code>GX_TG_COLOR0</code> should come first, followed by those with <code>GX_TG_COLOR1</code>.
151<LI>Texture coordinates using only <code>GX_TG_COLOR1</code> cannot be used. Coordinates using <code>GX_TG_COLOR0</code> should be included.
152<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.
153</UL>
154<H3>Indexed Texture Matrices</H3>
155<P>When generating texture coordinates using <code>GX_MTX3x4</code> or <code>GX_MTX2x4</code>, you may provide the matrix index per vertex, rather than using <code>GXSetTexCoordGen</code>. This feature is most often used with skinned (stitching) models.&nbsp;When the matrix index is provided per vertex, as indicated by the <a href="../Geometry/GXSetVtxDesc.html">current vertex descriptor</a>, the value specified by <code>GXSetTexCoordGen</code> is overwritten. In other words, <code>GXSetTexCoordGen</code> sets a current matrix index that will be replaced by the per-vertex index.</P>
156<H2>See Also</H2>
157<P><A href="GXSetNumTexGens.html"><CODE>GXSetNumTexGens</CODE></A><BR> <A href="GXSetTexCoordGen2.html"><CODE>GXSetTexCoordGen2</CODE></A><BR> <A href="../Geometry/GXSetVtxDesc.html"><CODE>GXSetVtxDesc</CODE></A><BR> <A href="../Tev/GXSetTevOrder.html"><CODE>GXSetTevOrder</CODE></A></P>
158<H2>Revision History</H2>
159<P>2006/03/01 Initial version.</P>
160<hr>
161<P>CONFIDENTIAL</p>
162</BODY>
163</HTML>