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>GXInitLightAttnK</TITLE>
9</HEAD>
10<BODY>
11<H1 align="left">GXInitLightAttnK</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 GXInitLightAttnK(
18    <A href="../Structures/GXLightObj.html">GXLightObj</A>* lt_obj,
19    f32         k0,
20    f32         k1,
21    f32         k2 );</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" bgcolor="#ffffe8"><EM><STRONG><CODE>lt_obj</CODE></STRONG></EM></TD>
28<TD width="520">pointer to a light object</TD>
29    </TR>
30    <TR>
31<TD width="120" bgcolor="#ffffe8"><EM><STRONG><CODE>k0</CODE></STRONG></EM></TD>
32<TD width="520">distance attenuation coefficient</TD>
33    </TR>
34    <TR>
35<TD width="120" bgcolor="#ffffe8"><EM><STRONG><CODE>k1</CODE></STRONG></EM></TD>
36<TD width="520">distance attenuation coefficient</TD>
37    </TR>
38    <TR>
39<TD width="120" bgcolor="#ffffe8"><EM><STRONG><CODE>k2</CODE></STRONG></EM></TD>
40<TD width="520">distance attenuation coefficient</TD>
41    </TR>
42  </TBODY>
43</TABLE>
44<H2>Return Values</H2>
45<P>None.</P>
46<H2>Description</H2>
47<P>This function sets coefficients used in the lighting attenuation calculation in a given light object.&nbsp;The application must allocate memory for the light object.&nbsp;The coefficients <CODE><EM><STRONG>k0</STRONG></EM></CODE>, <CODE><EM><STRONG>k1</STRONG></EM></CODE> and <CODE><EM><STRONG>k2</STRONG></EM></CODE> are used for distance attenuation.&nbsp;The attenuation function is:</P>
48<P><CITE><EM>atten = <U>clamp0(<STRONG> a2</STRONG> * cos(theta)^2 +</U></EM><U> <EM><STRONG>a1</STRONG></EM> * <EM>cos(theta) +</EM> <EM><STRONG>a0</STRONG></EM> )</U><BR> <EM><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k2</STRONG></EM> <EM>* d^2 +</EM> <EM><STRONG>k1</STRONG></EM> * <EM>d +</EM> <STRONG><EM>k0</EM></STRONG></CITE></P>
49<P>Here <CODE>cos(theta)</CODE> is the cosine of the angle between the normal vector of the light and the vector from the light's position to the vertex. <CODE>d</CODE> is the distance from the light position to the vertex. The coefficients <CODE><EM><STRONG>a0</STRONG></EM></CODE>, <CODE><EM><STRONG>a1</STRONG></EM></CODE> and <CODE><EM><STRONG>a2</STRONG></EM></CODE> can be set with <a href="GXInitLightAttnA.html"><code>GXInitLightAttnA</code></a>. Both the <CODE><EM><STRONG>a0</STRONG></EM></CODE>, <CODE><EM><STRONG>a1</STRONG></EM></CODE> and <CODE><EM><STRONG>a2</STRONG></EM></CODE> and the <CODE><EM><STRONG>k0</STRONG></EM></CODE>, <CODE><EM><STRONG>k1</STRONG></EM></CODE> and <CODE><EM><STRONG>k2</STRONG></EM></CODE> coefficients can be set simultaneously using the <a href="GXInitLightAttn.html"><code>GXInitLightAttn</code></a> function. The light color will be multiplied by the <em>atten</em> factor when the attenuation function for the color channel referencing this light is set to <code>GX_AF_SPOT</code> (see <a href="GXSetChanCtrl.html"><code>GXSetChanCtrl</code></a>).</P>
50<P>All coefficients are represented with a 20-bit floating point format (1-bit sign, 8-bit exponent, and 11-bit significand) in the hardware, as for other arguments associated with vertex lighting. Be aware of possible rounding errors as a result.</P>
51<P>Be aware that this function does not load any hardware registers directly.&nbsp;To load a light object into a hardware light, use <a href="GXLoadLightObjImm.html"><code>GXLoadLightObjImm</code></a> or <a href="GXLoadLightObjIndx.html"><code>GXLoadLightObjIndx</code></a>.</P>
52<P>The function <a href="GXInitLightSpot.html"><code>GXInitLightSpot</code></a> can conveniently be used to set the angle attenuation coefficients based on several spotlight types. The function <a href="GXInitLightDistAttn.html"><code>GXInitLightDistAtten</code></a> can be used to set the distance attenuation coefficients using one of the several common attenuation functions.</P>
53<H2>See Also</H2>
54<P><A href="GXInitLightAttn.html"><CODE>GXInitLightAttn</CODE></A><BR> <CODE><A href="GXInitLightAttnA.html">GXInitLightAttnA</A></CODE><BR> <CODE><A href="GXGetLightAttnK.html">GXGetLightAttnK</A></CODE><BR> <CODE><A href="GXSetChanCtrl.html">GXSetChanCtrl</A></CODE></P>
55<P><A href="GXLightObjInitFlow.html"><CODE>GXLightObj</CODE> Initialization Flow</A></P>
56<H2>Revision History</H2>
57<P>2006/03/01 Initial version.</P>
58<hr>
59<P>CONFIDENTIAL</p>
60</BODY>
61</HTML>