diff options
author | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
commit | 0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch) | |
tree | 2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /docs/doxygen/nel/zone__lighter_8cpp-source.html | |
download | nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip |
Initial commit
Diffstat (limited to '')
-rw-r--r-- | docs/doxygen/nel/zone__lighter_8cpp-source.html | 3428 |
1 files changed, 3428 insertions, 0 deletions
diff --git a/docs/doxygen/nel/zone__lighter_8cpp-source.html b/docs/doxygen/nel/zone__lighter_8cpp-source.html new file mode 100644 index 00000000..bded90d6 --- /dev/null +++ b/docs/doxygen/nel/zone__lighter_8cpp-source.html @@ -0,0 +1,3428 @@ +<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> +<HTML> +<HEAD> + <TITLE>nevrax.org : docs</TITLE> + <LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css"> + <link href="doxygen.css" rel="stylesheet" type="text/css"> +</HEAD> +<BODY MARGINHEIGHT="0" MARGINWIDTH="0"> + +<!-- uplinks --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD> + </TR> +</TABLE> + +<!-- banner Nevrax --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%> + <TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR> +</TABLE> + +<!-- main table --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + + <!------ Begin Box ------> + <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black> + <FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF> + <TABLE cellspacing=0 cellpadding=1 border=0> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr> + </TABLE> + </TD></TR></TABLE></TD></TR></TABLE> + <!------ End Box ------> + + </TD> + <TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + +<!-- title --> +<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td> +<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A> +</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT=""> +</td></tr></table> + + +<!-- block --> +<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD> + <TD><B>Documentation</B></TD> + <TD ALIGN=RIGHT> </td> +</tr></table> +<!-- Generated by Doxygen 1.2.14 --> +<center> +<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center> +<hr><h1>zone_lighter.cpp</h1><a href="zone__lighter_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00007 <font class="comment">/* Copyright, 2000 Nevrax Ltd.</font> +00008 <font class="comment"> *</font> +00009 <font class="comment"> * This file is part of NEVRAX NEL.</font> +00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font> +00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> +00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font> +00013 <font class="comment"> * any later version.</font> +00014 <font class="comment"></font> +00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font> +00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> +00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> +00018 <font class="comment"> * General Public License for more details.</font> +00019 <font class="comment"></font> +00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font> +00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font> +00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font> +00023 <font class="comment"> * MA 02111-1307, USA.</font> +00024 <font class="comment"> */</font> +00025 +00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font> +00027 +00028 <font class="preprocessor">#include "<a class="code" href="zone__lighter_8h.html">3d/zone_lighter.h</a>"</font> +00029 <font class="preprocessor">#include "<a class="code" href="landscape_8h.html">3d/landscape.h</a>"</font> +00030 <font class="preprocessor">#include "<a class="code" href="patchuv__locator_8h.html">3d/patchuv_locator.h</a>"</font> +00031 <font class="preprocessor">#include "<a class="code" href="shape_8h.html">3d/shape.h</a>"</font> +00032 <font class="preprocessor">#include "<a class="code" href="mesh_8h.html">3d/mesh.h</a>"</font> +00033 <font class="preprocessor">#include "<a class="code" href="mesh__multi__lod_8h.html">3d/mesh_multi_lod.h</a>"</font> +00034 <font class="preprocessor">#include "<a class="code" href="mesh__mrm_8h.html">3d/mesh_mrm.h</a>"</font> +00035 <font class="preprocessor">#include "<a class="code" href="transform__shape_8h.html">3d/transform_shape.h</a>"</font> +00036 <font class="preprocessor">#include "<a class="code" href="water__shape_8h.html">3d/water_shape.h</a>"</font> +00037 <font class="preprocessor">#include "<a class="code" href="texture__file_8h.html">3d/texture_file.h</a>"</font> +00038 +00039 +00040 +00041 +00042 +00043 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font> +00044 <font class="preprocessor">#include "<a class="code" href="thread_8h.html">nel/misc/thread.h</a>"</font> +00045 <font class="preprocessor">#include "<a class="code" href="path_8h.html">nel/misc/path.h</a>"</font> +00046 <font class="preprocessor">#include "<a class="code" href="file_8h.html">nel/misc/file.h</a>"</font> +00047 <font class="preprocessor">#include "<a class="code" href="aabbox_8h.html">nel/misc/aabbox.h</a>"</font> +00048 +00049 +00050 <font class="comment">// Define this to use hardware soft shadows</font> +00051 <font class="comment">//#define HARDWARE_SOFT_SHADOWS</font> +00052 +00053 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font> +00054 <font class="preprocessor"></font> +00055 <font class="preprocessor">#include "<a class="code" href="u__driver_8h.html">nel/3d/u_driver.h</a>"</font> +00056 +00057 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font> +00058 <font class="preprocessor"></font> +00059 +00060 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font> +00061 <font class="preprocessor"></font><font class="preprocessor"># define WIN32_LEAN_AND_MEAN</font> +00062 <font class="preprocessor"></font><font class="preprocessor"># include "windows.h"</font> +00063 <font class="preprocessor"># include "winbase.h"</font> +00064 <font class="preprocessor"># ifdef min</font> +00065 <font class="preprocessor"></font><font class="preprocessor"># undef min</font> +00066 <font class="preprocessor"></font><font class="preprocessor"># endif</font> +00067 <font class="preprocessor"></font><font class="preprocessor"># ifdef max</font> +00068 <font class="preprocessor"></font><font class="preprocessor"># undef max</font> +00069 <font class="preprocessor"></font><font class="preprocessor"># endif</font> +00070 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font> +00071 <font class="preprocessor"></font> +00072 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC; +00073 <font class="keyword">using</font> <font class="keyword">namespace </font>NL3D; +00074 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00075 +00076 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font> +00077 <font class="preprocessor"></font> +00078 UDriver *drv=NULL; +00079 +00080 <font class="preprocessor">#define LIGHT_BUFFER_SIZE 16</font> +00081 <font class="preprocessor"></font> +00082 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font> +00083 <font class="preprocessor"></font> +00084 +00085 <font class="comment">// Bad coded: don't set too big else it allocates too much memory.</font> +<a name="l00086"></a><a class="code" href="zone__lighter_8cpp.html#a0">00086</a> <font class="preprocessor">#define NL3D_ZONE_LIGHTER_CUBE_GRID_SIZE 16</font> +00087 <font class="preprocessor"></font> +00088 +00089 <font class="comment">// ***************************************************************************</font> +00090 +00091 +<a name="l00092"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a0">00092</a> CZoneLighter::CZoneLighter () : _PatchComputed ("PatchComputed"), _TriangleListAllocateur(100000) +00093 { +00094 +00095 } +00096 +00097 <font class="comment">// ***************************************************************************</font> +00098 +<a name="l00099"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a2">00099</a> <font class="keywordtype">void</font> CZoneLighter::init () +00100 { +00101 <font class="comment">// Precalc some values</font> +00102 <font class="keywordflow">for</font> (uint i=0; i<8; i++) +00103 { +00104 <font class="comment">// Precalc sinP and cosP</font> +00105 <font class="keywordtype">float</font> sinP=(float)(sin((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*(i+0.5))-sin((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*(i-0.5))); +00106 <font class="keywordtype">float</font> cosP=(float)(cos((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*(i-0.5))-cos((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*(i+0.5))); +00107 +00108 <font class="keywordflow">for</font> (uint phi=0; phi<256; phi++) +00109 { +00110 <font class="comment">// Real phi</font> +00111 <font class="keywordtype">float</font> fPhi=(float)((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2)*phi/256.0); +00112 +00113 <font class="comment">// Tmp result</font> +00114 <font class="keywordtype">float</font> tmp0=(float)(fPhi-sin(2*fPhi)/2); +00115 <font class="keywordtype">float</font> tmp1=(float)sin(fPhi); +00116 +00117 <font class="comment">// Calc K</font> +00118 <a class="code" href="classNL3D_1_1CZoneLighter.html#o37">_K</a>[phi][i].<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a> (tmp0*sinP, tmp0*cosP, (<font class="keywordtype">float</font>)((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*tmp1*tmp1)); +00119 } +00120 } +00121 +00122 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font> +00123 <font class="preprocessor"></font> <font class="keywordflow">if</font> (!drv) +00124 { +00125 <font class="comment">// Mode</font> +00126 UDriver::CMode mode (LIGHT_BUFFER_SIZE, LIGHT_BUFFER_SIZE, 32, <font class="keyword">true</font>); +00127 drv=UDriver::createDriver (); +00128 drv->setDisplay (mode); +00129 drv->setMatrixMode2D11 (); +00130 } +00131 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font> +00132 <font class="preprocessor"></font>} +00133 +00134 <font class="comment">// ***************************************************************************</font> +00135 +00136 <font class="comment">// N - NW - W - SW - S - SE - E - NE</font> +<a name="l00137"></a><a class="code" href="zone__lighter_8cpp.html#a5">00137</a> <font class="keyword">static</font> <font class="keyword">const</font> sint <a class="code" href="zone__lighter_8cpp.html#a5">deltaDirection</a>[8][2]= +00138 { +00139 {1, 0}, +00140 {1, 1}, +00141 {0, 1}, +00142 {-1, 1}, +00143 {-1, 0}, +00144 {-1, -1}, +00145 {0, -1}, +00146 {1, -1}, +00147 }; +00148 +00149 <font class="comment">// ***************************************************************************</font> +00150 +<a name="l00151"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c6">00151</a> <font class="keywordtype">float</font> CZoneLighter::calcSkyContribution (sint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, sint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, <font class="keywordtype">float</font> skyIntensity, <font class="keyword">const</font> CVector& normal)<font class="keyword"> const</font> +00152 <font class="keyword"></font>{ +00153 <font class="comment">// Sky contribution</font> +00154 <font class="keywordtype">float</font> skyContribution; +00155 +00156 <font class="comment">// Calc k</font> +00157 CVector k (0, 0, 0); +00158 +00159 <font class="comment">// For the height direction</font> +00160 <font class="keywordflow">for</font> (uint i=0; i<8; i++) +00161 { +00162 <font class="comment">// Get phi for this point</font> +00163 uint8 phi=<a class="code" href="classNL3D_1_1CZoneLighter.html#c8">getMaxPhi</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, <a class="code" href="zone__lighter_8cpp.html#a5">deltaDirection</a>[i][0], <a class="code" href="zone__lighter_8cpp.html#a5">deltaDirection</a>[i][1], <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>); +00164 +00165 <font class="comment">// Add to k</font> +00166 k+=<a class="code" href="classNL3D_1_1CZoneLighter.html#o37">_K</a>[phi][i]; +00167 } +00168 +00169 <font class="comment">// Finalize sky contribution</font> +00170 skyContribution=(float)(skyIntensity*(normal*k)/(2*<a class="code" href="namespaceNLMISC.html#a7">Pi</a>)); +00171 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (skyContribution, 0.f, 1.f); +00172 <font class="keywordflow">return</font> skyContribution; +00173 } +00174 +00175 <font class="comment">// ***************************************************************************</font> +00176 +<a name="l00177"></a><a class="code" href="zone__lighter_8cpp.html#a7">00177</a> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a369">NEL3DCalcBase</a> (CVector &direction, CMatrix& <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>) +00178 { +00179 direction.normalize(); +00180 CVector I=(fabs(direction*CVector(1.f,0,0))>0.99)?CVector(0.f,1.f,0.f):CVector(1.f,0.f,0.f); +00181 CVector K=-direction; +00182 CVector J=K^I; +00183 J.normalize(); +00184 I=J^K; +00185 I.normalize(); +00186 <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>.identity(); +00187 <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>.setRot(I,J,K, <font class="keyword">true</font>); +00188 } +00189 +00190 <font class="comment">// ***************************************************************************</font> +00191 +<a name="l00192"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html">00192</a> <font class="keyword">class </font>NL3D::CCalcRunnable : <font class="keyword">public</font> IRunnable +00193 { +00194 <font class="comment">// Members</font> +<a name="l00195"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#o0">00195</a> uint _Process; +<a name="l00196"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#o1">00196</a> CZoneLighter *_ZoneLighter; +<a name="l00197"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#o2">00197</a> <font class="keyword">const</font> CZoneLighter::CLightDesc *_Description; +00198 +00199 <font class="keyword">public</font>: +<a name="l00200"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#m0">00200</a> IThread *Thread; +00201 +00202 <font class="keyword">public</font>: +00203 <font class="comment">// Ctor</font> +<a name="l00204"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#a0">00204</a> CCalcRunnable (uint process, CZoneLighter *zoneLighter, <font class="keyword">const</font> CZoneLighter::CLightDesc *description) +00205 { +00206 _ZoneLighter = zoneLighter; +00207 _Process = process; +00208 _Description = description; +00209 } +00210 +00211 <font class="comment">// Run method</font> +<a name="l00212"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#a1">00212</a> <font class="keywordtype">void</font> run() +00213 { +00214 <font class="comment">// Set the processor mask</font> +00215 uint64 mask = IProcess::getCurrentProcess()->getCPUMask (); +00216 +00217 <font class="comment">// Mask must not be NULL</font> +00218 <a class="code" href="debug_8h.html#a6">nlassert</a> (mask != 0); +00219 +00220 <font class="keywordflow">if</font> (mask != 0) +00221 { +00222 uint i=0; +00223 uint count = 0; +00224 <font class="keywordflow">while</font> (1) +00225 { +00226 <font class="keywordflow">if</font> (mask & (1<<i)) +00227 { +00228 <font class="keywordflow">if</font> (count == _Process) +00229 <font class="keywordflow">break</font>; +00230 count++; +00231 } +00232 i++; +00233 <font class="keywordflow">if</font> (i==64) +00234 i = 0; +00235 } +00236 +00237 <font class="comment">// Set the CPU mask</font> +00238 Thread->setCPUMask (1<<i); +00239 } +00240 +00241 _ZoneLighter->processCalc (_Process, *_Description); +00242 _ZoneLighter->_ProcessExited++; +00243 } +00244 }; +00245 +00246 +00247 <font class="comment">// ***************************************************************************</font> +<a name="l00248"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html">00248</a> <font class="keyword">class </font>NL3D::CCalcLightableShapeRunnable : <font class="keyword">public</font> IRunnable +00249 { +00250 <font class="keyword">public</font>: +<a name="l00251"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#a0">00251</a> CCalcLightableShapeRunnable(uint process, +00252 CZoneLighter *zoneLighter, +00253 <font class="keyword">const</font> CZoneLighter::CLightDesc *description, +00254 CZoneLighter::TShapeVect *shapeToLit, +00255 uint firstShape, +00256 uint lastShape +00257 ) +00258 : +00259 _ZoneLighter(zoneLighter), +00260 _Description(description), +00261 _ShapesToLit(shapeToLit), +00262 _FirstShape(firstShape), +00263 _LastShape(lastShape), +00264 _Process(process) +00265 { +00266 } +<a name="l00267"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#a1">00267</a> <font class="keywordtype">void</font> run() +00268 { +00269 _ZoneLighter->processLightableShapeCalc(_Process, _ShapesToLit, _FirstShape, _LastShape, *_Description); +00270 _ZoneLighter->_ProcessExited++; +00271 } +00272 <font class="keyword">private</font>: +<a name="l00273"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o0">00273</a> CZoneLighter *_ZoneLighter; +<a name="l00274"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o1">00274</a> <font class="keyword">const</font> CZoneLighter::CLightDesc *_Description; +<a name="l00275"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o2">00275</a> CZoneLighter::TShapeVect *_ShapesToLit; +<a name="l00276"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o4">00276</a> uint _FirstShape, _LastShape; +<a name="l00277"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o5">00277</a> uint _Process; +00278 +00279 }; +00280 +00281 <font class="comment">// ***************************************************************************</font> +00282 +<a name="l00283"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a3">00283</a> <font class="keywordtype">void</font> CZoneLighter::light (CLandscape &landscape, CZone& output, uint zoneToLight, <font class="keyword">const</font> CLightDesc& description, std::vector<CTriangle>& obstacles, vector<uint> &listZone) +00284 { +00285 <font class="comment">/*</font> +00286 <font class="comment"> * Lighting algorithm</font> +00287 <font class="comment"> * ------------------</font> +00288 <font class="comment"> *</font> +00289 <font class="comment"> * - Create a quad grid to store shadow casting triangles</font> +00290 <font class="comment"> * - Create a heightfield used for global illumination. Cells are initialized with -FLT_MAX</font> +00291 <font class="comment"> * - Insert each shadow casting triangles in the quad grid and fill the heightfield's cells overlapped by the bounding box of the triangle with</font> +00292 <font class="comment"> * the max height of the triangle if its height is > than the current height in the heightfield's cell.</font> +00293 <font class="comment"> * - </font> +00294 <font class="comment"> */</font> +00295 +00296 <font class="comment">// Backup thread mask</font> +00297 IThread *currentThread = IThread::getCurrentThread (); +00298 uint64 threadMask = currentThread->getCPUMask(); +00299 currentThread->setCPUMask (1); +00300 +00301 <font class="comment">// Calc the ray basis</font> +00302 <a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>=description.LightDirection; +00303 <a class="code" href="zone__lighter_8cpp.html#a7">NEL3DCalcBase</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>, <a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>); +00304 +00305 <font class="comment">// Zone to light</font> +00306 <a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>=zoneToLight; +00307 +00308 <font class="comment">// Landscape </font> +00309 <a class="code" href="classNL3D_1_1CZoneLighter.html#o5">_Landscape</a>=&landscape; +00310 +00311 <font class="comment">// Process count</font> +00312 <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>=description.NumCPU; +00313 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>==0) +00314 { +00315 <font class="comment">// Create a doomy thread</font> +00316 IProcess *pProcess=IProcess::getCurrentProcess (); +00317 <a class="code" href="classNL3D_1_1CZoneLighter.html#o13">_CPUMask</a> = pProcess->getCPUMask(); +00318 <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a> = 0; +00319 uint64 i; +00320 <font class="keywordflow">for</font> (i=0; i<64; i++) +00321 { +00322 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o13">_CPUMask</a>&((uint64)1<<i)) +00323 <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>++; +00324 } +00325 } +00326 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>><a class="code" href="zone__lighter_8h.html#a2">MAX_CPU_PROCESS</a>) +00327 <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>=<a class="code" href="zone__lighter_8h.html#a2">MAX_CPU_PROCESS</a>; +00328 +00329 <font class="comment">// Number of CPUS used</font> +00330 printf (<font class="stringliteral">"Number of CPU used: %d\n"</font>, <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>); +00331 +00332 <font class="comment">// Fallof distance</font> +00333 <a class="code" href="classNL3D_1_1CZoneLighter.html#o18">_FallofDistance</a>=description.SoftshadowFallof; +00334 +00335 <font class="comment">// Shadow bias</font> +00336 <a class="code" href="classNL3D_1_1CZoneLighter.html#o6">_ShadowBias</a>=description.ShadowBias; +00337 +00338 <font class="comment">// Resize the shape array</font> +00339 <a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>=description.SoftshadowShapeVertexCount; +00340 +00341 <font class="comment">// Softshadow ?</font> +00342 <a class="code" href="classNL3D_1_1CZoneLighter.html#o7">_Softshadow</a>=description.Softshadow; +00343 +00344 <font class="comment">// Radius of the shape</font> +00345 <a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>=description.SoftshadowBlurSize; +00346 <a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>.<a class="code" href="classNLMISC_1_1CMatrix.html#z291_7">getI</a>(); +00347 <a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>+=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>.<a class="code" href="classNLMISC_1_1CMatrix.html#z291_8">getJ</a>(); +00348 <a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>.<a class="code" href="classNLMISC_1_1CVector.html#z331_4">normalize</a>(); +00349 <a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>*=1.5f*<a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>; +00350 +00351 <font class="comment">// Build the shape</font> +00352 uint i; +00353 <font class="keywordflow">for</font> (i=0; i<<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>; i++) +00354 { +00355 <font class="comment">// Shape is a smapled circle</font> +00356 <font class="keywordtype">float</font> angle=(float)((float)i*2*<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>); +00357 <a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m1">Vertices</a>[i]=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>*CVector (<a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>*(<font class="keywordtype">float</font>)cos (angle), <a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>*(<font class="keywordtype">float</font>)sin (angle), 0); +00358 } +00359 +00360 <font class="comment">// Calculate the area of the shape</font> +00361 <a class="code" href="classNL3D_1_1CZoneLighter.html#o16">_ShapeArea</a>=0; +00362 <font class="keywordflow">for</font> (i=0; i<<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>; i++) +00363 { +00364 <font class="comment">// Sum area of each triangle</font> +00365 <a class="code" href="classNL3D_1_1CZoneLighter.html#o16">_ShapeArea</a>+=(<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m1">Vertices</a>[i]^<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m1">Vertices</a>[(i+1)%<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>]).norm(); +00366 } +00367 +00368 <font class="comment">// Zone pointer</font> +00369 CZone *pZone=landscape.getZone (<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>); +00370 <font class="keywordflow">if</font> (pZone) +00371 { +00372 <font class="comment">// Change the quadGrid basis</font> +00373 CMatrix invRayBasis=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>; +00374 invRayBasis.<a class="code" href="classNLMISC_1_1CMatrix.html#z293_6">invert</a> (); +00375 +00376 uint cpu; +00377 <font class="keywordflow">for</font> (cpu=0; cpu<<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>; cpu++) +00378 { +00379 <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].changeBase (invRayBasis); +00380 +00381 <font class="comment">// Init the quadGrid</font> +00382 <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].create (description.GridSize, description.GridCellSize); +00383 } +00384 +00385 <font class="comment">// Init the heightfield</font> +00386 <a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>=description.HeightfieldCellSize; +00387 <a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>=(sint)(description.HeightfieldSize/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>); +00388 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>!=0); +00389 <font class="keyword">const</font> CAABBoxExt &zoneBB=pZone->getZoneBB(); +00390 <a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>=zoneBB.getCenter ()-CVector (description.HeightfieldSize/2, description.HeightfieldSize/2, 0); +00391 <a class="code" href="classNL3D_1_1CZoneLighter.html#o19">_HeightField</a>.resize (<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>*<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>, -FLT_MAX); +00392 +00393 <font class="comment">// Fill the quadGrid and the heightField</font> +00394 uint size=obstacles.size(); +00395 <font class="keywordflow">for</font> (uint triangleId=0; triangleId<size; triangleId++) +00396 { +00397 <font class="comment">// Progress bar</font> +00398 <font class="keywordflow">if</font> ( (triangleId&0xff) == 0) +00399 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Build quadtree and heightfield"</font>, (<font class="keywordtype">float</font>)triangleId/(<font class="keywordtype">float</font>)size); +00400 +00401 <font class="comment">// Triangle ref</font> +00402 CZoneLighter::CTriangle& triangle=obstacles[triangleId]; +00403 +00404 <font class="comment">// Calc the plane</font> +00405 triangle.Plane.make (triangle.Triangle.V0, triangle.Triangle.V1, triangle.Triangle.V2); +00406 +00407 <font class="comment">// Calc the clipping plane</font> +00408 CVector edgeDirection[3]; +00409 CVector point[3]; +00410 point[0]=triangle.Triangle.V0; +00411 edgeDirection[0]=triangle.Triangle.V1-triangle.Triangle.V0; +00412 point[1]=triangle.Triangle.V1; +00413 edgeDirection[1]=triangle.Triangle.V2-triangle.Triangle.V1; +00414 point[2]=triangle.Triangle.V2; +00415 edgeDirection[2]=triangle.Triangle.V0-triangle.Triangle.V2; +00416 +00417 <font class="comment">// Flip plane ?</font> +00418 <font class="keywordtype">bool</font> flip=((triangle.Plane.getNormal()*(-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>))<0); +00419 +00420 <font class="comment">// For each plane</font> +00421 <font class="keywordflow">for</font> (uint edge=0; edge<3; edge++) +00422 { +00423 <font class="comment">// Plane normal</font> +00424 edgeDirection[edge]=edgeDirection[edge]^(-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>); +00425 edgeDirection[edge].normalize(); +00426 <font class="keywordflow">if</font> (flip) +00427 edgeDirection[edge]=-edgeDirection[edge]; +00428 +00429 <font class="comment">// Make a plane</font> +00430 triangle.ClippingPlanes[edge].make (edgeDirection[edge], point[edge]); +00431 } +00432 +00433 <font class="comment">// Look for the min coordinate, in the RayBasis</font> +00434 CVector irbMinv; +00435 CVector irbV0= invRayBasis * triangle.Triangle.V0; +00436 CVector irbV1= invRayBasis * triangle.Triangle.V1; +00437 CVector irbV2= invRayBasis * triangle.Triangle.V2; +00438 irbMinv.minof (irbV0, irbV1); +00439 irbMinv.minof (irbMinv, irbV2); +00440 +00441 <font class="comment">// Look for the max coordinate, in the RayBasis</font> +00442 CVector irbMaxv; +00443 irbMaxv.maxof (irbV0, irbV1); +00444 irbMaxv.maxof (irbMaxv, irbV2); +00445 +00446 <font class="comment">// Insert in the quad grid</font> +00447 <font class="keywordflow">for</font> (cpu=0; cpu<<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>; cpu++) +00448 <font class="comment">// Set the coord in World Basis.</font> +00449 <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].insert (<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a> * irbMinv, <a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a> * irbMaxv, &triangle); +00450 +00451 +00452 <font class="comment">// Look for the min coordinate, in World Basis</font> +00453 CVector minv; +00454 minv.minof (triangle.Triangle.V0, triangle.Triangle.V1); +00455 minv.minof (minv, triangle.Triangle.V2); +00456 +00457 <font class="comment">// Look for the max coordinate, in World Basis</font> +00458 CVector maxv; +00459 maxv.maxof (triangle.Triangle.V0, triangle.Triangle.V1); +00460 maxv.maxof (maxv, triangle.Triangle.V2); +00461 +00462 +00463 <font class="comment">// Lanscape tri ?</font> +00464 <font class="keywordflow">if</font> (triangle.ZoneId!=0xffffffff) +00465 { +00466 <font class="comment">// Fill the heightfield</font> +00467 sint minX=std::max (0, (sint)floor (0.5f+(minv.x-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>)); +00468 sint maxX=<a class="code" href="bit__set_8cpp.html#a0">std::min</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>, (sint)floor (0.5f+(maxv.x-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>)); +00469 sint minY=std::max (0, (sint)floor (0.5f+(minv.y-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>)); +00470 sint maxY=<a class="code" href="bit__set_8cpp.html#a0">std::min</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>, (sint)floor (0.5f+(maxv.y-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>)); +00471 +00472 <font class="comment">// Calc position in the heightfield</font> +00473 <font class="keywordflow">for</font> (sint <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=minY; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a><maxY; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++) +00474 <font class="keywordflow">for</font> (sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=minX; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a><maxX; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++) +00475 { +00476 <font class="comment">// Valid position, try to insert it</font> +00477 <font class="keywordflow">if</font> (maxv.z><a class="code" href="classNL3D_1_1CZoneLighter.html#o19">_HeightField</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>]) +00478 { +00479 <font class="comment">// New height in this cell</font> +00480 <a class="code" href="classNL3D_1_1CZoneLighter.html#o19">_HeightField</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>]=maxv.z; +00481 } +00482 } +00483 } +00484 } +00485 +00486 <font class="comment">// Retrieve the zone to fill its shaded value</font> +00487 pZone->retrieve (<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>, <a class="code" href="classNL3D_1_1CZoneLighter.html#o24">_BorderVertices</a>); +00488 +00489 <font class="comment">// Number of patch</font> +00490 uint patchCount=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size(); +00491 +00492 <font class="comment">// Bit array to know if the lumel is shadowed</font> +00493 <font class="keywordflow">if</font> (description.Shadow) +00494 <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>.resize (patchCount); +00495 +00496 <font class="comment">// A lumel vector by patch</font> +00497 vector<vector<CLumelDescriptor> > lumels; +00498 lumels.resize (patchCount); +00499 +00500 <font class="comment">// Build zone informations</font> +00501 <a class="code" href="classNL3D_1_1CZoneLighter.html#c3">buildZoneInformation</a> (landscape, +00502 listZone, +00503 description.Oversampling!=CLightDesc::NoOverSampling, +00504 description); +00505 +00506 } +00507 +00508 <font class="comment">// Number of patch</font> +00509 uint patchCount=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size(); +00510 +00511 <font class="comment">// Reset patch count</font> +00512 { +00513 CSynchronized<std::vector<bool> >::CAccessor access (&<a class="code" href="classNL3D_1_1CZoneLighter.html#o9">_PatchComputed</a>); +00514 access.value().resize (0); +00515 access.value().resize (patchCount, <font class="keyword">false</font>); +00516 } +00517 +00518 <font class="comment">// Patch by thread</font> +00519 uint patchCountByThread = patchCount/<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>; +00520 patchCountByThread++; +00521 +00522 <font class="comment">// Patch to allocate</font> +00523 uint firstPatch=0; +00524 <a class="code" href="classNL3D_1_1CZoneLighter.html#o11">_NumberOfPatchComputed</a> = 0; +00525 +00526 <a class="code" href="classNL3D_1_1CZoneLighter.html#o14">_ProcessExited</a>=0; +00527 +00528 <font class="comment">// Set the thread state</font> +00529 <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>.resize (<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>); +00530 +00531 <font class="comment">// Launch threads</font> +00532 <font class="keywordflow">for</font> (uint process=1; process<<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>; process++) +00533 { +00534 <font class="comment">// Last patch</font> +00535 uint lastPatch=firstPatch+patchCountByThread; +00536 <font class="keywordflow">if</font> (lastPatch>patchCount) +00537 lastPatch=patchCount; +00538 +00539 <font class="comment">// Last patch computed</font> +00540 <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>[process] = firstPatch; +00541 +00542 <font class="comment">// Create a thread</font> +00543 CCalcRunnable *runnable = <font class="keyword">new</font> CCalcRunnable (process, <font class="keyword">this</font>, &description); +00544 IThread *pThread=IThread::create (runnable); +00545 runnable->Thread = pThread; +00546 +00547 <font class="comment">// New first patch</font> +00548 firstPatch=lastPatch; +00549 +00550 <font class="comment">// Launch</font> +00551 pThread->start(); +00552 } +00553 +00554 <font class="comment">// My thread</font> +00555 uint lastPatch=firstPatch+patchCountByThread; +00556 <font class="keywordflow">if</font> (lastPatch>patchCount) +00557 lastPatch=patchCount; +00558 <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>[0] = firstPatch; +00559 CCalcRunnable thread (0, <font class="keyword">this</font>, &description); +00560 thread.Thread = currentThread; +00561 thread.run(); +00562 +00563 <font class="comment">// Wait for others processes</font> +00564 <font class="keywordflow">while</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o14">_ProcessExited</a>!=<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>) +00565 { +00566 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (10); +00567 } +00568 +00569 <font class="comment">// Reset old thread mask</font> +00570 currentThread->setCPUMask (threadMask); +00571 +00572 <font class="comment">// Progress bar</font> +00573 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compute Influences of PointLights"</font>, 0.f); +00574 +00575 <font class="comment">// Compute PointLight influences on zone.</font> +00576 <font class="comment">// Some precalc.</font> +00577 <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_0">compilePointLightRT</a>(description.GridSize, description.GridCellSize, obstacles, +00578 description.Shadow || description.Softshadow ); +00579 <font class="comment">// Influence patchs and get light list of interest</font> +00580 std::vector<CPointLightNamed> listPointLight; +00581 <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_1">processZonePointLightRT</a>(listPointLight); +00582 +00583 +00584 <font class="comment">// Rebuild the zone</font> +00585 +00586 <font class="comment">// Progress bar</font> +00587 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compress the lightmap"</font>, 0.6f); +00588 +00589 <font class="comment">// Build, with list of lights.</font> +00590 CZoneInfo zinfo; +00591 zinfo.ZoneId= <a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>; +00592 zinfo.Patchs= <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>; +00593 zinfo.BorderVertices= <a class="code" href="classNL3D_1_1CZoneLighter.html#o24">_BorderVertices</a>; +00594 zinfo.PointLights= listPointLight; +00595 output.build (zinfo); +00596 +00598 <a class="code" href="classNL3D_1_1CZoneLighter.html#f0">copyTileFlags</a>(output, *(landscape.getZone(zoneToLight))); +00599 +00601 <a class="code" href="classNL3D_1_1CZoneLighter.html#c14">lightShapes</a>(zoneToLight, description); +00602 } +00603 +00604 +00605 <font class="comment">// *************************************************************************************</font> +<a name="l00606"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#f0">00606</a> <font class="keywordtype">void</font> CZoneLighter::copyTileFlags(CZone &destZone, <font class="keyword">const</font> CZone &srcZone) +00607 { +00608 <a class="code" href="debug_8h.html#a6">nlassert</a>(destZone.getZoneId() == srcZone.getZoneId()); +00609 <font class="keywordflow">for</font> (sint k = 0; k < srcZone.getNumPatchs(); ++k) +00610 { +00611 destZone.copyTilesFlags(k, srcZone.getPatch(k)); +00612 } +00613 } +00614 +00615 <font class="comment">// ***************************************************************************</font> +<a name="l00616"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c7">00616</a> <font class="keywordtype">float</font> CZoneLighter::getSkyContribution(<font class="keyword">const</font> CVector &pos, <font class="keyword">const</font> CVector &normal, <font class="keywordtype">float</font> skyIntensity)<font class="keyword"> const</font> +00617 <font class="keyword"></font>{ +00618 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=(pos.x-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>; +00619 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=(pos.y-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>; +00620 sint sInt=(sint)(floor (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f)); +00621 sint tInt=(sint)(floor (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f)); +00622 +00623 <font class="comment">// Bilinear</font> +00624 <font class="keywordtype">float</font> skyContributionTab[2][2]; +00625 skyContributionTab[0][0] = <a class="code" href="classNL3D_1_1CZoneLighter.html#c6">calcSkyContribution</a> (sInt-1, tInt-1, pos.z, skyIntensity, normal); +00626 skyContributionTab[1][0] = <a class="code" href="classNL3D_1_1CZoneLighter.html#c6">calcSkyContribution</a> (sInt, tInt-1, pos.z, skyIntensity, normal); +00627 skyContributionTab[1][1] = <a class="code" href="classNL3D_1_1CZoneLighter.html#c6">calcSkyContribution</a> (sInt, tInt, pos.z, skyIntensity, normal); +00628 skyContributionTab[0][1] = <a class="code" href="classNL3D_1_1CZoneLighter.html#c6">calcSkyContribution</a> (sInt-1, tInt, pos.z, skyIntensity, normal); +00629 +00630 <font class="keywordtype">float</font> sFact=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f-sInt; +00631 <font class="keywordtype">float</font> tFact=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f-tInt; +00632 <font class="keywordflow">return</font> (skyContributionTab[0][0]*(1.f-sFact) + skyContributionTab[1][0]*sFact)*(1.f-tFact) + +00633 (skyContributionTab[0][1]*(1.f-sFact) + skyContributionTab[1][1]*sFact)*tFact; +00634 } +00635 +00636 +00637 <font class="comment">// ***************************************************************************</font> +<a name="l00638"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c2">00638</a> <font class="keywordtype">void</font> CZoneLighter::processCalc (uint process, <font class="keyword">const</font> CLightDesc& description) +00639 { +00640 <font class="comment">// *** Raytrace each patches</font> +00641 +00642 <font class="comment">// Pointer on the zone</font> +00643 CZone *pZone=<a class="code" href="classNL3D_1_1CZoneLighter.html#o5">_Landscape</a>-><a class="code" href="classNL3D_1_1CLandscape.html#z481_0">getZone</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>); +00644 +00645 <font class="comment">// Get a patch</font> +00646 uint patch = <a class="code" href="classNL3D_1_1CZoneLighter.html#c21">getAPatch</a> (process); +00647 <font class="keywordflow">while</font> (patch != 0xffffffff) +00648 { +00649 <font class="comment">// For each patch</font> +00650 <font class="keywordflow">if</font> (description.Shadow) +00651 { +00652 <font class="comment">// Shape array</font> +00653 CMultiShape *shapeArray=<font class="keyword">new</font> CMultiShape; +00654 CMultiShape *shapeArrayTmp=<font class="keyword">new</font> CMultiShape; +00655 shapeArray->Shapes.reserve (<a class="code" href="zone__lighter_8h.html#a1">SHAPE_MAX</a>); +00656 shapeArrayTmp->Shapes.reserve (<a class="code" href="zone__lighter_8h.html#a1">SHAPE_MAX</a>); +00657 +00658 <font class="comment">// Lumels</font> +00659 std::vector<CLumelDescriptor> &lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch]; +00660 +00661 <font class="comment">// Lumel count</font> +00662 uint lumelCount=lumels.size(); +00663 CPatchInfo &patchInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[patch]; +00664 <a class="code" href="debug_8h.html#a6">nlassert</a> (patchInfo.Lumels.size()==lumelCount); +00665 +00666 <font class="comment">// Resize shadow array</font> +00667 <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>[patch].resize (lumelCount); +00668 +00669 <font class="comment">// For each lumel</font> +00670 <font class="keywordflow">for</font> (uint lumel=0; lumel<lumelCount; lumel++) +00671 { +00672 <font class="keywordtype">float</font> factor=0; +00673 <a class="code" href="classNL3D_1_1CZoneLighter.html#c9">rayTrace</a> (lumels[lumel].Position, lumels[lumel].Normal, lumels[lumel].S, lumels[lumel].T, patch, factor, *shapeArray, *shapeArrayTmp, process); +00674 patchInfo.Lumels[lumel]=(uint)(factor*255); +00675 } +00676 <font class="keyword">delete</font> shapeArray; +00677 <font class="keyword">delete</font> shapeArrayTmp; +00678 } +00679 <font class="keywordflow">else</font> +00680 { +00681 <font class="comment">// Lumels</font> +00682 std::vector<CLumelDescriptor> &lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch]; +00683 +00684 <font class="comment">// Lumel count</font> +00685 uint lumelCount=lumels.size(); +00686 CPatchInfo &patchInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[patch]; +00687 <a class="code" href="debug_8h.html#a6">nlassert</a> (patchInfo.Lumels.size()==lumelCount); +00688 +00689 <font class="comment">// For each lumel</font> +00690 <font class="keywordflow">for</font> (uint lumel=0; lumel<lumelCount; lumel++) +00691 { +00692 <font class="comment">// Not shadowed</font> +00693 patchInfo.Lumels[lumel]=255; +00694 } +00695 } +00696 +00697 <font class="comment">// *** Antialising</font> +00698 +00699 <font class="comment">// Id of this zone in the array</font> +00700 uint zoneNumber=<a class="code" href="classNL3D_1_1CZoneLighter.html#o31">_ZoneId</a>[<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>]; +00701 +00702 <font class="comment">// Enabled ?</font> +00703 <font class="keywordflow">if</font> ((description.Shadow)&&(description.Oversampling!=CLightDesc::NoOverSampling)) +00704 { +00705 <font class="comment">// Get a patch pointer</font> +00706 <font class="keyword">const</font> CPatch *pPatch=(const_cast<const CZone*>(pZone))->getPatch (patch); +00707 +00708 <font class="comment">// Get the patch info</font> +00709 CPatchInfo &patchInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[patch]; +00710 +00711 <font class="comment">// Get order of the patch</font> +00712 uint orderLumelS=pPatch->getOrderS()<<2; +00713 uint orderLumelT=pPatch->getOrderT()<<2; +00714 +00715 <font class="comment">// ** Pointer on arries</font> +00716 vector<bool> &binded=<a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zoneNumber][patch]; +00717 vector<bool> &oversampleEdges=<a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>[patch]; +00718 vector<CPatchUVLocator> &locator=<a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zoneNumber][patch]; +00719 std::vector<CLumelDescriptor> &lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch]; +00720 +00721 <font class="comment">// Shadow array</font> +00722 vector<uint8> &shadowPatch=<a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>[patch]; +00723 +00724 <font class="comment">// Go for each lumel</font> +00725 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><orderLumelT; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>++) +00726 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a><orderLumelS; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>++) +00727 { +00728 <font class="comment">// Over sample this lumel</font> +00729 <font class="keywordtype">bool</font> oversample=<font class="keyword">false</font>; +00730 uint8 shadowed=shadowPatch[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*orderLumelS]; +00731 +00732 <font class="comment">// Left..</font> +00733 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>==0) +00734 { +00735 <font class="comment">// Edge test</font> +00736 oversample=<a class="code" href="classNL3D_1_1CZoneLighter.html#c13">isLumelOnEdgeMustBeOversample</a> (patch, 0, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, binded, oversampleEdges, locator, shadowed, <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>); +00737 } +00738 <font class="keywordflow">else</font> +00739 { +00740 <font class="comment">// Internal test</font> +00741 oversample=(shadowed!=shadowPatch[(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>-1)+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*orderLumelS]); +00742 } +00743 +00744 <font class="comment">// Bottom..</font> +00745 <font class="keywordflow">if</font> (!oversample) +00746 { +00747 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>==(orderLumelT-1)) +00748 { +00749 <font class="comment">// Edge test</font> +00750 oversample=<a class="code" href="classNL3D_1_1CZoneLighter.html#c13">isLumelOnEdgeMustBeOversample</a> (patch, 1, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, binded, oversampleEdges, locator, shadowed, <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>); +00751 } +00752 <font class="keywordflow">else</font> +00753 { +00754 <font class="comment">// Internal test</font> +00755 oversample=(shadowed!=shadowPatch[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+1)*orderLumelS]); +00756 } +00757 +00758 <font class="comment">// Right..</font> +00759 <font class="keywordflow">if</font> (!oversample) +00760 { +00761 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>==(orderLumelS-1)) +00762 { +00763 <font class="comment">// Edge test</font> +00764 oversample=<a class="code" href="classNL3D_1_1CZoneLighter.html#c13">isLumelOnEdgeMustBeOversample</a> (patch, 2, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, binded, oversampleEdges, locator, shadowed, <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>); +00765 } +00766 <font class="keywordflow">else</font> +00767 { +00768 <font class="comment">// Internal test</font> +00769 oversample=(shadowed!=shadowPatch[(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+1)+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*orderLumelS]); +00770 } +00771 +00772 <font class="comment">// Top..</font> +00773 <font class="keywordflow">if</font> (!oversample) +00774 { +00775 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>==0) +00776 { +00777 <font class="comment">// Edge test</font> +00778 oversample=<a class="code" href="classNL3D_1_1CZoneLighter.html#c13">isLumelOnEdgeMustBeOversample</a> (patch, 3, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, binded, oversampleEdges, locator, shadowed, <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>); +00779 } +00780 <font class="keywordflow">else</font> +00781 { +00782 <font class="comment">// Internal test</font> +00783 oversample=(shadowed!=shadowPatch[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>-1)*orderLumelS]); +00784 } +00785 } +00786 } +00787 } +00788 +00789 <font class="comment">// Must oversample ?</font> +00790 <font class="keywordflow">if</font> (oversample) +00791 { +00792 <font class="comment">// LumelId</font> +00793 uint lumel=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*orderLumelS; +00794 +00795 <font class="comment">// Lighting</font> +00796 <font class="keywordtype">float</font> factor=0; +00797 +00798 <font class="comment">// Number of ray clipped</font> +00799 uint tested=0; +00800 +00801 <font class="comment">// For each triangle</font> +00802 CTriangleList *list=lumels[lumel].TriangleList; +00803 <font class="keywordflow">while</font> (list!=NULL) +00804 { +00805 <font class="comment">// Raytrace this triangle </font> +00806 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (list->Triangle, lumels[lumel].Normal, description.Oversampling, lumels[lumel].S, lumels[lumel].T, factor, tested, patch); +00807 +00808 <font class="comment">// Next triangle</font> +00809 list=list->Next; +00810 } +00811 +00812 <font class="comment">// Set new shadow value</font> +00813 <a class="code" href="debug_8h.html#a6">nlassert</a> (tested!=0); +00814 <font class="keywordflow">if</font> (tested!=0) +00815 patchInfo.Lumels[lumel]=(uint)(255.f*factor/(float)tested); +00816 } +00817 } +00818 } +00819 +00820 <font class="comment">// *** Lighting</font> +00821 +00822 <font class="comment">// Get the patch info</font> +00823 CPatchInfo &patchInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[patch]; +00824 +00825 <font class="comment">// ** Pointer on arries</font> +00826 std::vector<CLumelDescriptor> &lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch]; +00827 +00828 <font class="comment">// Go for light each lumel</font> +00829 <font class="keywordflow">for</font> (uint lumel=0; lumel<lumels.size(); lumel++) +00830 { +00831 <font class="comment">// Sky contribution</font> +00832 <font class="keywordtype">float</font> skyContribution; +00833 +00834 <font class="keywordflow">if</font> (description.SkyContribution) +00835 { +00836 skyContribution = <a class="code" href="classNL3D_1_1CZoneLighter.html#c7">getSkyContribution</a>(lumels[lumel].Position, lumels[lumel].Normal, description.SkyIntensity); +00837 } +00838 <font class="keywordflow">else</font> +00839 { +00840 skyContribution = 0.f; +00841 } +00842 +00843 <font class="comment">// Sun contribution</font> +00844 <font class="keywordtype">float</font> sunContribution; +00845 <font class="keywordflow">if</font> (description.SunContribution) +00846 { +00847 sunContribution=(-lumels[lumel].Normal*<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>)-skyContribution; +00848 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (sunContribution, 0.f, 1.f); +00849 } +00850 <font class="keywordflow">else</font> +00851 sunContribution=0; +00852 +00853 <font class="comment">// Final lighting</font> +00854 sint finalLighting=(sint)(255.f*(((float)patchInfo.Lumels[lumel])*sunContribution/255.f+skyContribution)); +00855 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (finalLighting, 0, 255); +00856 patchInfo.Lumels[lumel]=finalLighting; +00857 } +00858 +00859 <font class="comment">// Next patch</font> +00860 patch = <a class="code" href="classNL3D_1_1CZoneLighter.html#c21">getAPatch</a> (process); +00861 } +00862 } +00863 +00864 <font class="comment">// ***************************************************************************</font> +00865 +<a name="l00866"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c8">00866</a> uint8 CZoneLighter::getMaxPhi (sint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, sint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, sint deltaS, sint deltaT, <font class="keywordtype">float</font> heightPos)<font class="keyword"> const</font> +00867 <font class="keyword"></font>{ +00868 <font class="comment">// Start position</font> +00869 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+=deltaS; +00870 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=deltaT; +00871 +00872 <font class="comment">// Distance increment</font> +00873 <font class="keywordtype">float</font> stepDistance=CVector (deltaS*<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>, deltaT*<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>,0).norm (); +00874 +00875 <font class="comment">// Current distance</font> +00876 <font class="keywordtype">float</font> distance=stepDistance; +00877 +00878 <font class="comment">// Max height</font> +00879 <font class="keywordtype">float</font> maxHeight=0; +00880 <font class="keywordtype">float</font> maxTanTeta=0; +00881 +00882 <font class="comment">// For all the line</font> +00883 <font class="keywordflow">while</font> ((s<_HeightFieldCellCount)&&(t<_HeightFieldCellCount)&&(s>=0)&&(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>>=0)) +00884 { +00885 <font class="comment">// Get height</font> +00886 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=<a class="code" href="classNL3D_1_1CZoneLighter.html#o19">_HeightField</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>]; +00887 <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>-=heightPos; +00888 +00889 <font class="comment">// Better ?</font> +00890 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>>maxHeight) +00891 { +00892 <font class="comment">// Calc sin teta</font> +00893 <font class="keywordtype">float</font> tanTeta=<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>/distance; +00894 <a class="code" href="debug_8h.html#a6">nlassert</a> (tanTeta>=0); +00895 +00896 <font class="comment">// Better ?</font> +00897 <font class="keywordflow">if</font> (tanTeta>maxTanTeta) +00898 { +00899 <font class="comment">// New max height</font> +00900 maxHeight=<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>; +00901 maxTanTeta=tanTeta; +00902 } +00903 } +00904 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+=deltaS; +00905 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=deltaT; +00906 distance+=stepDistance; +00907 } +00908 +00909 <font class="comment">// return phi</font> +00910 <font class="keywordtype">float</font> teta=(float)atan (maxTanTeta); +00911 <a class="code" href="debug_8h.html#a6">nlassert</a> (teta>=0); +00912 <a class="code" href="debug_8h.html#a6">nlassert</a> (teta<=<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2); +00913 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (teta, 0.f, (<font class="keywordtype">float</font>)<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2); +00914 sint <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>=(sint)((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2-teta)*256/(<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2)); +00915 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>, 0, 255); +00916 <font class="keywordflow">return</font> (uint8)<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>; +00917 } +00918 +00919 <font class="comment">// ***************************************************************************</font> +00920 +<a name="l00921"></a><a class="code" href="zone__lighter_8cpp.html#a1">00921</a> <font class="preprocessor">#define AllFront 0</font> +<a name="l00922"></a><a class="code" href="zone__lighter_8cpp.html#a2">00922</a> <font class="preprocessor"></font><font class="preprocessor">#define AllBack 1</font> +<a name="l00923"></a><a class="code" href="zone__lighter_8cpp.html#a3">00923</a> <font class="preprocessor"></font><font class="preprocessor">#define Clipped 2</font> +00924 <font class="preprocessor"></font> +00925 <font class="comment">// ***************************************************************************</font> +00926 +<a name="l00927"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c12">00927</a> <font class="keywordtype">void</font> CZoneLighter::testRaytrace (<font class="keyword">const</font> CVector& position, <font class="keyword">const</font> CVector& normal, <font class="keyword">const</font> CPlane &plane, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, uint patchId, CMultiShape &shape, CMultiShape &shapeTmp, uint cpu) +00928 { +00929 <font class="comment">// Clear the selection of the quad tree</font> +00930 <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].clearSelection (); +00931 +00932 <font class="comment">// Light position</font> +00933 CVector lightPos=position-(<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>*1000.f); +00934 +00935 <font class="comment">// Select an element with the X axis as a 3d ray</font> +00936 <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].select (lightPos-<a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>, lightPos+<a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>); +00937 +00938 <font class="comment">// Tmp</font> +00939 CShape back; +00940 CShape front; +00941 CShape copy; +00942 +00943 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font> +00944 <font class="preprocessor"></font> +00945 <font class="comment">// Vector unit</font> +00946 <font class="keywordtype">float</font> unit=2*<a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>; +00947 +00948 <font class="comment">// Make a scale matrix</font> +00949 CMatrix lumelScale; +00950 lumelScale.identity (); +00951 lumelScale.scale (unit); +00952 +00953 <font class="comment">// Get the ray basis</font> +00954 CMatrix lumelBasis=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>*lumelScale; +00955 +00956 <font class="comment">// Change origine in the top left corner</font> +00957 lumelBasis.<a class="code" href="classNLMISC_1_1CMatrix.html#z290_6">setPos</a> (position-lumelBasis.getI()/2-lumelBasis.getJ()/2); +00958 +00959 <font class="comment">// Inverse this matrix</font> +00960 lumelBasis.invert (); +00961 +00962 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font> +00963 <font class="preprocessor"></font> +00964 <font class="comment">// For each triangle selected</font> +00965 CQuadGrid<const CTriangle*>::CIterator it=<a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].begin(); +00966 <font class="keywordflow">while</font> (it!=<a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].end()) +00967 { +00968 <font class="comment">// Source vector</font> +00969 CVector source=position; +00970 +00971 <font class="comment">// Same triangle ?</font> +00972 <font class="keywordflow">if</font> ( +00973 ((*it)->PatchId==patchId)&& +00974 ((*it)->ZoneId==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)&& +00975 ((*it)->StartS<=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>)&& +00976 ((*it)->StartT<=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>)&& +00977 ((*it)->EndS>=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>)&& +00978 ((*it)->EndT>=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) +00979 ) +00980 source+=(normal*<a class="code" href="classNL3D_1_1CZoneLighter.html#o6">_ShadowBias</a>); +00981 +00982 <font class="comment">// Blur ?</font> +00983 <font class="keywordflow">if</font> (!<a class="code" href="classNL3D_1_1CZoneLighter.html#o7">_Softshadow</a>) +00984 { +00985 <font class="comment">// Hit position</font> +00986 CVector hit; +00987 +00988 <font class="comment">// Intersect</font> +00989 <font class="keywordflow">if</font> ((*it)->Triangle.intersect (source, lightPos, hit, (*it)->Plane)) +00990 { +00991 <font class="comment">// Clear the shape list</font> +00992 shape.Shapes.resize (0); +00993 <font class="keywordflow">break</font>; +00994 } +00995 } +00996 <font class="keywordflow">else</font> +00997 { +00998 <font class="comment">// Triangle clippable ?</font> +00999 <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> &triangle=(*it)->Triangle; +01000 +01001 <font class="comment">// Clip the ray over the triangle</font> +01002 <font class="keywordtype">float</font> edgeFactor[3]= +01003 { +01004 ((((triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>+triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>)/2) - source)*-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o18">_FallofDistance</a>, +01005 ((((triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>+triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>)/2) - source)*-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o18">_FallofDistance</a>, +01006 ((((triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>+triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>)/2) - source)*-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o18">_FallofDistance</a>, +01007 }; +01008 <font class="keywordtype">float</font> oOEdgeFactor[3]; +01009 <font class="keywordtype">bool</font> scaleEdge[3]; +01010 uint edgeFlags[3]; +01011 <font class="keywordtype">bool</font> oneNotBack=<font class="keyword">false</font>; +01012 uint i; +01013 <font class="keywordflow">for</font> (i=0; i<3; i++) +01014 { +01015 <font class="comment">// Edge factor</font> +01016 <font class="keywordflow">if</font> (edgeFactor[i]<0) +01017 <font class="comment">// Polygon behing</font> +01018 <font class="keywordflow">break</font>; +01019 <font class="keywordflow">if</font> (edgeFactor[i]>1) +01020 { +01021 scaleEdge[i]=<font class="keyword">false</font>; +01022 edgeFactor[i]=1; +01023 } +01024 <font class="keywordflow">else</font> +01025 { +01026 scaleEdge[i]=<font class="keyword">true</font>; +01027 oOEdgeFactor[i]=1/edgeFactor[i]; +01028 } +01029 +01030 <font class="comment">// Distance from clipping plane</font> +01031 <font class="keywordtype">float</font> distance=(*it)->ClippingPlanes[i]*source; +01032 +01033 <font class="comment">// Clipping distance</font> +01034 <font class="keywordtype">float</font> clipDist=edgeFactor[i]*<a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>; +01035 +01036 <font class="comment">// Clip this distance</font> +01037 <font class="keywordflow">if</font> (distance<-clipDist) +01038 { +01039 <font class="comment">// Back</font> +01040 edgeFlags[i]=<a class="code" href="zone__lighter_8cpp.html#a2">AllBack</a>; +01041 } +01042 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (distance>clipDist) +01043 <font class="comment">// Front</font> +01044 <font class="keywordflow">break</font>; +01045 <font class="keywordflow">else</font> +01046 { +01047 <font class="comment">// Clipped</font> +01048 edgeFlags[i]=<a class="code" href="zone__lighter_8cpp.html#a3">Clipped</a>; +01049 oneNotBack=<font class="keyword">true</font>; +01050 } +01051 } +01052 +01053 <font class="comment">// Not front clipped</font> +01054 <font class="keywordflow">if</font> (i==3) +01055 { +01056 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font> +01057 <font class="preprocessor"></font> <font class="comment">// Transform this triangle in lumel basis</font> +01058 CVector <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[3] = { lumelBasis*triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>, lumelBasis*triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>, lumelBasis*triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a> }; +01059 +01060 <font class="comment">// Draw the triangle</font> +01061 drv->drawTriangle (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, CRGBA(0, 0, 0, 2)); +01062 drv->drawTriangle (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, CRGBA(0, 0, 0, 2)); +01063 +01064 <font class="preprocessor">#else // HARDWARE_SOFT_SHADOWS</font> +01065 <font class="preprocessor"></font> <font class="comment">// All back ?</font> +01066 <font class="keywordflow">if</font> (oneNotBack) +01067 { +01068 uint backupSize=shape.Shapes.size(); +01069 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a><backupSize; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>++) +01070 { +01071 <font class="comment">// Reset out list</font> +01072 shapeTmp.Shapes.resize (0); +01073 back = shape.Shapes[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>]; +01074 +01075 <font class="comment">// Clip this shape with the triangle (3 planes)</font> +01076 <font class="keywordflow">for</font> (i=0; i<3; i++) +01077 { +01078 <font class="comment">// All back ?</font> +01079 <font class="keywordflow">if</font> (edgeFlags[i]==<a class="code" href="zone__lighter_8cpp.html#a2">AllBack</a>) +01080 <font class="comment">// Yes, next</font> +01081 <font class="keywordflow">continue</font>; +01082 +01083 <font class="comment">// Security</font> +01084 <font class="keywordflow">if</font> (back.NumVertex > (<a class="code" href="zone__lighter_8h.html#a0">SHAPE_VERTICES_MAX</a>-10) ) +01085 <font class="keywordflow">break</font>; +01086 +01087 <font class="comment">// Scale down this shape</font> +01088 <font class="keywordflow">if</font> (scaleEdge[i]) +01089 back.scale (source, edgeFactor[i]); +01090 +01091 <font class="comment">// Copy the back buffer</font> +01092 copy=back; +01093 +01094 <font class="comment">// Clipping plane</font> +01095 <font class="keyword">const</font> CPlane &clippingPlane=(*it)->ClippingPlanes[i]; +01096 +01097 <font class="comment">// Reset back and front</font> +01098 back.NumVertex=0; +01099 front.NumVertex=0; +01100 +01101 <font class="comment">// Clip</font> +01102 <font class="keywordflow">if</font>(copy.NumVertex>2) +01103 { +01104 <font class="comment">// Previous vertex</font> +01105 uint prev=copy.NumVertex-1; +01106 +01107 <font class="comment">// Previous front ?</font> +01108 <font class="keywordtype">bool</font> previousFront=(clippingPlane*copy.Vertices[prev] >= 0); +01109 +01110 <font class="comment">// For each vertex</font> +01111 <font class="keywordflow">for</font> (uint cur=0;cur<copy.NumVertex;cur++) +01112 { +01113 <font class="comment">// Current vertex front ?</font> +01114 <font class="keywordtype">bool</font> currentFront=(clippingPlane*copy.Vertices[cur] >= 0); +01115 <font class="keywordflow">if</font> ( currentFront ) +01116 { +01117 <font class="comment">// Previous vertex back ?</font> +01118 <font class="keywordflow">if</font> ( !previousFront ) +01119 { +01120 <font class="comment">// Ok, intersect</font> +01121 front.Vertices[front.NumVertex]= clippingPlane.intersect(copy.Vertices[prev],copy.Vertices[cur]); +01122 back.Vertices[back.NumVertex++]= front.Vertices[front.NumVertex]; +01123 front.NumVertex++; +01124 } +01125 <font class="comment">// Store new vertex front</font> +01126 front.Vertices[front.NumVertex++]=copy.Vertices[cur]; +01127 } +01128 <font class="keywordflow">else</font> +01129 { +01130 <font class="comment">// Previous vertex front ?</font> +01131 <font class="keywordflow">if</font> ( previousFront ) +01132 { +01133 front.Vertices[front.NumVertex]= clippingPlane.intersect(copy.Vertices[prev],copy.Vertices[cur]); +01134 back.Vertices[back.NumVertex++]= front.Vertices[front.NumVertex]; +01135 front.NumVertex++; +01136 } +01137 back.Vertices[back.NumVertex++]=copy.Vertices[cur]; +01138 } +01139 prev=cur; +01140 previousFront=currentFront; +01141 } +01142 } +01143 +01144 <font class="comment">// Scale up this shape</font> +01145 <font class="keywordflow">if</font> (scaleEdge[i]) +01146 { +01147 back.scale (source, oOEdgeFactor[i]); +01148 front.scale (source, oOEdgeFactor[i]); +01149 } +01150 +01151 <font class="comment">// Some vertices front ?</font> +01152 <font class="keywordflow">if</font> (front.NumVertex!=0) +01153 { +01154 <font class="comment">// Front vertices ?</font> +01155 <font class="keywordflow">if</font> (back.NumVertex==0) +01156 <font class="comment">// Nothing else to clip</font> +01157 <font class="keywordflow">break</font>; +01158 } +01159 <font class="keywordflow">else</font> +01160 { +01161 <font class="comment">// All vertices are back</font> +01162 <font class="comment">// Pass entire triangle to next plane</font> +01163 <font class="keywordflow">continue</font>; +01164 } +01165 +01166 <font class="comment">// Code is clipped</font> +01167 <font class="comment">// res is the front shape, so it is out</font> +01168 <font class="comment">// Last plane ?</font> +01169 shapeTmp.Shapes.push_back (front); +01170 } +01171 <font class="keywordflow">if</font> (i==3) +01172 { +01173 <font class="comment">// Merge list..</font> +01174 <font class="keywordflow">if</font> (shapeTmp.Shapes.empty()) +01175 { +01176 <font class="comment">// Erase this entry</font> +01177 shape.Shapes[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>].NumVertex=0; +01178 } +01179 <font class="keywordflow">else</font> +01180 { +01181 <font class="comment">// Copy first element</font> +01182 shape.Shapes[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>]=shapeTmp.Shapes[0]; +01183 +01184 <font class="comment">// Insert others</font> +01185 uint size=shapeTmp.Shapes.size(); +01186 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=1; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><size; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>++) +01187 { +01188 <font class="comment">// Append new shapes</font> +01189 shape.Shapes.push_back (shapeTmp.Shapes[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>]); +01190 } +01191 } +01192 } +01193 } +01194 } +01195 <font class="keywordflow">else</font> +01196 { +01197 <font class="comment">// Clear all the ray</font> +01198 shape.Shapes.resize (0); +01199 } +01200 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font> +01201 <font class="preprocessor"></font> } +01202 } +01203 +01204 <font class="comment">// Next</font> +01205 it++; +01206 } +01207 } +01208 +01209 <font class="comment">// ***************************************************************************</font> +01210 +<a name="l01211"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c9">01211</a> <font class="keywordtype">void</font> CZoneLighter::rayTrace (<font class="keyword">const</font> CVector& position, <font class="keyword">const</font> CVector& normal, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, uint patchId, <font class="keywordtype">float</font> &factor, CMultiShape &shape, CMultiShape &shapeTmp, uint cpu) +01212 { +01213 <font class="comment">// Resize the shape list</font> +01214 shape.Shapes.resize (1); +01215 +01216 <font class="comment">// Ref on the cshape</font> +01217 CShape &shp=shape.Shapes[0]; +01218 +01219 <font class="comment">// Copy the shape</font> +01220 shp=<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>; +01221 +01222 <font class="comment">// Translate the shape</font> +01223 sint j; +01224 <font class="keywordflow">for</font> (j=0; j<(sint)shp.NumVertex; j++) +01225 { +01226 shp.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m1">Vertices</a>[j]+=position; +01227 } +01228 +01229 <font class="comment">// Build a clipping plane</font> +01230 CPlane plane; +01231 plane.make (-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>, position); +01232 +01233 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font> +01234 <font class="preprocessor"></font> +01235 <font class="comment">// Clear all pixels in green</font> +01236 drv->clearRGBABuffer (CRGBA (0, 255, 0, 0)); +01237 +01238 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font> +01239 <font class="preprocessor"></font> +01240 <font class="comment">// Go!</font> +01241 <a class="code" href="classNL3D_1_1CZoneLighter.html#c12">testRaytrace</a> (position, normal, plane, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, patchId, shape, shapeTmp, cpu); +01242 +01243 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font> +01244 <font class="preprocessor"></font> +01245 <font class="comment">// Download frame buffer</font> +01246 <font class="keyword">static</font> CBitmap bitmap; +01247 drv->getBufferPart (bitmap, CRect (0, 0, LIGHT_BUFFER_SIZE, LIGHT_BUFFER_SIZE)); +01248 <a class="code" href="debug_8h.html#a6">nlassert</a> (bitmap.getWidth()==LIGHT_BUFFER_SIZE); +01249 <a class="code" href="debug_8h.html#a6">nlassert</a> (bitmap.getHeight()==LIGHT_BUFFER_SIZE); +01250 +01251 <font class="comment">// Pixels</font> +01252 bitmap.convertToType (CBitmap::RGBA); +01253 +01254 <font class="comment">// RGBA pointer</font> +01255 CRGBA *pixels=(CRGBA*)&bitmap.getPixels ()[0]; +01256 +01257 <font class="comment">// Average pixel</font> +01258 factor=0; +01259 <font class="keywordflow">for</font> (uint p=0; p<LIGHT_BUFFER_SIZE*LIGHT_BUFFER_SIZE; p++) +01260 { +01261 factor+=pixels[p].G; +01262 } +01263 factor/=(float)(255*LIGHT_BUFFER_SIZE*LIGHT_BUFFER_SIZE); +01264 +01265 <font class="preprocessor">#else // HARDWARE_SOFT_SHADOWS</font> +01266 <font class="preprocessor"></font> <font class="comment">// Calc the surface ratio</font> +01267 uint size=shape.Shapes.size(); +01268 <font class="keywordflow">for</font> (uint i=0; i<size; i++) +01269 { +01270 <font class="comment">// For each shape</font> +01271 CShape &vect=shape.Shapes[i]; +01272 +01273 <font class="keywordflow">for</font> (j=1; j<(sint)vect.NumVertex-1; j++) +01274 { +01275 <font class="comment">// Sum the area</font> +01276 factor+=((vect.Vertices[j]-vect.Vertices[0])^(vect.Vertices[j+1]-vect.Vertices[0])).norm(); +01277 } +01278 } +01279 +01280 factor/=<a class="code" href="classNL3D_1_1CZoneLighter.html#o16">_ShapeArea</a>; +01281 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font> +01282 <font class="preprocessor"></font>} +01283 +01284 <font class="comment">// ***************************************************************************</font> +01285 +<a name="l01286"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c11">01286</a> <font class="keywordtype">void</font> CZoneLighter::rayTraceTriangle (<font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a>& toOverSample, CVector& normal, uint order, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, <font class="keywordtype">float</font> &factor, uint &tested, uint patch) +01287 { +01288 <font class="comment">// Ok ?</font> +01289 <font class="keywordflow">if</font> (order==0) +01290 { +01291 <font class="comment">// Ray !</font> +01292 tested++; +01293 <font class="comment">//rayTrace (-_LightDirection+(toOverSample.V0+toOverSample.V1+toOverSample.V2)/3, normal, s, t, patch, factor);</font> +01294 } +01295 <font class="keywordflow">else</font> +01296 { +01297 <font class="comment">// Subdivide the triangle</font> +01298 CVector v0V1=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>; +01299 v0V1+=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>; +01300 v0V1/=2; +01301 CVector v0V2=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>; +01302 v0V2+=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>; +01303 v0V2/=2; +01304 CVector v1V2=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>; +01305 v1V2+=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>; +01306 v1V2/=2; +01307 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>, v0V1, v0V2), normal, order-1, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, factor, tested, patch); +01308 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>, v1V2, v0V1), normal, order-1, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, factor, tested, patch); +01309 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>, v0V2, v1V2), normal, order-1, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, factor, tested, patch); +01310 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0V1, v1V2, v0V2), normal, order-1, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, factor, tested, patch); +01311 } +01312 } +01313 +01314 <font class="comment">// ***************************************************************************</font> +01315 +<a name="l01316"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c13">01316</a> <font class="keywordtype">bool</font> CZoneLighter::isLumelOnEdgeMustBeOversample (uint patch, uint edge, sint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, sint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, <font class="keyword">const</font> vector<bool> &binded, +01317 <font class="keyword">const</font> vector<bool> &oversampleEdges, vector<CPatchUVLocator> &locator, +01318 uint8 shadowed, vector<vector<uint8> >& shadowBuffer) +01319 { +01320 <font class="comment">// Must force oversampling of this edge ?</font> +01321 <font class="keywordflow">if</font> (oversampleEdges[edge]) +01322 <font class="keywordflow">return</font> <font class="keyword">true</font>; +01323 <font class="keywordflow">else</font> +01324 { +01325 <font class="comment">// binded ?</font> +01326 <font class="keywordflow">if</font> (binded[edge]) +01327 { +01328 <font class="comment">// Lumel coord</font> +01329 CVector2f lumelCoord (((<font class="keywordtype">float</font>)(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[edge])+0.5f)/4.f, ((<font class="keywordtype">float</font>)(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[edge])+0.5f)/4.f); +01330 uint otherPatch=locator[edge].selectPatch(lumelCoord); +01331 +01332 <font class="comment">// Get uv</font> +01333 CVector2f neighborUV; +01334 CPatch *patchOut; +01335 locator[edge].locateUV (lumelCoord, otherPatch, patchOut, neighborUV); +01336 +01337 <font class="comment">// Is the same shadowed flag ?</font> +01338 sint ss=(sint)(neighborUV.x*4.f); +01339 sint tt=(sint)(neighborUV.y*4.f); +01340 <font class="keywordflow">return</font> (shadowBuffer[patchOut->getPatchId()][ss+(patchOut->getOrderS()<<2)*tt]!=shadowed); +01341 } +01342 <font class="keywordflow">else</font> +01343 { +01344 <font class="comment">// Not oversample if not binded</font> +01345 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01346 } +01347 } +01348 } +01349 +01350 <font class="comment">// ***************************************************************************</font> +01351 +<a name="l01352"></a><a class="code" href="zone__lighter_8cpp.html#a8">01352</a> <font class="keywordtype">float</font> <a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>) +01353 { +01354 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>; +01355 <font class="comment">// cubic tq f(0)=0, f'(0)=0, f(1)=1, f'(1)=0.</font> +01356 <font class="keywordtype">float</font> x2=<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>; +01357 <font class="keywordtype">float</font> x3=x2*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>; +01358 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= -2*x3 + 3*x2; +01359 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>; +01360 } +01361 +01362 <font class="comment">// ***************************************************************************</font> +01363 +<a name="l01364"></a><a class="code" href="zone__lighter_8cpp.html#a9">01364</a> <font class="keywordtype">float</font> <a class="code" href="zone__lighter_8cpp.html#a9">easineasoutC2</a>(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>) +01365 { +01366 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>; +01367 <font class="comment">// 5-nome tq f(0)=0, f'(0)=0, f''(0)=0, f(1)=1, f'(1)=0, f''(1)=0.</font> +01368 <font class="keywordtype">float</font> x3=<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>; +01369 <font class="keywordtype">float</font> x4=x3*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>; +01370 <font class="keywordtype">float</font> x5=x4*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>; +01371 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= 6*x5 -15*x4 +10*x3; +01372 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>; +01373 } +01374 +01375 <font class="comment">// ***************************************************************************</font> +01376 +01377 +<a name="l01378"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#r0">01378</a> sint16 CZoneLighter::_GetNormalDeltaS[4]={ -1, 0, 1, 0 }; +<a name="l01379"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#r1">01379</a> sint16 CZoneLighter::_GetNormalDeltaT[4]={ 0, 1, 0, -1 }; +01380 +01381 <font class="comment">// ***************************************************************************</font> +01382 +<a name="l01383"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c10">01383</a> <font class="keywordtype">void</font> CZoneLighter::getNormal (<font class="keyword">const</font> CPatch *pPatch, sint16 lumelS, sint16 lumelT, vector<CPatchUVLocator> &locator, +01384 <font class="keyword">const</font> vector<CPatch::CBindInfo> &bindInfo, <font class="keyword">const</font> vector<bool> &binded, set<uint64>& visited, +01385 <font class="keywordtype">float</font> deltaS, <font class="keywordtype">float</font> deltaT, uint rotation, <font class="keyword">const</font> CBezierPatch &bezierPatch, uint lastEdge) +01386 { +01387 <font class="comment">// Build a desc srructure</font> +01388 uint64 <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>=(uint64)lumelS|(((uint64)lumelT)<<16)|(((uint64)pPatch->getPatchId())<<32)|(((uint64)pPatch->getZone()->getZoneId())<<48); +01389 +01390 <font class="comment">// Insert it</font> +01391 <font class="keywordflow">if</font> (visited.insert (id).second) +01392 { +01393 <font class="comment">// Clip</font> +01394 <font class="keywordtype">float</font> sqDist=deltaS*deltaS+deltaT*deltaT; +01395 <font class="keywordflow">if</font> ( sqDist < 1 ) +01396 { +01397 <font class="comment">// Continue...</font> +01398 +01399 sint orderSx4=pPatch->getOrderS()<<2; +01400 sint orderTx4=pPatch->getOrderT()<<2; +01401 +01402 sint16 _GetNormalBorderS[4]={ 0, -10, 1, -10 }; +01403 sint16 _GetNormalBorderT[4]={ -10, 1, -10, 0 }; +01404 _GetNormalBorderS[2]=orderSx4-1; +01405 _GetNormalBorderT[1]=orderTx4-1; +01406 +01407 <font class="comment">// Add normal</font> +01408 <a class="code" href="classNL3D_1_1CZoneLighter.html#o33">_GetNormalNormal</a>+=bezierPatch.evalNormal ( ((<font class="keywordtype">float</font>)lumelS+0.5f)/(<font class="keywordtype">float</font>)orderSx4, ((<font class="keywordtype">float</font>)lumelT+0.5f)/(<font class="keywordtype">float</font>)orderTx4 ); +01409 +01410 <font class="comment">// For the four neighbors</font> +01411 <font class="keywordflow">for</font> (uint edge=0; edge<4; edge++) +01412 { +01413 <font class="comment">// Not last edge ?</font> +01414 <font class="keywordflow">if</font> (edge!=lastEdge) +01415 { +01416 <font class="comment">// Direction</font> +01417 uint globalDirection=(edge+(4-rotation))&0x3; +01418 +01419 <font class="comment">// Neighbor</font> +01420 <font class="keywordflow">if</font> ( (lumelS==_GetNormalBorderS[edge]) || (lumelT==_GetNormalBorderT[edge]) ) +01421 { +01422 <font class="comment">// Binded ?</font> +01423 <font class="keywordtype">bool</font> bind=binded[edge]; +01424 <font class="keywordtype">bool</font> smooth=pPatch->getSmoothFlag (edge); +01425 <font class="keywordflow">if</font> (bind&&smooth) +01426 { +01427 <font class="comment">// Lumel coord</font> +01428 CVector2f lumelCoord ( ((<font class="keywordtype">float</font>)(lumelS+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[edge])+0.5f)/4, +01429 ((<font class="keywordtype">float</font>)(lumelT+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[edge])+0.5f)/4 ); +01430 +01431 <font class="comment">// Get neighbor pixel</font> +01432 uint otherPatch=locator[edge].selectPatch(lumelCoord); +01433 +01434 <font class="comment">// Get uv</font> +01435 CVector2f neighborUV; +01436 CPatch *patchOut; +01437 locator[edge].locateUV (lumelCoord, otherPatch, patchOut, neighborUV); +01438 +01439 <font class="comment">// New coordinates</font> +01440 sint16 newLumelS=(sint16)(4.f*neighborUV.x); +01441 sint16 newLumelT=(sint16)(4.f*neighborUV.y); +01442 +01443 <font class="comment">// Zone id</font> +01444 uint16 patchId=patchOut->getPatchId(); +01445 uint16 zoneId=<a class="code" href="classNL3D_1_1CZoneLighter.html#o31">_ZoneId</a>[patchOut->getZone()->getZoneId ()]; +01446 +01447 <font class="comment">// Get edge</font> +01448 uint newEdge=0; +01449 uint i; +01450 <font class="keywordflow">for</font> (i=0; i<=(uint)bindInfo[edge].NPatchs; i++) +01451 { +01452 <font class="comment">// Good patch ?</font> +01453 <font class="keywordflow">if</font> (bindInfo[edge].Next[i]==patchOut) +01454 { +01455 <font class="comment">// Get its edge</font> +01456 newEdge=bindInfo[edge].Edge[i]; +01457 <font class="keywordflow">break</font>; +01458 } +01459 } +01460 +01461 <font class="comment">// Rotation </font> +01462 uint newRotation=(2-edge+rotation+newEdge)&0x3; +01463 +01464 <font class="comment">// Must found it</font> +01465 <a class="code" href="debug_8h.html#a6">nlassert</a> (i!=(uint)bindInfo[edge].NPatchs); +01466 +01467 <font class="comment">// Get the bezier patch</font> +01468 CBezierPatch &NewBezierPatch=<a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>[zoneId][patchId]; +01469 +01470 <font class="comment">// Next lumel</font> +01471 <a class="code" href="classNL3D_1_1CZoneLighter.html#c10">getNormal</a> (patchOut, newLumelS, newLumelT, <a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zoneId][patchId], <a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>[zoneId][patchId], +01472 <a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zoneId][patchId], visited, deltaS+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[globalDirection], +01473 deltaT+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[globalDirection], newRotation, NewBezierPatch, newEdge); +01474 } +01475 } +01476 <font class="keywordflow">else</font> +01477 { +01478 <font class="comment">// Left internal</font> +01479 <a class="code" href="classNL3D_1_1CZoneLighter.html#c10">getNormal</a> (pPatch, lumelS+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[edge], lumelT+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[edge], locator, bindInfo, binded, visited, +01480 deltaS+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[globalDirection], deltaT+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[globalDirection], rotation, bezierPatch, (edge+2)&0x3); +01481 } +01482 } +01483 } +01484 } +01485 } +01486 } +01487 +01488 <font class="comment">// ***************************************************************************</font> +01489 +<a name="l01490"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a4">01490</a> <font class="keywordtype">void</font> CZoneLighter::addTriangles (CLandscape &landscape, vector<uint> &listZone, uint order, std::vector<CTriangle>& triangleArray) +01491 { +01492 <font class="comment">// Set all to refine</font> +01493 <a class="code" href="classNL3D_1_1CZoneLighter.html#c4">excludeAllPatchFromRefineAll</a> (landscape, listZone, <font class="keyword">false</font>); +01494 +01495 <font class="comment">// Setup the landscape</font> +01496 landscape.setThreshold (0); +01497 landscape.setTileMaxSubdivision (order); +01498 +01499 <font class="comment">// Refine it</font> +01500 landscape.refineAll (CVector (0, 0, 0)); +01501 +01502 <font class="comment">// Dump tesselated triangles</font> +01503 std::vector<const CTessFace*> leaves; +01504 landscape.getTessellationLeaves(leaves); +01505 +01506 <font class="comment">// Number of leaves</font> +01507 uint leavesCount=leaves.size(); +01508 +01509 <font class="comment">// Reserve the array</font> +01510 triangleArray.reserve (triangleArray.size()+leavesCount); +01511 +01512 <font class="comment">// Scan each leaves</font> +01513 <font class="keywordflow">for</font> (uint leave=0; leave<leavesCount; leave++) +01514 { +01515 <font class="comment">// Leave</font> +01516 <font class="keyword">const</font> CTessFace *face=leaves[leave]; +01517 +01518 <font class="comment">// Start and end coordinate</font> +01519 <font class="keywordtype">float</font> startS=<a class="code" href="bit__set_8cpp.html#a0">min</a> (<a class="code" href="bit__set_8cpp.html#a0">min</a> (face->PVBase.getS(), face->PVLeft.getS()), face->PVRight.getS()); +01520 <font class="keywordtype">float</font> endS=max (max (face->PVBase.getS(), face->PVLeft.getS()), face->PVRight.getS()); +01521 <font class="keywordtype">float</font> startT=<a class="code" href="bit__set_8cpp.html#a0">min</a> (<a class="code" href="bit__set_8cpp.html#a0">min</a> (face->PVBase.getT(), face->PVLeft.getT()), face->PVRight.getT()); +01522 <font class="keywordtype">float</font> endT=max (max (face->PVBase.getT(), face->PVLeft.getT()), face->PVRight.getT()); +01523 +01524 <font class="comment">// Add a triangle</font> +01525 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (face->VBase->EndPos, face->VLeft->EndPos, face->VRight->EndPos), +01526 face->Patch->getZone()->getZoneId(), face->Patch->getPatchId(), startS ,endS, startT, endT)); +01527 } +01528 +01529 <font class="comment">// Setup the landscape</font> +01530 landscape.setThreshold (1000); +01531 landscape.setTileMaxSubdivision (0); +01532 +01533 <font class="comment">// Remove all triangles</font> +01534 landscape.refineAll (CVector (0, 0, 0)); +01535 landscape.refineAll (CVector (0, 0, 0)); +01536 landscape.refineAll (CVector (0, 0, 0)); +01537 landscape.refineAll (CVector (0, 0, 0)); +01538 landscape.refineAll (CVector (0, 0, 0)); +01539 landscape.refineAll (CVector (0, 0, 0)); +01540 landscape.refineAll (CVector (0, 0, 0)); +01541 landscape.refineAll (CVector (0, 0, 0)); +01542 landscape.refineAll (CVector (0, 0, 0)); +01543 landscape.refineAll (CVector (0, 0, 0)); +01544 } +01545 +01546 <font class="comment">// ***************************************************************************</font> +01547 +<a name="l01548"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a5">01548</a> <font class="keywordtype">void</font> CZoneLighter::addTriangles (<font class="keyword">const</font> IShape &shape, <font class="keyword">const</font> CMatrix& modelMT, std::vector<CTriangle>& triangleArray) +01549 { +01550 <font class="comment">// Cast to CMesh</font> +01551 <font class="keyword">const</font> CMesh *mesh=dynamic_cast<const CMesh*>(&shape); +01552 +01553 <font class="comment">// Cast to CMeshMultiLod</font> +01554 <font class="keyword">const</font> CMeshMultiLod *meshMulti=dynamic_cast<const CMeshMultiLod*>(&shape); +01555 +01556 <font class="comment">// Cast to CMeshMultiLod</font> +01557 <font class="keyword">const</font> CMeshMRM *meshMRM=dynamic_cast<const CMeshMRM*>(&shape); +01558 +01559 <font class="comment">// It is a mesh ?</font> +01560 <font class="keywordflow">if</font> (mesh) +01561 { +01562 <font class="comment">// Add its triangles</font> +01563 <a class="code" href="classNL3D_1_1CZoneLighter.html#a4">addTriangles</a> (mesh->getMeshGeom (), modelMT, triangleArray); +01564 } +01565 <font class="comment">// It is a CMeshMultiLod ?</font> +01566 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (meshMulti) +01567 { +01568 <font class="comment">// Get the first geommesh</font> +01569 <font class="keyword">const</font> IMeshGeom *meshGeom=&meshMulti->getMeshGeom (0); +01570 +01571 <font class="comment">// Dynamic cast</font> +01572 <font class="keyword">const</font> CMeshGeom *geomMesh=dynamic_cast<const CMeshGeom*>(meshGeom); +01573 <font class="keywordflow">if</font> (geomMesh) +01574 { +01575 <a class="code" href="classNL3D_1_1CZoneLighter.html#a4">addTriangles</a> (*geomMesh, modelMT, triangleArray); +01576 } +01577 +01578 <font class="comment">// Dynamic cast</font> +01579 <font class="keyword">const</font> CMeshMRMGeom *mrmGeomMesh=dynamic_cast<const CMeshMRMGeom*>(meshGeom); +01580 <font class="keywordflow">if</font> (mrmGeomMesh) +01581 { +01582 <a class="code" href="classNL3D_1_1CZoneLighter.html#a4">addTriangles</a> (*mrmGeomMesh, modelMT, triangleArray); +01583 } +01584 } +01585 <font class="comment">// It is a CMeshMultiLod ?</font> +01586 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (meshMRM) +01587 { +01588 <font class="comment">// Get the first lod mesh geom</font> +01589 <a class="code" href="classNL3D_1_1CZoneLighter.html#a4">addTriangles</a> (meshMRM->getMeshGeom (), modelMT, triangleArray); +01590 } +01591 } +01592 +01593 <font class="comment">// ***************************************************************************</font> +01594 +<a name="l01595"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c0">01595</a> <font class="keywordtype">void</font> CZoneLighter::addTriangles (<font class="keyword">const</font> CMeshGeom &meshGeom, <font class="keyword">const</font> CMatrix& modelMT, std::vector<CTriangle>& triangleArray) +01596 { +01597 <font class="comment">// Get the vertex buffer</font> +01598 <font class="keyword">const</font> CVertexBuffer &vb=meshGeom.getVertexBuffer(); +01599 +01600 <font class="comment">// For each matrix block</font> +01601 uint numBlock=meshGeom.getNbMatrixBlock(); +01602 <font class="keywordflow">for</font> (uint block=0; block<numBlock; block++) +01603 { +01604 <font class="comment">// For each render pass</font> +01605 uint numRenderPass=meshGeom.getNbRdrPass(block); +01606 <font class="keywordflow">for</font> (uint pass=0; pass<numRenderPass; pass++) +01607 { +01608 <font class="comment">// Get the primitive block</font> +01609 <font class="keyword">const</font> CPrimitiveBlock &primitive=meshGeom.getRdrPassPrimitiveBlock ( block, pass); +01610 +01611 <font class="comment">// Dump triangles</font> +01612 <font class="keyword">const</font> uint32* triIndex=primitive.getTriPointer (); +01613 uint numTri=primitive.getNumTri (); +01614 uint tri; +01615 <font class="keywordflow">for</font> (tri=0; tri<numTri; tri++) +01616 { +01617 <font class="comment">// Vertex</font> +01618 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3])); +01619 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+1])); +01620 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+2])); +01621 +01622 <font class="comment">// Make a triangle</font> +01623 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2))); +01624 } +01625 +01626 <font class="comment">// Dump quad</font> +01627 triIndex=primitive.getQuadPointer (); +01628 numTri=primitive.getNumQuad (); +01629 <font class="keywordflow">for</font> (tri=0; tri<numTri; tri++) +01630 { +01631 <font class="comment">// Vertex</font> +01632 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4])); +01633 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+1])); +01634 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+2])); +01635 CVector v3=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+3])); +01636 +01637 <font class="comment">// Make 2 triangles</font> +01638 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2))); +01639 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v2, v3))); +01640 } +01641 } +01642 } +01643 } +01644 +01645 <font class="comment">// ***************************************************************************</font> +01646 +<a name="l01647"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c1">01647</a> <font class="keywordtype">void</font> CZoneLighter::addTriangles (<font class="keyword">const</font> CMeshMRMGeom &meshGeom, <font class="keyword">const</font> CMatrix& modelMT, std::vector<CTriangle>& triangleArray) +01648 { +01649 <font class="comment">// Get the vertex buffer</font> +01650 <font class="keyword">const</font> CVertexBuffer &vb=meshGeom.getVertexBuffer(); +01651 +01652 <font class="comment">// For each render pass</font> +01653 uint numRenderPass=meshGeom.getNbRdrPass(0); +01654 <font class="keywordflow">for</font> (uint pass=0; pass<numRenderPass; pass++) +01655 { +01656 <font class="comment">// Get the primitive block</font> +01657 <font class="keyword">const</font> CPrimitiveBlock &primitive=meshGeom.getRdrPassPrimitiveBlock ( 0, pass); +01658 +01659 <font class="comment">// Dump triangles</font> +01660 <font class="keyword">const</font> uint32* triIndex=primitive.getTriPointer (); +01661 uint numTri=primitive.getNumTri (); +01662 uint tri; +01663 <font class="keywordflow">for</font> (tri=0; tri<numTri; tri++) +01664 { +01665 <font class="comment">// Vertex</font> +01666 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3])); +01667 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+1])); +01668 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+2])); +01669 +01670 <font class="comment">// Make a triangle</font> +01671 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2))); +01672 } +01673 +01674 <font class="comment">// Dump quad</font> +01675 triIndex=primitive.getQuadPointer (); +01676 numTri=primitive.getNumQuad (); +01677 <font class="keywordflow">for</font> (tri=0; tri<numTri; tri++) +01678 { +01679 <font class="comment">// Vertex</font> +01680 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4])); +01681 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+1])); +01682 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+2])); +01683 CVector v3=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+3])); +01684 +01685 <font class="comment">// Make 2 triangles</font> +01686 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2))); +01687 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v2, v3))); +01688 } +01689 } +01690 } +01691 +01692 <font class="comment">// ***************************************************************************</font> +01693 +<a name="l01694"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c4">01694</a> <font class="keywordtype">void</font> CZoneLighter::excludeAllPatchFromRefineAll (CLandscape &landscape, vector<uint> &listZone, <font class="keywordtype">bool</font> exclude) +01695 { +01696 <font class="comment">// For each zone</font> +01697 <font class="keywordflow">for</font> (uint zone=0; zone<listZone.size(); zone++) +01698 { +01699 <font class="comment">// Get num patches</font> +01700 uint patchCount=landscape.getZone(listZone[zone])->getNumPatchs(); +01701 +01702 <font class="comment">// For each patches</font> +01703 <font class="keywordflow">for</font> (uint patch=0; patch<patchCount; patch++) +01704 { +01705 <font class="comment">// Exclude all the patches from refine all</font> +01706 landscape.excludePatchFromRefineAll (listZone[zone], patch, exclude); +01707 } +01708 } +01709 } +01710 +01711 <font class="comment">// ***************************************************************************</font> +01712 +<a name="l01713"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c3">01713</a> <font class="keywordtype">void</font> CZoneLighter::buildZoneInformation (CLandscape &landscape, <font class="keyword">const</font> vector<uint> &listZone, <font class="keywordtype">bool</font> oversampling, <font class="keyword">const</font> CLightDesc &lightDesc) +01714 { +01715 <font class="comment">// Bool visit</font> +01716 vector<vector<uint> > visited; +01717 +01718 <font class="comment">// Zone count</font> +01719 uint zoneCount=listZone.size(); +01720 +01721 <font class="comment">// Resize arries</font> +01722 <a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>.resize (zoneCount); +01723 <a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>.resize (zoneCount); +01724 <a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>.resize (zoneCount); +01725 <a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>.resize (zoneCount); +01726 +01727 <font class="comment">// For each zone</font> +01728 <font class="keywordflow">for</font> (uint zone=0; zone<zoneCount; zone++) +01729 { +01730 <font class="comment">// Get num patches</font> +01731 uint patchCount=landscape.getZone(listZone[zone])->getNumPatchs(); +01732 +01733 <font class="comment">// Insert zone id</font> +01734 <a class="code" href="classNL3D_1_1CZoneLighter.html#o31">_ZoneId</a>.insert (map<uint, uint>::value_type (listZone[zone], zone)); +01735 +01736 <font class="comment">// This is the zone to light ?</font> +01737 <font class="keywordflow">if</font> (listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) +01738 { +01739 <font class="comment">// Resize the arraies</font> +01740 <a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>.resize(patchCount); +01741 <font class="comment">// _BezierPatch.resize(patchCount);</font> +01742 <a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>.resize(patchCount); +01743 visited.resize(patchCount); +01744 } +01745 +01746 <font class="comment">// Common arries</font> +01747 <a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zone].resize(patchCount); +01748 <a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zone].resize(patchCount); +01749 <a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>[zone].resize(patchCount); +01750 <a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>[zone].resize(patchCount); +01751 +01752 <font class="comment">// For each patch</font> +01753 uint patch; +01754 <font class="keywordflow">for</font> (patch=0; patch<patchCount; patch++) +01755 { +01756 <font class="comment">// Get a patch pointer</font> +01757 <font class="keyword">const</font> CPatch* pPatch=(const_cast<const CZone*>(landscape.getZone(listZone[zone])))->getPatch (patch); +01758 +01759 <font class="comment">// Progress bar</font> +01760 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Scan all patches"</font>, (<font class="keywordtype">float</font>)patch/(<font class="keywordtype">float</font>)patchCount); +01761 +01762 <font class="comment">// Get pointer on arries</font> +01763 vector<bool> &binded=<a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zone][patch]; +01764 vector<CPatch::CBindInfo> &bindInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>[zone][patch]; +01765 vector<CPatchUVLocator> &locator=<a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zone][patch]; +01766 CBezierPatch &bezierPatch=<a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>[zone][patch]; +01767 binded.resize (4, <font class="keyword">false</font>); +01768 bindInfo.resize (4); +01769 locator.resize (4); +01770 +01771 <font class="comment">// Contruct the patch</font> +01772 bezierPatch=*pPatch->unpackIntoCache(); +01773 +01774 <font class="comment">// Same zone ?</font> +01775 <font class="keywordflow">if</font> (listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) +01776 { +01777 <font class="comment">// oversample this edge</font> +01778 <a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>[patch].resize (4, <font class="keyword">false</font>); +01779 } +01780 +01781 <font class="comment">// *** Build bind info</font> +01782 +01783 <font class="comment">// *** Build neighboorhood information</font> +01784 uint edge; +01785 <font class="keywordflow">for</font> (edge=0; edge<4; edge++) +01786 { +01787 <font class="comment">// Bond neighbor</font> +01788 pPatch->getBindNeighbor (edge, bindInfo[edge]); +01789 +01790 <font class="comment">// Patch binded</font> +01791 <font class="keywordflow">if</font> (bindInfo[edge].NPatchs>0) +01792 { +01793 <font class="comment">// This edeg is binded</font> +01794 binded[edge]=<font class="keyword">true</font>; +01795 +01796 <font class="comment">// Same zone ?</font> +01797 <font class="keywordflow">if</font> ((listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)&&(bindInfo[edge].Zone->getZoneId()!=<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)) +01798 { +01799 <font class="comment">// oversample this edge</font> +01800 <a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>[patch][edge]=<font class="keyword">true</font>; +01801 } +01802 locator[edge].build (pPatch, edge, bindInfo[edge]); +01803 } +01804 <font class="keywordflow">else</font> +01805 { +01806 <font class="keywordflow">if</font> (listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) +01807 { +01808 <font class="comment">// oversample this edge</font> +01809 <a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>[patch][edge]=<font class="keyword">true</font>; +01810 } +01811 } +01812 } +01813 +01814 <font class="comment">// This is the zone to light ?</font> +01815 <font class="keywordflow">if</font> (listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) +01816 { +01817 <font class="comment">// *** Resize lumel array for this patch</font> +01818 +01819 <font class="comment">// Get patch order</font> +01820 uint orderS=pPatch->getOrderS(); +01821 uint orderT=pPatch->getOrderT(); +01822 +01823 <font class="comment">// Number of lumels</font> +01824 uint lumelCount=orderS*orderT*16; +01825 +01826 <font class="comment">// Resize the lumel descriptor</font> +01827 CLumelDescriptor descriptor; +01828 descriptor.Normal.set (0,0,0); +01829 descriptor.Position.set (0,0,0); +01830 descriptor.S=0; +01831 descriptor.T=0; +01832 <a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch].resize (lumelCount, descriptor); +01833 visited[patch].resize (lumelCount, 0); +01834 +01835 <font class="comment">// *** Unexclude this patch</font> +01836 +01837 <font class="comment">// Exclude all the patches from refine all</font> +01838 landscape.excludePatchFromRefineAll (listZone[zone], patch, <font class="keyword">false</font>); +01839 } +01840 <font class="keywordflow">else</font> +01841 { +01842 <font class="comment">// Exclude all the patches from refine all</font> +01843 landscape.excludePatchFromRefineAll (listZone[zone], patch, <font class="keyword">true</font>); +01844 } +01845 } +01846 } +01847 +01848 <font class="comment">// *** Now tesselate this zone to shadow accuracy</font> +01849 +01850 <font class="comment">// Setup the landscape</font> +01851 landscape.setThreshold (0); +01852 landscape.setTileMaxSubdivision (0); +01853 +01854 <font class="comment">// Refine all</font> +01855 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Refine landscape to shadow accuracy"</font>, 0.5f); +01856 landscape.refineAll (CVector (0, 0, 0)); +01857 +01858 <font class="comment">// Get tesselated faces</font> +01859 std::vector<const CTessFace*> leaves; +01860 landscape.getTessellationLeaves(leaves); +01861 +01862 +01863 +01864 +01865 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.size() != 0) <font class="comment">// any water shape in this zone ?</font> +01866 { +01868 <a class="code" href="classNL3D_1_1CZoneLighter.html#c18">makeQuadGridFromWaterShapes</a>(landscape.getZone(_ZoneToLight)->getZoneBB().getAABBox()); +01869 +01871 <a class="code" href="classNL3D_1_1CZoneLighter.html#c19">computeTileFlagsForPositionTowardWater</a>(lightDesc, leaves); +01872 } +01873 <font class="keywordflow">else</font> +01874 { +01875 <a class="code" href="classNL3D_1_1CZoneLighter.html#c20">setTileFlagsToDefault</a>(leaves); +01876 } +01877 +01878 +01879 <font class="comment">// Id of this zone in the array</font> +01880 uint zoneNumber=<a class="code" href="classNL3D_1_1CZoneLighter.html#o31">_ZoneId</a>[<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>]; +01881 +01882 <font class="comment">// Scan each leaves</font> +01883 uint leavesCount=leaves.size(); +01884 uint leave; +01885 <font class="keywordflow">for</font> (leave=0; leave<leavesCount; leave++) +01886 { +01887 <font class="comment">// Progress bar</font> +01888 <font class="keywordflow">if</font> ( (leave&0xff) == 0) +01889 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Precompute lumel position"</font>, (<font class="keywordtype">float</font>)leave/(<font class="keywordtype">float</font>)leavesCount); +01890 +01891 <font class="comment">// Leave</font> +01892 <font class="keyword">const</font> CTessFace *face=leaves[leave]; +01893 +01894 <font class="comment">// Get zone id</font> +01895 <font class="keywordflow">if</font> (face->Patch->getZone()->getZoneId()==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) +01896 { +01897 <font class="comment">// Get a patch pointer</font> +01898 <font class="keyword">const</font> CPatch* pPatch=face->Patch; +01899 +01900 <font class="comment">// Get order</font> +01901 uint orderS=pPatch->getOrderS(); +01902 uint orderT=pPatch->getOrderT(); +01903 +01904 <font class="comment">// *** Base Coordinates</font> +01905 CVector pos[14]; +01906 pos[0]=face->VBase->EndPos; <font class="comment">// p0</font> +01907 pos[1]=face->VRight->EndPos; +01908 pos[2]=face->VLeft->EndPos; <font class="comment">// p2</font> +01909 pos[3]=(pos[1]+pos[2])/2; +01910 pos[4]=(pos[0]+pos[1])/2; <font class="comment">// p4</font> +01911 pos[5]=(pos[0]+pos[2])/2; +01912 pos[6]=(pos[0]+pos[3])/2; <font class="comment">// p6</font> +01913 pos[7]=(pos[2]+pos[3])/2; +01914 pos[8]=(pos[1]+pos[3])/2; <font class="comment">// p8</font> +01915 pos[9]=(pos[0]+pos[4])/2; +01916 pos[10]=(pos[1]+pos[4])/2; <font class="comment">// p10</font> +01917 pos[11]=(pos[0]+pos[5])/2; +01918 pos[12]=(pos[2]+pos[5])/2; <font class="comment">// p12</font> +01919 pos[13]=(pos[3]+pos[5])/2; +01920 pos[14]=(pos[3]+pos[4])/2; <font class="comment">// p14</font> +01921 +01922 <font class="keywordtype">float</font> s0=face->PVBase.getS(); +01923 <font class="keywordtype">float</font> s1=face->PVRight.getS(); +01924 <font class="keywordtype">float</font> s2=face->PVLeft.getS(); +01925 <font class="keywordtype">float</font> s3=(s1+s2)/2; +01926 <font class="keywordtype">float</font> s4=(s0+s1)/2; +01927 <font class="keywordtype">float</font> s5=(s0+s2)/2; +01928 <font class="keywordtype">float</font> s6=(s4+s5)/2; +01929 <font class="keywordtype">float</font> s7=(s2+s3)/2; +01930 <font class="keywordtype">float</font> s8=(s1+s3)/2; +01931 +01932 <font class="keywordtype">float</font> t0=face->PVBase.getT(); +01933 <font class="keywordtype">float</font> t1=face->PVRight.getT(); +01934 <font class="keywordtype">float</font> t2=face->PVLeft.getT(); +01935 <font class="keywordtype">float</font> t3=(t1+t2)/2; +01936 <font class="keywordtype">float</font> t4=(t0+t1)/2; +01937 <font class="keywordtype">float</font> t5=(t0+t2)/2; +01938 <font class="keywordtype">float</font> t6=(t4+t5)/2; +01939 <font class="keywordtype">float</font> t7=(t2+t3)/2; +01940 <font class="keywordtype">float</font> t8=(t1+t3)/2; +01941 +01942 <font class="comment">// *** Interpolated value</font> +01943 CVector interpolatedP[10]= +01944 { +01945 (pos[0]+pos[6])/2, +01946 (pos[4]+pos[6])/2, +01947 (pos[4]+pos[8])/2, +01948 (pos[1]+pos[8])/2, +01949 (pos[5]+pos[6])/2, +01950 (pos[3]+pos[6])/2, +01951 (pos[3]+pos[8])/2, +01952 (pos[5]+pos[7])/2, +01953 (pos[3]+pos[7])/2, +01954 (pos[2]+pos[7])/2, +01955 }; +01956 +01957 <font class="keywordtype">float</font> interpolatedS[10]= +01958 { +01959 (s0+s6)/2, +01960 (s4+s6)/2, +01961 (s4+s8)/2, +01962 (s1+s8)/2, +01963 (s5+s6)/2, +01964 (s3+s6)/2, +01965 (s3+s8)/2, +01966 (s5+s7)/2, +01967 (s3+s7)/2, +01968 (s2+s7)/2, +01969 }; +01970 +01971 <font class="keywordtype">float</font> interpolatedT[10]= +01972 { +01973 (t0+t6)/2, +01974 (t4+t6)/2, +01975 (t4+t8)/2, +01976 (t1+t8)/2, +01977 (t5+t6)/2, +01978 (t3+t6)/2, +01979 (t3+t8)/2, +01980 (t5+t7)/2, +01981 (t3+t7)/2, +01982 (t2+t7)/2, +01983 }; +01984 +01985 <font class="keyword">static</font> sint8 triangle[10][2][3]= +01986 { +01987 {{0, 11, 6}, {0, 6, 9}}, +01988 {{9, 6, 4}, {4, 6, 14}}, +01989 {{4, 14, 8}, {4, 8, 10}}, +01990 {{10, 8, 1}, {-1, -1, -1}}, +01991 {{11, 5, 6}, {5, 13, 6}}, +01992 {{6, 13, 3}, {6, 3, 14}}, +01993 {{3, 8, 14}, {-1, -1, -1}}, +01994 {{5, 12, 7}, {5, 7, 13}}, +01995 {{7, 3, 13}, {-1, -1, -1}}, +01996 {{12, 2, 7}, {-1, -1, -1}} +01997 }; +01998 +01999 <font class="keywordflow">for</font> (uint i=0; i<10; i++) +02000 { +02001 uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=(uint)((float)orderS*4*interpolatedS[i]); +02002 uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=(uint)((float)orderT*4*interpolatedT[i]); +02003 +02004 <font class="comment">/*nlassert (s>=0);</font> +02005 <font class="comment"> nlassert (s<orderS*4);</font> +02006 <font class="comment"> nlassert (t>=0);</font> +02007 <font class="comment"> nlassert (t<orderT*4);*/</font> +02008 +02009 <font class="keywordflow">if</font> ((<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>>=0)&&(s<orderS*4)&&(t>=0)&&(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><orderT*4)) +02010 { +02011 <font class="comment">// Triangle index</font> +02012 uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*orderS*4; +02013 +02014 <font class="comment">// Ge tthe patch id</font> +02015 uint patchId=pPatch->getPatchId(); +02016 +02017 <font class="comment">// Get lumel array</font> +02018 vector<CLumelDescriptor> &lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patchId]; +02019 +02020 <font class="comment">// Visited</font> +02021 visited[patchId][<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++; +02022 +02023 <font class="comment">// Position</font> +02024 lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].Position+=interpolatedP[i]; +02025 +02026 <font class="comment">// Triangle</font> +02027 <font class="keywordflow">if</font> (oversampling) +02028 { +02029 <font class="comment">// Triangle list</font> +02030 CTriangleList *next=lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].TriangleList; +02031 +02032 <font class="comment">// What triangle ?</font> +02033 uint numTriangle; +02034 <font class="keywordflow">switch</font> (i) +02035 { +02036 <font class="keywordflow">case</font> 3: +02037 <font class="keywordflow">case</font> 6: +02038 <font class="keywordflow">case</font> 8: +02039 <font class="keywordflow">case</font> 9: +02040 <font class="comment">// Single triangle</font> +02041 numTriangle=1; +02042 <font class="keywordflow">break</font>; +02043 <font class="keywordflow">default</font>: +02044 <font class="comment">// Two triangles</font> +02045 numTriangle=2; +02046 <font class="keywordflow">break</font>; +02047 } +02048 +02049 <font class="comment">// Add triangles</font> +02050 <font class="keywordflow">for</font> (uint tri=0; tri<numTriangle; tri++) +02051 { +02052 <font class="comment">// one triangle</font> +02053 lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].TriangleList=<a class="code" href="classNL3D_1_1CZoneLighter.html#o36">_TriangleListAllocateur</a>.<a class="code" href="classNLMISC_1_1CPoolMemory.html#a1">allocate</a> (); +02054 lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].TriangleList->Triangle=<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (pos[triangle[i][tri][0]], pos[triangle[i][tri][1]], pos[triangle[i][tri][2]]); +02055 lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].TriangleList->Next=next; +02056 } +02057 } +02058 } +02059 } +02060 } +02061 } +02062 +02063 <font class="comment">// *** Now, finalise patch informations for shadow source positions</font> +02064 +02065 <font class="comment">// For each patches</font> +02066 uint patchCount=landscape.getZone(_ZoneToLight)->getNumPatchs(); +02067 uint patch; +02068 <font class="keywordflow">for</font> (patch=0; patch<patchCount; patch++) +02069 { +02070 <font class="comment">// Info</font> +02071 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Finalize lumel positions"</font>, (<font class="keywordtype">float</font>)patch/(<font class="keywordtype">float</font>)patchCount); +02072 +02073 <font class="comment">// *** Resize lumel array for this patch</font> +02074 +02075 <font class="comment">// Get a patch pointer</font> +02076 <font class="keyword">const</font> CPatch* pPatch=(const_cast<const CZone*>(landscape.getZone(<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)))->getPatch (patch); +02077 uint orderS=pPatch->getOrderS(); +02078 uint orderT=pPatch->getOrderT(); +02079 +02080 <font class="comment">// Get lumel array</font> +02081 vector<CLumelDescriptor> &lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch]; +02082 +02083 <font class="comment">// *** Compute an interpolated normal</font> +02084 +02085 <font class="comment">// Renormalize</font> +02086 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a> (orderS)); +02087 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a> (orderT)); +02088 uint powerS=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (orderS); +02089 uint powerT=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (orderT); +02090 uint lumelS=4<<powerS; +02091 uint lumelT=4<<powerT; +02092 +02093 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><lumelT; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>++) +02094 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a><lumelS; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>++) +02095 { +02096 <font class="comment">// Lumel index</font> +02097 uint lumelIndex=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*lumelS; +02098 +02099 <font class="comment">// *** Number of visit</font> +02100 uint visitedCount=visited[patch][lumelIndex]; +02101 +02102 <font class="comment">// Some lumel have not been found in tesselation</font> +02103 <font class="comment">//nlassert ((visitedCount==1)||(visitedCount==2));</font> +02104 +02105 <font class="comment">// If visited, renormalise other values</font> +02106 <font class="keywordflow">if</font> (visitedCount) +02107 { +02108 <font class="comment">// Normalise position</font> +02109 lumels[lumelIndex].Position/=(float)visitedCount; +02110 } +02111 +02112 <font class="comment">// Not visited for next pass</font> +02113 visited[patch][lumelIndex]=<font class="keyword">false</font>; +02114 } +02115 } +02116 +02117 <font class="comment">// *** Now tesselate this zone to shadow accuracy</font> +02118 +02119 <font class="comment">// Setup the landscape</font> +02120 landscape.setThreshold (0); +02121 landscape.setTileMaxSubdivision (4); +02122 +02123 <font class="comment">// Refine all</font> +02124 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Refine landscape to lumels"</font>, 0.5f); +02125 landscape.refineAll (CVector (0, 0, 0)); +02126 +02127 <font class="comment">// Get tesselated faces</font> +02128 leaves.clear (); +02129 landscape.getTessellationLeaves(leaves); +02130 +02131 <font class="comment">// Scan each leaves</font> +02132 leavesCount=leaves.size(); +02133 <font class="keywordflow">for</font> (leave=0; leave<leavesCount; leave++) +02134 { +02135 <font class="comment">// Progress bar</font> +02136 <font class="keywordflow">if</font> ( (leave&0xff) == 0) +02137 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Precompute tesselation"</font>, (<font class="keywordtype">float</font>)leave/(<font class="keywordtype">float</font>)leavesCount); +02138 +02139 <font class="comment">// Leave</font> +02140 <font class="keyword">const</font> CTessFace *face=leaves[leave]; +02141 +02142 <font class="comment">// Get zone id</font> +02143 <font class="keywordflow">if</font> (face->Patch->getZone()->getZoneId()==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) +02144 { +02145 <font class="comment">// Get a patch pointer</font> +02146 <font class="keyword">const</font> CPatch* pPatch=face->Patch; +02147 +02148 <font class="comment">// Get order</font> +02149 uint orderS=pPatch->getOrderS(); +02150 uint orderT=pPatch->getOrderT(); +02151 +02152 <font class="comment">// Coordinates</font> +02153 <font class="keywordtype">float</font> fS=(face->PVBase.getS()+face->PVLeft.getS()+face->PVRight.getS())/3.f; +02154 <font class="keywordtype">float</font> fT=(face->PVBase.getT()+face->PVLeft.getT()+face->PVRight.getT())/3.f; +02155 uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=(uint)((float)orderS*4*fS); +02156 uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=(uint)((float)orderT*4*fT); +02157 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>>=0); +02158 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a><orderS*4); +02159 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>>=0); +02160 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><orderT*4); +02161 +02162 <font class="comment">// Triangle index</font> +02163 uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*orderS*4; +02164 +02165 <font class="comment">// Ge tthe patch id</font> +02166 uint patchId=pPatch->getPatchId(); +02167 +02168 <font class="comment">// Get lumel array</font> +02169 vector<CLumelDescriptor> &lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patchId]; +02170 +02171 <font class="comment">// Visited</font> +02172 visited[patchId][<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++; +02173 +02174 <font class="comment">// Lumel s and t</font> +02175 lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].S+=fS; +02176 lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].T+=fT; +02177 +02178 <font class="comment">// Normal</font> +02179 CPlane plane; +02180 plane.make (face->VBase->EndPos, face->VLeft->EndPos, face->VRight->EndPos); +02181 lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].Normal+=plane.getNormal(); +02182 } +02183 } +02184 +02185 <font class="comment">// *** Now, finalise patch informations</font> +02186 +02187 <font class="comment">// For each patches</font> +02188 patchCount=landscape.getZone(_ZoneToLight)->getNumPatchs(); +02189 <font class="keywordflow">for</font> (patch=0; patch<patchCount; patch++) +02190 { +02191 <font class="comment">// Info</font> +02192 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Finalize patches"</font>, (<font class="keywordtype">float</font>)patch/(<font class="keywordtype">float</font>)patchCount); +02193 +02194 <font class="comment">// *** Resize lumel array for this patch</font> +02195 +02196 <font class="comment">// Get a patch pointer</font> +02197 <font class="keyword">const</font> CPatch* pPatch=(const_cast<const CZone*>(landscape.getZone(<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)))->getPatch (patch); +02198 uint orderS=pPatch->getOrderS(); +02199 uint orderT=pPatch->getOrderT(); +02200 +02201 <font class="comment">// Get lumel array</font> +02202 vector<CLumelDescriptor> &lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch]; +02203 +02204 <font class="comment">// *** Compute an interpolated normal</font> +02205 +02206 <font class="comment">// Get pointer on arries</font> +02207 vector<bool> &binded=<a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zoneNumber][patch]; +02208 vector<CPatchUVLocator> &locator=<a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zoneNumber][patch]; +02209 vector<CPatch::CBindInfo> &bindInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>[zoneNumber][patch]; +02210 CBezierPatch &bezierPatch=<a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>[zoneNumber][patch]; +02211 +02212 <font class="comment">// Renormalize</font> +02213 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a> (orderS)); +02214 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a> (orderT)); +02215 uint powerS=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (orderS); +02216 uint powerT=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (orderT); +02217 uint lumelS=4<<powerS; +02218 uint lumelT=4<<powerT; +02219 +02220 <font class="comment">// Sample edge normal</font> +02221 CVector normals[<a class="code" href="patch_8h.html#a1">NL_MAX_TILES_BY_PATCH_EDGE</a>*<a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>+1][4]; +02222 uint sFixed[4] = { 0, 0xffffffff, lumelS-1, 0xffffffff }; +02223 uint tFixed[4] = { 0xffffffff, lumelT-1, 0xffffffff, 0 }; +02224 <font class="keywordtype">float</font> sOri[4] = { 0, -1, (float)lumelS, -1 }; +02225 <font class="keywordtype">float</font> tOri[4] = { -1, (float)lumelT, -1, 0 }; +02226 <font class="keywordflow">for</font> (uint edge=0; edge<4; edge++) +02227 { +02228 <font class="comment">// s and t</font> +02229 uint count=(edge&1)?lumelS:lumelT; +02230 <font class="keywordflow">for</font> (uint lumel=0; lumel<=count; lumel++) +02231 { +02232 <font class="comment">// Start coordinates</font> +02233 <font class="keywordtype">float</font> origineS; +02234 <font class="keywordtype">float</font> origineT; +02235 uint startS; +02236 uint startT; +02237 <font class="keywordflow">if</font> (edge&1) +02238 { +02239 <font class="keywordflow">if</font> (lumel==count) +02240 startS=count-1; +02241 <font class="keywordflow">else</font> +02242 startS=lumel; +02243 startT=tFixed[edge]; +02244 origineS=(float)lumel; +02245 origineT=tOri[edge]; +02246 } +02247 <font class="keywordflow">else</font> +02248 { +02249 <font class="keywordflow">if</font> (lumel==count) +02250 startT=count-1; +02251 <font class="keywordflow">else</font> +02252 startT=lumel; +02253 startS=sFixed[edge]; +02254 origineT=(float)lumel; +02255 origineS=sOri[edge]; +02256 } +02257 <a class="code" href="classNL3D_1_1CZoneLighter.html#o33">_GetNormalNormal</a>=CVector::Null; +02258 set<uint64> visitedLumels; +02259 <a class="code" href="classNL3D_1_1CZoneLighter.html#c10">getNormal</a> (pPatch, startS, startT, locator, bindInfo, binded, visitedLumels, +02260 startS+0.5f-origineS, startT+0.5f-origineT, 0, bezierPatch); +02261 <a class="code" href="classNL3D_1_1CZoneLighter.html#o33">_GetNormalNormal</a>.<a class="code" href="classNLMISC_1_1CVector.html#z331_4">normalize</a> (); +02262 normals[lumel][edge]=<a class="code" href="classNL3D_1_1CZoneLighter.html#o33">_GetNormalNormal</a>; +02263 } +02264 +02265 <font class="comment">// Smooth the corners</font> +02266 <font class="preprocessor">#define BLUR_SIZE 4</font> +02267 <font class="preprocessor"></font> <font class="keywordflow">for</font> (uint i=1; i<BLUR_SIZE; i++) +02268 { +02269 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=(float)i/BLUR_SIZE; +02270 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>); +02271 normals[i][edge]=normals[0][edge]*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)+normals[i][edge]*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>; +02272 normals[i][edge].normalize(); +02273 normals[count-i][edge]=normals[count][edge]*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)+normals[count-i][edge]*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>; +02274 normals[count-i][edge].normalize(); +02275 } +02276 } +02277 +02278 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><lumelT; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>++) +02279 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a><lumelS; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>++) +02280 { +02281 <font class="comment">// Lumel index</font> +02282 uint lumelIndex=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*lumelS; +02283 +02284 <font class="comment">// *** Calc the smoothed normal</font> +02285 +02286 <font class="comment">// For each edge</font> +02287 CVector normalS=bezierPatch.evalNormal (((<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f)/(<font class="keywordtype">float</font>)lumelS, ((<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f)/(<font class="keywordtype">float</font>)lumelT); +02288 <font class="keywordtype">float</font> sFactor=0; +02289 CVector normalT=normalS; +02290 <font class="keywordtype">float</font> tFactor=0; +02291 <font class="keywordtype">bool</font> sGood=<font class="keyword">false</font>, tGood=<font class="keyword">false</font>; +02292 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a><BLUR_SIZE) +02293 { +02294 sGood=<font class="keyword">true</font>; +02295 <font class="comment">// Average the two normals</font> +02296 CVector average=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>][0]; +02297 average+=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+1][0]; +02298 average/=2; +02299 +02300 <font class="comment">// Blend</font> +02301 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f; +02302 sFactor=BLUR_SIZE-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>; +02303 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>/=BLUR_SIZE; +02304 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>); +02305 normalS=(normalS*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>+average*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)); +02306 normalS.normalize(); +02307 } +02308 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>>=lumelS-BLUR_SIZE) +02309 { +02310 sGood=<font class="keyword">true</font>; +02311 <font class="comment">// Average the two normals</font> +02312 CVector average=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>][2]; +02313 average+=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+1][2]; +02314 average/=2; +02315 +02316 <font class="comment">// Blend</font> +02317 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f; +02318 sFactor=BLUR_SIZE-(lumelS-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>); +02319 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=(lumelS-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)/BLUR_SIZE; +02320 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>); +02321 normalS=(normalS*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>+average*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)); +02322 normalS.normalize(); +02323 } +02324 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><BLUR_SIZE) +02325 { +02326 tGood=<font class="keyword">true</font>; +02327 <font class="comment">// Average the two normals</font> +02328 CVector average=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>][3]; +02329 average+=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+1][3]; +02330 average/=2; +02331 +02332 <font class="comment">// Blend</font> +02333 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f; +02334 tFactor=BLUR_SIZE-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>; +02335 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>/=BLUR_SIZE; +02336 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>); +02337 normalT=(normalT*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>+average*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)); +02338 normalT.normalize(); +02339 } +02340 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>>=lumelT-BLUR_SIZE) +02341 { +02342 tGood=<font class="keyword">true</font>; +02343 <font class="comment">// Average the two normals</font> +02344 CVector average=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>][1]; +02345 average+=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+1][1]; +02346 average/=2; +02347 +02348 <font class="comment">// Blend</font> +02349 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f; +02350 tFactor=BLUR_SIZE-(lumelT-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>); +02351 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=((lumelT)-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)/BLUR_SIZE; +02352 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>); +02353 normalT=(normalT*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>+average*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)); +02354 normalT.normalize(); +02355 } +02356 +02357 <font class="comment">// The smooth normal</font> +02358 CVector smoothNormal; +02359 +02360 <font class="keywordflow">if</font> ((sGood)&&(tGood)) +02361 { +02362 <font class="keywordflow">if</font> ((sFactor!=BLUR_SIZE)||(tFactor!=BLUR_SIZE)) +02363 smoothNormal=normalS*(BLUR_SIZE-tFactor)+normalT*(BLUR_SIZE-sFactor); +02364 <font class="keywordflow">else</font> +02365 smoothNormal=normalS+normalT; +02366 } +02367 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (sGood) +02368 smoothNormal=normalS; +02369 <font class="keywordflow">else</font> +02370 smoothNormal=normalT; +02371 +02372 <font class="comment">// Normalize it</font> +02373 smoothNormal.normalize(); +02374 +02375 <font class="comment">// The pure normal</font> +02376 CVector purNormal=bezierPatch.evalNormal (((<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f)/(<font class="keywordtype">float</font>)lumelS, ((<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f)/(<font class="keywordtype">float</font>)lumelT); +02377 +02378 <font class="comment">// Normalize the noisy normal</font> +02379 lumels[lumelIndex].Normal.normalize(); +02380 +02381 <font class="comment">// Final normal</font> +02382 lumels[lumelIndex].Normal=lumels[lumelIndex].Normal-purNormal+smoothNormal; +02383 lumels[lumelIndex].Normal.normalize (); +02384 +02385 <font class="comment">// *** Number of visit</font> +02386 uint visitedCount=visited[patch][lumelIndex]; +02387 +02388 <font class="comment">// Some lumel have not been found in tesselation</font> +02389 <font class="comment">//nlassert (visitedCount==2);</font> +02390 +02391 <font class="comment">// If visited, renormalise other values</font> +02392 <font class="keywordflow">if</font> (visitedCount) +02393 { +02394 <font class="comment">// Normalise position</font> +02395 lumels[lumelIndex].S/=(float)visitedCount; +02396 lumels[lumelIndex].T/=(float)visitedCount; +02397 } +02398 } +02399 } +02400 } +02401 +02402 <font class="comment">// ***************************************************************************</font> +02403 +<a name="l02404"></a><a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#a0">02404</a> CZoneLighter::CLightDesc::CLightDesc () +02405 { +02406 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m0">LightDirection</a>.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a> (1, 1, -1); +02407 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m2">GridSize</a>=512; +02408 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m3">GridCellSize</a>=4; +02409 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m4">HeightfieldSize</a>=200; +02410 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m5">HeightfieldCellSize</a>=20; +02411 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m13">SkyContribution</a>=<font class="keyword">true</font>; +02412 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m14">SkyIntensity</a>=0.25; +02413 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m7">ShadowBias</a>=0.5f; +02414 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m9">SoftshadowBlurSize</a>=1.f; +02415 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m10">SoftshadowFallof</a>=10.f; +02416 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m11">SoftshadowShapeVertexCount</a>=4; +02417 <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m1">Oversampling</a>=<a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#s5s3">OverSamplingx32</a>; +02418 } +02419 +02420 <font class="comment">// ***************************************************************************</font> +<a name="l02421"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a6">02421</a> <font class="keywordtype">void</font> CZoneLighter::addLightableShape(IShape *shape, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a>& MT) +02422 { +02423 CShapeInfo lsi; +02424 lsi.MT = MT; +02425 lsi.Shape = shape; +02426 <a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.push_back(lsi); +02427 } +02428 +02429 +02430 <font class="comment">// ***************************************************************************</font> +<a name="l02431"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#d0">02431</a> <font class="keywordtype">bool</font> CZoneLighter::isLightableShape(IShape &shape) +02432 { +02434 <font class="keywordflow">if</font> (dynamic_cast<CWaterShape *>(&shape) != NULL) +02435 { +02436 <font class="comment">// check that this water surface has a diffuse map that is a CTextureFile (we must be able to save it !)</font> +02437 CWaterShape *ws = static_cast<CWaterShape *>(&shape); +02438 <font class="keyword">const</font> ITexture *tex = ws->getColorMap(); +02439 <font class="keywordflow">if</font> (dynamic_cast<const CTextureFile *>(tex) != NULL) +02440 { +02441 <font class="keywordflow">return</font> ws->isLightMappingEnabled(); +02442 } +02443 } +02444 <font class="keywordflow">return</font> <font class="keyword">false</font>; +02445 } +02446 +02447 <font class="comment">// ***************************************************************************</font> +<a name="l02448"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c14">02448</a> <font class="keywordtype">void</font> CZoneLighter::lightShapes(uint zoneID, <font class="keyword">const</font> CLightDesc& description) +02449 { +02451 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size() == 0) <font class="keywordflow">return</font>; +02452 +02453 uint numShapePerThread = 1 + (<a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size() / <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>); +02454 uint currShapeIndex = 0; +02455 uint process = 0; +02456 <a class="code" href="classNL3D_1_1CZoneLighter.html#o14">_ProcessExited</a> = 0; +02457 +02458 <a class="code" href="classNL3D_1_1CZoneLighter.html#o39">_NumLightableShapesProcessed</a> = 0; +02459 +02460 +02461 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Processing lightable shapes"</font>, 0); +02462 +02463 <font class="keywordflow">for</font> (uint k = 0; k < <a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size(); ++k, ++process) +02464 { +02465 uint lastShapeIndex = currShapeIndex + numShapePerThread; +02466 lastShapeIndex = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size(), lastShapeIndex); +02467 IThread *pThread = IThread::create (<font class="keyword">new</font> <a class="code" href="classNL3D_1_1CZoneLighter.html#l1">CCalcLightableShapeRunnable</a>(process, <font class="keyword">this</font>, &description, &<a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>, currShapeIndex, lastShapeIndex)); +02468 pThread->start(); +02469 currShapeIndex = lastShapeIndex; +02470 } +02471 +02473 <font class="keywordflow">while</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o14">_ProcessExited</a> != <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>) +02474 { +02475 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (10); +02476 } +02477 +02478 } +02479 +02480 +02481 +02482 <font class="comment">// ***************************************************************************</font> +02483 +<a name="l02484"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c15">02484</a> <font class="keywordtype">void</font> CZoneLighter::processLightableShapeCalc (uint process, +02485 TShapeVect *shapesToLit, +02486 uint firstShape, +02487 uint lastShape, +02488 <font class="keyword">const</font> CLightDesc& description) +02489 { +02490 CMultiShape *shapeArray=<font class="keyword">new</font> CMultiShape; +02491 CMultiShape *shapeArrayTmp=<font class="keyword">new</font> CMultiShape; +02492 shapeArray->Shapes.reserve (<a class="code" href="zone__lighter_8h.html#a1">SHAPE_MAX</a>); +02493 shapeArrayTmp->Shapes.reserve (<a class="code" href="zone__lighter_8h.html#a1">SHAPE_MAX</a>); +02494 +02495 <font class="comment">// for each lightable shape</font> +02496 <font class="keywordflow">for</font> (uint k = firstShape; k < lastShape; ++k) +02497 { +02498 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#d0">isLightableShape</a>(* (*shapesToLit)[k].Shape)); <font class="comment">// make sure it is a lightable shape </font> +02499 <a class="code" href="classNL3D_1_1CZoneLighter.html#c16">lightSingleShape</a>((*shapesToLit)[k], *shapeArray, *shapeArrayTmp, description, process); +02500 } +02501 +02502 <font class="keyword">delete</font> shapeArray; +02503 <font class="keyword">delete</font> shapeArrayTmp; +02504 } +02505 +02506 +02507 <font class="comment">// ***************************************************************************</font> +<a name="l02508"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c16">02508</a> <font class="keywordtype">void</font> CZoneLighter::lightSingleShape(CShapeInfo &si, CMultiShape &shape, CMultiShape &shapeTmp, <font class="keyword">const</font> CLightDesc& description, uint cpu) +02509 { +02511 <font class="keywordflow">if</font> (dynamic_cast<CWaterShape *>(si.Shape)) +02512 { +02513 <a class="code" href="classNL3D_1_1CZoneLighter.html#c17">lightWater</a>(* static_cast<CWaterShape *>(si.Shape), si.MT, shape, shapeTmp, description, cpu); +02514 +02515 } +02516 ++<a class="code" href="classNL3D_1_1CZoneLighter.html#o39">_NumLightableShapesProcessed</a>; +02517 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Processing lightable shapes"</font>, (<font class="keywordtype">float</font>) <a class="code" href="classNL3D_1_1CZoneLighter.html#o39">_NumLightableShapesProcessed</a> / <a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size()); +02518 <font class="keywordflow">return</font>; +02519 } +02520 +02521 +02522 +02523 <font class="comment">// ***************************************************************************</font> +02524 <font class="comment">// utility function to get the directory of a fileName</font> +<a name="l02525"></a><a class="code" href="zone__lighter_8cpp.html#a10">02525</a> <font class="keyword">static</font> std::string <a class="code" href="zone__lighter_8cpp.html#a10">getDir</a> (<font class="keyword">const</font> std::string& path) +02526 { +02527 <font class="keywordtype">char</font> tmpPath[512]; +02528 strcpy (tmpPath, path.c_str()); +02529 <font class="keywordtype">char</font>* slash=strrchr (tmpPath, <font class="charliteral">'/'</font>); +02530 <font class="keywordflow">if</font> (!slash) +02531 { +02532 slash=strrchr (tmpPath, <font class="charliteral">'\\'</font>); +02533 } +02534 +02535 <font class="keywordflow">if</font> (!slash) +02536 <font class="keywordflow">return</font> <font class="stringliteral">""</font>; +02537 +02538 slash++; +02539 *slash=0; +02540 <font class="keywordflow">return</font> tmpPath; +02541 } +02542 +02543 +02544 <font class="comment">// ***************************************************************************</font> +02545 <font class="comment">// utility function to get a file name fdrom a path</font> +<a name="l02546"></a><a class="code" href="zone__lighter_8cpp.html#a11">02546</a> <font class="keyword">static</font> std::string <a class="code" href="zone__lighter_8cpp.html#a11">getName</a> (<font class="keyword">const</font> std::string& path) +02547 { +02548 std::string dir=<a class="code" href="zone__lighter_8cpp.html#a10">getDir</a> (path); +02549 +02550 <font class="keywordtype">char</font> tmpPath[512]; +02551 strcpy (tmpPath, path.c_str()); +02552 +02553 <font class="keywordtype">char</font> *name=tmpPath; +02554 <a class="code" href="debug_8h.html#a6">nlassert</a> (dir.length()<=strlen(tmpPath)); +02555 name+=dir.length(); +02556 +02557 <font class="keywordtype">char</font>* point=strrchr (name, <font class="charliteral">'.'</font>); +02558 <font class="keywordflow">if</font> (point) +02559 *point=0; +02560 +02561 <font class="keywordflow">return</font> name; +02562 } +02563 +02564 +02565 <font class="comment">// ***************************************************************************</font> +02566 <font class="comment">// utility function to get the extension of a fileName</font> +<a name="l02567"></a><a class="code" href="zone__lighter_8cpp.html#a12">02567</a> <font class="keyword">static</font> std::string <a class="code" href="zone__lighter_8cpp.html#a12">getExt</a> (<font class="keyword">const</font> std::string& path) +02568 { +02569 std::string dir = <a class="code" href="zone__lighter_8cpp.html#a10">getDir</a> (path); +02570 std::string name = <a class="code" href="zone__lighter_8cpp.html#a11">getName</a> (path); +02571 +02572 <font class="keywordtype">char</font> tmpPath[512]; +02573 strcpy (tmpPath, path.c_str()); +02574 +02575 <font class="keywordtype">char</font> *ext=tmpPath; +02576 <a class="code" href="debug_8h.html#a6">nlassert</a> (dir.length()+name.length()<=strlen(tmpPath)); +02577 ext+=dir.length()+name.length(); +02578 +02579 <font class="keywordflow">return</font> ext; +02580 } +02581 +02582 +02583 <font class="comment">// ***************************************************************************</font> +<a name="l02584"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c17">02584</a> <font class="keywordtype">void</font> CZoneLighter::lightWater(CWaterShape &ws, <font class="keyword">const</font> CMatrix &MT, CMultiShape &shape, CMultiShape &shapeTmp, <font class="keyword">const</font> CLightDesc& description, uint cpu) +02585 { +02586 <font class="keywordflow">try</font> +02587 { +02589 CTextureFile *diffuseTex = NLMISC::safe_cast<CTextureFile *>(ws.getColorMap()); +02590 std::string texFileName = CPath::lookup(diffuseTex->getFileName()); +02591 diffuseTex->generate(); +02592 <font class="keyword">const</font> uint <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a> = diffuseTex->getWidth(); +02593 <font class="keyword">const</font> uint <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a> = diffuseTex->getHeight(); +02594 +02596 <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> worldSpaceToUVs; +02597 <a class="code" href="classNLMISC_1_1CVector2f.html">NLMISC::CVector2f</a> col0, col1, pos; +02598 ws.getColorMapMat(col0, col1, pos); +02599 worldSpaceToUVs.<a class="code" href="classNLMISC_1_1CMatrix.html#z290_1">setRot</a>(<a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>(col0.<a class="code" href="classNLMISC_1_1CVector2f.html#m0">x</a> * <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, col0.<a class="code" href="classNLMISC_1_1CVector2f.html#m1">y</a> * <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, 0), +02600 <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>(col1.<a class="code" href="classNLMISC_1_1CVector2f.html#m0">x</a> * width, col1.<a class="code" href="classNLMISC_1_1CVector2f.html#m1">y</a> * <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, 0), +02601 <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>); +02602 worldSpaceToUVs.<a class="code" href="classNLMISC_1_1CMatrix.html#z290_6">setPos</a>(<a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>(pos.<a class="code" href="classNLMISC_1_1CVector2f.html#m0">x</a> * width, pos.<a class="code" href="classNLMISC_1_1CVector2f.html#m1">y</a> * <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, 0)); +02603 +02605 <a class="code" href="classNLMISC_1_1CPolygon.html">NLMISC::CPolygon</a> p; +02606 ws.getShapeInWorldSpace(p); +02607 +02608 <font class="keywordtype">float</font> minU, maxU; +02609 <font class="keywordtype">float</font> minV, maxV; +02610 +02611 <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> uvs = worldSpaceToUVs * p.<a class="code" href="classNLMISC_1_1CPolygon.html#m0">Vertices</a>[0]; +02612 minU = maxU = uvs.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>; +02613 minV = maxV = uvs.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>; +02614 +02615 +02616 <font class="keywordflow">for</font> (uint k = 1; k < (uint) p.<a class="code" href="classNLMISC_1_1CPolygon.html#a2">getNumVertices</a>(); ++k) +02617 { +02618 uvs = worldSpaceToUVs * p.<a class="code" href="classNLMISC_1_1CPolygon.html#m0">Vertices</a>[k]; +02619 minU = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(uvs.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, minU); +02620 minV = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(uvs.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>, minV); +02621 maxU = std::max(uvs.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, maxU); +02622 maxV = std::max(uvs.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>, maxV); +02623 } +02624 +02625 +02626 +02627 +02628 sint iMinU = (sint) minU; +02629 sint iMaxU = (sint) maxU; +02630 sint iMinV = (sint) minV; +02631 sint iMaxV = (sint) maxV; +02632 +02633 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(iMinU, 0, (sint) width); +02634 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(iMaxU, 0, (sint) width); +02635 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(iMinV, 0, (sint) <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>); +02636 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(iMaxV, 0, (sint) <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>); +02637 +02638 <font class="comment">// matrix to go from uv space to worldspace</font> +02639 <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> UVSpaceToWorldSpace = worldSpaceToUVs.<a class="code" href="classNLMISC_1_1CMatrix.html#z293_7">inverted</a>(); +02640 +02641 std::vector<uint8> &pixs8 = diffuseTex->getPixels(); +02642 <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> *rgbPixs = (<a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> *) &pixs8[0]; +02643 +02644 +02646 <font class="keywordflow">for</font> (sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = iMinU; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> < iMaxU; ++<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>) +02647 { +02648 <font class="keywordflow">for</font> (sint <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = iMinV; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> < iMaxV; ++<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>) +02649 { +02650 <font class="keywordtype">float</font> factor; +02651 <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> pos = UVSpaceToWorldSpace * <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>( <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> + 0.5f, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> + 0.5f, 0 ) +02652 + description.WaterShadowBias * <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>; +02653 <font class="keywordflow">if</font> (description.Shadow) +02654 { +02655 <a class="code" href="classNL3D_1_1CZoneLighter.html#c9">rayTrace</a>(pos, <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>, 0, 0, -1, factor, shape, shapeTmp, cpu); +02656 } +02657 <font class="keywordflow">else</font> +02658 { +02659 factor = - <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a> * description.LightDirection; +02660 } +02661 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(factor, 0.f, 1.f); +02662 factor = factor * description.WaterDiffuse + description.WaterAmbient; +02663 <font class="keywordflow">if</font> (description.SkyContributionForWater) +02664 { +02665 factor += <a class="code" href="classNL3D_1_1CZoneLighter.html#c7">getSkyContribution</a>(pos, <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>, description.SkyIntensity); +02666 } +02667 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(factor, 0.f, 1.f); +02668 uint intensity = (uint8) (255 * factor); +02669 <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> srcCol(intensity, +02670 intensity, +02671 intensity, +02672 255); +02673 +02674 <font class="keywordflow">if</font> (!description.ModulateWaterColor) +02675 { +02676 rgbPixs[<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> + <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> * width] = srcCol; +02677 } +02678 <font class="keywordflow">else</font> +02679 { +02680 <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> &col = rgbPixs[<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> + <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> * width]; +02681 col.<a class="code" href="classNLMISC_1_1CRGBA.html#a9">modulateFromColor</a>(col, srcCol); +02682 } +02683 } +02684 } +02685 +02687 <font class="keywordflow">if</font> (<a class="code" href="zone__lighter_8cpp.html#a12">getExt</a>(texFileName) != <font class="stringliteral">".tga"</font>) +02688 { +02689 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Zone lighter : error when lighting a water surface : input bitmap is not a tga file"</font>); +02690 } +02691 <font class="keywordflow">else</font> +02692 { +02693 <font class="keywordflow">try</font> +02694 { +02695 COFile of; +02696 of.open(texFileName); +02697 diffuseTex->writeTGA(of, 24); +02698 of.close(); +02699 } +02700 <font class="keywordflow">catch</font> (<a class="code" href="classNLMISC_1_1Exception.html">NLMISC::Exception</a> &) +02701 { +02702 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Zone lighter : while lighting a water shape, writing %s failed! "</font>, texFileName.c_str()); +02703 } +02704 } +02705 } +02706 <font class="keywordflow">catch</font>(<a class="code" href="classNLMISC_1_1Exception.html">NLMISC::Exception</a> &e) +02707 { +02708 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Water shape lighting failed !"</font>); +02709 <a class="code" href="debug_8h.html#a2">nlwarning</a>(e.what()); +02710 } +02711 } +02712 +<a name="l02714"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a7">02714</a> <font class="keywordtype">void</font> CZoneLighter::addWaterShape(CWaterShape *shape, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> &MT) +02715 { +02717 CShapeInfo ci; +02718 ci.Shape = shape; +02719 ci.MT = MT; +02720 <a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.push_back(ci); +02721 } +02722 +<a name="l02724"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c18">02724</a> <font class="keywordtype">void</font> CZoneLighter::makeQuadGridFromWaterShapes(<a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> zoneBBox) +02725 { +02726 <font class="keywordflow">if</font> (!<a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.size()) <font class="keywordflow">return</font>; +02727 +02728 <a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> tmpBox; +02729 +02731 <font class="keyword">const</font> uint numCells = 16; +02732 +02734 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a> = zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_1">getMax</a>().x - zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_0">getMin</a>().x; +02735 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a> = zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_1">getMax</a>().y - zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_0">getMin</a>().y; +02736 +02737 <font class="keywordtype">float</font> dim = std::max(<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>); +02738 +02739 +02741 <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.create(numCells, dim / numCells); +02742 +02743 +02744 uint count = 0, totalCount = <a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.size(); +02745 +02747 <font class="keywordflow">for</font> (TShapeVect::iterator it = <a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.begin(); it != <a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.end(); ++it, ++count) +02748 { +02750 it->Shape->getAABBox(tmpBox); +02751 <a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> currBB = <a class="code" href="classNLMISC_1_1CAABBox.html#z266_3">NLMISC::CAABBox::transformAABBox</a>(it->MT, tmpBox); +02752 +02754 <font class="keywordflow">if</font> (zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z265_4">intersect</a>(currBB)) +02755 { +02756 <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.insert(currBB.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_0">getMin</a>(), currBB.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_1">getMax</a>(), NLMISC::safe_cast<CWaterShape *>(it->Shape)); +02757 } +02758 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Building quadtree from water surfaces"</font>, (<font class="keywordtype">float</font>) count / totalCount); +02759 } +02760 +02762 <a class="code" href="namespaceNLMISC.html#a222">NLMISC::contReset</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>); +02763 } +02764 +02765 +02766 <font class="comment">//==================================================================</font> +02767 +<a name="l02769"></a><a class="code" href="structCTileOfPatch.html">02769</a> <font class="keyword">struct </font><a class="code" href="structCTileOfPatch.html">CTileOfPatch</a> +02770 { +<a name="l02771"></a><a class="code" href="structCTileOfPatch.html#m0">02771</a> uint8 TileId; +<a name="l02772"></a><a class="code" href="structCTileOfPatch.html#m1">02772</a> CPatch *Patch; +02773 <a class="code" href="structCTileOfPatch.html">CTileOfPatch</a>(); +<a name="l02774"></a><a class="code" href="structCTileOfPatch.html#a1">02774</a> <a class="code" href="structCTileOfPatch.html">CTileOfPatch</a>(uint8 tileId, CPatch *patch) : TileId(tileId), Patch(patch) +02775 { +02776 } +02777 }; +02778 +02779 +02780 +02781 <font class="comment">// ***************************************************************************</font> +02782 <font class="comment">// ***************************************************************************</font> +02783 <font class="comment">// Static point lights.</font> +02784 <font class="comment">// ***************************************************************************</font> +02785 <font class="comment">// ***************************************************************************</font> +02786 +02787 +02788 <font class="comment">// ***************************************************************************</font> +<a name="l02789"></a><a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#a0">02789</a> CZoneLighter::CPointLightRT::CPointLightRT() +02790 { +02791 <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m4">RefCount</a>= 0; +02792 } +02793 +02794 +02795 <font class="comment">// ***************************************************************************</font> +<a name="l02796"></a><a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#a1">02796</a> <font class="keywordtype">bool</font> CZoneLighter::CPointLightRT::testRaytrace(<font class="keyword">const</font> CVector &<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>) +02797 { +02798 CVector dummy; +02799 +02800 <font class="keywordflow">if</font>(!<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m2">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#a2">include</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)) +02801 <font class="keywordflow">return</font> <font class="keyword">false</font>; +02802 +02803 <font class="comment">// If Ambient light, just skip</font> +02804 <font class="keywordflow">if</font>(<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m0">PointLight</a>.getType()== CPointLight::AmbientLight) +02805 <font class="keywordflow">return</font> <font class="keyword">false</font>; +02806 +02807 <font class="comment">// If SpotLight verify in angle radius.</font> +02808 <font class="keywordflow">if</font>(<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m0">PointLight</a>.getType()== CPointLight::SpotLight) +02809 { +02810 <font class="keywordtype">float</font> att= <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m0">PointLight</a>.computeLinearAttenuation(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>); +02811 <font class="keywordflow">if</font> (att==0) +02812 <font class="keywordflow">return</font> <font class="keyword">false</font>; +02813 } +02814 +02815 <font class="comment">// Select in the cubeGrid</font> +02816 <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.select(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>); +02817 <font class="comment">// For all faces selected</font> +02818 <font class="keywordflow">while</font>(!<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.isEndSel()) +02819 { +02820 <font class="keyword">const</font> CTriangle *tri= <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.getSel(); +02821 +02822 <font class="comment">// If intersect, the point is occluded.</font> +02823 <font class="keywordflow">if</font>( tri->Triangle.intersect(<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m2">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m0">Center</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, dummy, tri->getPlane()) ) +02824 <font class="keywordflow">return</font> <font class="keyword">false</font>; +02825 +02826 <font class="comment">// next</font> +02827 <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.nextSel(); +02828 } +02829 +02830 <font class="comment">// Ok the point is visilbe from the light</font> +02831 <font class="keywordflow">return</font> <font class="keyword">true</font>; +02832 } +02833 +02834 +02835 <font class="comment">// ***************************************************************************</font> +<a name="l02836"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#z922_0">02836</a> <font class="keywordtype">void</font> CZoneLighter::addStaticPointLight(<font class="keyword">const</font> CPointLightNamed &pln) +02837 { +02838 <font class="comment">// build the plRT.</font> +02839 CPointLightRT plRT; +02840 plRT.PointLight= pln; +02841 <font class="comment">// compute plRT.OODeltaAttenuation</font> +02842 plRT.OODeltaAttenuation= pln.getAttenuationEnd() - pln.getAttenuationBegin(); +02843 <font class="keywordflow">if</font>(plRT.OODeltaAttenuation <=0 ) +02844 plRT.OODeltaAttenuation= 0; +02845 <font class="keywordflow">else</font> +02846 plRT.OODeltaAttenuation= 1.0f / plRT.OODeltaAttenuation; +02847 <font class="comment">// compute plRT.BSphere</font> +02848 plRT.BSphere.Center= pln.getPosition(); +02849 plRT.BSphere.Radius= pln.getAttenuationEnd(); +02850 <font class="comment">// NB: FaceCubeGrid will be computed during light()</font> +02851 +02852 <font class="comment">// add the plRT</font> +02853 <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.push_back(plRT); +02854 +02855 } +02856 +02857 +02858 <font class="comment">// ***************************************************************************</font> +<a name="l02859"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#z923_0">02859</a> <font class="keywordtype">void</font> CZoneLighter::compilePointLightRT(uint gridSize, <font class="keywordtype">float</font> gridCellSize, std::vector<CTriangle>& obstacles, <font class="keywordtype">bool</font> doShadow) +02860 { +02861 uint i; +02862 +02863 <font class="comment">// Fill the quadGrid of Lights.</font> +02864 <font class="comment">// ===========</font> +02865 <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.create(gridSize, gridCellSize); +02866 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size();i++) +02867 { +02868 CPointLightRT &plRT= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>[i]; +02869 +02870 <font class="comment">// Compute the bbox of the light</font> +02871 CAABBox bbox; +02872 bbox.setCenter(plRT.BSphere.Center); +02873 <font class="keywordtype">float</font> hl= plRT.BSphere.Radius; +02874 bbox.setHalfSize(CVector(hl,hl,hl)); +02875 +02876 <font class="comment">// Insert the pointLight in the quadGrid.</font> +02877 <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.insert(bbox.getMin(), bbox.getMax(), &plRT); +02878 } +02879 +02880 +02881 <font class="comment">// Append triangles to cubeGrid ??</font> +02882 <font class="keywordflow">if</font>(doShadow) +02883 { +02884 <font class="comment">// For all obstacles, Fill a quadGrid.</font> +02885 <font class="comment">// ===========</font> +02886 CQuadGrid<CTriangle*> obstacleGrid; +02887 obstacleGrid.create(gridSize, gridCellSize); +02888 uint size= obstacles.size(); +02889 <font class="keywordflow">for</font>(i=0; i<size; i++) +02890 { +02891 <font class="comment">// bbox of triangle</font> +02892 CAABBox bbox; +02893 bbox.setCenter(obstacles[i].Triangle.V0); +02894 bbox.extend(obstacles[i].Triangle.V1); +02895 bbox.extend(obstacles[i].Triangle.V2); +02896 <font class="comment">// insert triangle in quadGrid.</font> +02897 obstacleGrid.insert(bbox.getMin(), bbox.getMax(), &obstacles[i]); +02898 } +02899 +02900 +02901 <font class="comment">// For all PointLights, fill his CubeGrid</font> +02902 <font class="comment">// ===========</font> +02903 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size();i++) +02904 { +02905 <font class="comment">// progress</font> +02906 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compute Influences of PointLights"</font>, 0.5f*i / (<font class="keywordtype">float</font>)(<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size()-1)); +02907 +02908 CPointLightRT &plRT= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>[i]; +02909 <font class="comment">// Create the cubeGrid</font> +02910 plRT.FaceCubeGrid.create(plRT.PointLight.getPosition(), <a class="code" href="zone__lighter_8cpp.html#a0">NL3D_ZONE_LIGHTER_CUBE_GRID_SIZE</a>); +02911 +02912 <font class="comment">// AmbiantLIghts: do nothing.</font> +02913 <font class="keywordflow">if</font>(plRT.PointLight.getType()!=CPointLight::AmbientLight) +02914 { +02915 <font class="comment">// Select only obstacle Faces around the light. Other are not usefull</font> +02916 CAABBox bbox; +02917 bbox.setCenter(plRT.PointLight.getPosition()); +02918 <font class="keywordtype">float</font> hl= plRT.PointLight.getAttenuationEnd(); +02919 bbox.setHalfSize(CVector(hl,hl,hl)); +02920 obstacleGrid.select(bbox.getMin(), bbox.getMax()); +02921 +02922 <font class="comment">// For all faces, fill the cubeGrid.</font> +02923 CQuadGrid<CTriangle*>::CIterator itObstacle; +02924 itObstacle= obstacleGrid.begin(); +02925 <font class="keywordflow">while</font>( itObstacle!=obstacleGrid.end() ) +02926 { +02927 CTriangle &tri= *(*itObstacle); +02928 <font class="comment">// Test BackFace culling. Only faces which are BackFace the point light are inserted.</font> +02929 <font class="comment">// This is to avoid AutoOccluding problems</font> +02930 <font class="keywordflow">if</font>( tri.getPlane() * plRT.BSphere.Center < 0) +02931 { +02932 <font class="comment">// Insert the triangle in the CubeGrid</font> +02933 plRT.FaceCubeGrid.insert( tri.Triangle, &tri); +02934 } +02935 +02936 itObstacle++; +02937 } +02938 } +02939 +02940 <font class="comment">// Compile the CubeGrid.</font> +02941 plRT.FaceCubeGrid.compile(); +02942 +02943 <font class="comment">// And Reset RefCount.</font> +02944 plRT.RefCount= 0; +02945 } +02946 } +02947 <font class="comment">// else, just build empty grid</font> +02948 <font class="keywordflow">else</font> +02949 { +02950 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size();i++) +02951 { +02952 <font class="comment">// progress</font> +02953 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compute Influences of PointLights"</font>, 0.5f*i / (<font class="keywordtype">float</font>)(<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size()-1)); +02954 +02955 CPointLightRT &plRT= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>[i]; +02956 <font class="comment">// Create a dummy empty cubeGrid => no rayTrace :)</font> +02957 plRT.FaceCubeGrid.create(plRT.PointLight.getPosition(), 4); +02958 +02959 <font class="comment">// Compile the CubeGrid.</font> +02960 plRT.FaceCubeGrid.compile(); +02961 +02962 <font class="comment">// And Reset RefCount.</font> +02963 plRT.RefCount= 0; +02964 } +02965 } +02966 +02967 } +02968 +02969 +02970 <font class="comment">// ***************************************************************************</font> +<a name="l02971"></a><a class="code" href="structNL3D_1_1CZoneLighter_1_1CPredPointLightToPoint.html#a0">02971</a> <font class="keywordtype">bool</font> CZoneLighter::CPredPointLightToPoint::operator() (CPointLightRT *pla, CPointLightRT *plb)<font class="keyword"> const</font> +02972 <font class="keyword"></font>{ +02973 <font class="keywordtype">float</font> ra= (pla->BSphere.Center - <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPredPointLightToPoint.html#m0">Point</a>).norm(); +02974 <font class="keywordtype">float</font> rb= (plb->BSphere.Center - <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPredPointLightToPoint.html#m0">Point</a>).norm(); +02975 <font class="keywordtype">float</font> infA= (pla->PointLight.getAttenuationEnd() - ra) * pla->OODeltaAttenuation; +02976 <font class="keywordtype">float</font> infB= (plb->PointLight.getAttenuationEnd() - rb) * plb->OODeltaAttenuation; +02977 <font class="comment">// return which light impact the most.</font> +02978 <font class="comment">// If same impact</font> +02979 <font class="keywordflow">if</font>(infA==infB) +02980 <font class="comment">// return nearest</font> +02981 <font class="keywordflow">return</font> ra < rb; +02982 <font class="keywordflow">else</font> +02983 <font class="comment">// return better impact</font> +02984 <font class="keywordflow">return</font> infA > infB; +02985 } +02986 +02987 <font class="comment">// ***************************************************************************</font> +<a name="l02988"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#z923_1">02988</a> <font class="keywordtype">void</font> CZoneLighter::processZonePointLightRT(vector<CPointLightNamed> &listPointLight) +02989 { +02990 uint i; +02991 vector<CPointLightRT*> lightInfs; +02992 lightInfs.reserve(1024); +02993 +02994 <font class="comment">// clear result list</font> +02995 listPointLight.clear(); +02996 +02997 <font class="comment">// zoneToLight</font> +02998 CZone *zoneToLight= <a class="code" href="classNL3D_1_1CZoneLighter.html#o5">_Landscape</a>-><a class="code" href="classNL3D_1_1CLandscape.html#z481_0">getZone</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>); +02999 <font class="keywordflow">if</font>(!zoneToLight) +03000 <font class="keywordflow">return</font>; +03001 +03002 <font class="comment">// Build patchForPLs</font> +03003 <font class="comment">//===========</font> +03004 vector<CPatchForPL> patchForPLs; +03005 patchForPLs.resize(<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size()); +03006 <font class="keywordflow">for</font>(i=0; i<patchForPLs.size(); i++) +03007 { +03008 <font class="comment">// Get OrderS/OrderT</font> +03009 patchForPLs[i].OrderS= <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[i].OrderS; +03010 patchForPLs[i].OrderT= <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[i].OrderT; +03011 <font class="comment">// resize TileLightInfluences</font> +03012 uint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= patchForPLs[i].WidthTLI= patchForPLs[i].OrderS/2 +1 ; +03013 uint h= patchForPLs[i].HeightTLI= patchForPLs[i].OrderT/2 +1; +03014 patchForPLs[i].TileLightInfluences.resize(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h); +03015 } +03016 +03017 +03018 <font class="comment">// compute each TileLightInfluence</font> +03019 <font class="comment">//===========</font> +03020 <font class="keywordflow">for</font>(i=0; i<patchForPLs.size(); i++) +03021 { +03022 <font class="comment">// progress</font> +03023 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compute Influences of PointLights"</font>, 0.5f + 0.5f*i / (<font class="keywordtype">float</font>)patchForPLs.size()); +03024 +03025 CPatchForPL &pfpl= patchForPLs[i]; +03026 <font class="keyword">const</font> CPatch *patch= const_cast<const CZone*>(zoneToLight)->getPatch(i); +03027 +03028 uint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>; +03029 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= 0; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a><pfpl.HeightTLI; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++) +03030 { +03031 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= 0; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a><pfpl.WidthTLI; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++) +03032 { +03033 <font class="comment">// compute the point and normal (normalized) where the TLI lies.</font> +03034 <font class="comment">//---------</font> +03035 CVector pos, normal; +03036 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>; +03037 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>= (float)<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> / (pfpl.WidthTLI-1); +03038 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= (float)<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> / (pfpl.HeightTLI-1); +03039 <font class="comment">// Compute the Vertex, with Noise information (important for accurate raytracing).</font> +03040 pos= patch->computeVertex(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>); +03041 <font class="comment">// Use UnNoised normal from BezierPatch, because the lighting does not need to be so precise.</font> +03042 CBezierPatch *bp= patch->unpackIntoCache(); +03043 normal= bp->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>); +03044 +03045 +03046 <font class="comment">// Compute Which light influences him.</font> +03047 <font class="comment">//---------</font> +03048 lightInfs.clear(); +03049 <font class="comment">// Search possible lights around the position.</font> +03050 <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.select(pos, pos); +03051 <font class="comment">// For all of them, get the ones which touch this point.</font> +03052 CQuadGrid<CPointLightRT*>::CIterator it= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.begin(); +03053 <font class="keywordflow">while</font>(it != <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.end()) +03054 { +03055 CPointLightRT *pl= *it; +03056 +03057 <font class="comment">// a light influence a TLI only if this one is FrontFaced to the light !!</font> +03058 <font class="keywordflow">if</font>( ( pl->BSphere.Center - pos ) * normal > 0) +03059 { +03060 <font class="comment">// Add 5cm else it fails in some case where ( pl->BSphere.Center - pos ) * normal is </font> +03061 <font class="comment">// nearly 0 and the point should be occluded.</font> +03062 <font class="keyword">const</font> <font class="keywordtype">float</font> deltaY= 0.05f; +03063 CVector posToRT= pos + normal * deltaY; +03064 <font class="comment">// Test if really in the radius of the light, if no occlusion, and if in SpotAngle</font> +03065 <font class="keywordflow">if</font>( pl->testRaytrace(posToRT) ) +03066 { +03067 <font class="comment">// Ok, add the light to the lights which influence the TLI </font> +03068 lightInfs.push_back(pl); +03069 } +03070 } +03071 +03072 <font class="comment">// next</font> +03073 it++; +03074 } +03075 +03076 <font class="comment">// Choose the Best ones.</font> +03077 <font class="comment">//---------</font> +03078 CPredPointLightToPoint predPLTP; +03079 predPLTP.Point= pos; +03080 <font class="comment">// sort.</font> +03081 sort(lightInfs.begin(), lightInfs.end(), predPLTP); +03082 <font class="comment">// truncate.</font> +03083 lightInfs.resize( <a class="code" href="bit__set_8cpp.html#a0">min</a>(lightInfs.size(), (uint)CTileLightInfluence::NumLightPerCorner) ); +03084 +03085 +03086 <font class="comment">// For each of them, fill TLI</font> +03087 <font class="comment">//---------</font> +03088 CTileLightInfUnpack tli; +03089 uint lightInfId; +03090 <font class="keywordflow">for</font>(lightInfId=0; lightInfId<lightInfs.size(); lightInfId++) +03091 { +03092 CPointLightRT *pl= lightInfs[lightInfId]; +03093 +03094 <font class="comment">// copy light.</font> +03095 tli.Light[lightInfId]= pl; +03096 <font class="comment">// Compute light Diffuse factor.</font> +03097 CVector dir= pl->BSphere.Center - pos; +03098 dir.normalize(); +03099 tli.LightFactor[lightInfId]= dir * normal; +03100 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(tli.LightFactor[lightInfId], 0.f, 1.f); +03101 <font class="comment">// modulate by light attenuation.</font> +03102 tli.LightFactor[lightInfId]*= pl->PointLight.computeLinearAttenuation(pos); +03103 +03104 <font class="comment">// Inc RefCount of the light.</font> +03105 pl->RefCount++; +03106 } +03107 <font class="comment">// Reset any empty slot to NULL.</font> +03108 <font class="keywordflow">for</font>(; lightInfId<CTileLightInfluence::NumLightPerCorner; lightInfId++) +03109 { +03110 tli.Light[lightInfId]= NULL; +03111 } +03112 +03113 +03114 <font class="comment">// Set TLI in patch.</font> +03115 <font class="comment">//---------</font> +03116 pfpl.TileLightInfluences[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*pfpl.WidthTLI + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= tli; +03117 } +03118 } +03119 } +03120 +03121 +03122 <font class="comment">// compress and setup _PatchInfo with compressed data.</font> +03123 <font class="comment">//===========</font> +03124 uint plId= 0; +03125 <font class="comment">// Process each pointLights</font> +03126 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size(); i++) +03127 { +03128 CPointLightRT &plRT= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>[i]; +03129 <font class="comment">// If this light is used.</font> +03130 <font class="keywordflow">if</font>(plRT.RefCount > 0) +03131 { +03132 <font class="comment">// Must Copy it into Zone.</font> +03133 listPointLight.push_back(plRT.PointLight); +03134 plRT.DstId= plId++; +03135 <font class="comment">// If index >= 255, too many lights (NB: => because 255 is a NULL code).</font> +03136 <font class="keywordflow">if</font>(plId>=0xFF) +03137 { +03138 <font class="keywordflow">throw</font> Exception(<font class="stringliteral">"Too many Static Point Lights influence the zone!!"</font>); +03139 } +03140 } +03141 } +03142 +03143 <font class="comment">// For each patch, compress TLI in PatchInfo.</font> +03144 <font class="keywordflow">for</font>(i=0; i<patchForPLs.size(); i++) +03145 { +03146 CPatchForPL &pfpl= patchForPLs[i]; +03147 CPatchInfo &pInfo= <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[i]; +03148 +03149 uint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= pfpl.WidthTLI; +03150 uint h= pfpl.HeightTLI; +03151 +03152 <font class="comment">// Fill pInfo.TileLightInfluences</font> +03153 pInfo.TileLightInfluences.resize(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h); +03154 uint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>; +03155 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= 0; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a><h; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++) +03156 { +03157 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= 0; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a><<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++) +03158 { +03159 uint tliId= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>; +03160 <font class="comment">// For all light slot</font> +03161 <font class="keywordflow">for</font>(uint lightId= 0; lightId<CTileLightInfluence::NumLightPerCorner; lightId++) +03162 { +03163 CTileLightInfUnpack &tliSrc= pfpl.TileLightInfluences[tliId]; +03164 CTileLightInfluence &tliDst= pInfo.TileLightInfluences[tliId]; +03165 <font class="keywordflow">if</font>(tliSrc.Light[lightId] == NULL) +03166 { +03167 <font class="comment">// Mark as unused.</font> +03168 tliDst.Light[lightId]= 0xFF; +03169 } +03170 <font class="keywordflow">else</font> +03171 { +03172 <font class="comment">// Get index.</font> +03173 tliDst.Light[lightId]= tliSrc.Light[lightId]->DstId; +03174 <font class="comment">// Get Diffuse Factor.</font> +03175 tliDst.setDiffuseLightFactor(lightId, (uint8)(tliSrc.LightFactor[lightId]*255)); +03176 } +03177 } +03178 } +03179 } +03180 +03181 } +03182 +03183 } +03184 +03187 <font class="comment">// TileFlagsForPositionTowardWater</font> +03190 <font class="comment"></font> +03191 +03192 <font class="comment">//==================================================================</font> +<a name="l03194"></a><a class="code" href="zone__lighter_8cpp.html#a13">03194</a> <font class="comment">static inline bool operator < (const CTileOfPatch &lhs, const CTileOfPatch &rhs)</font> +03195 { +03196 <font class="keywordflow">return</font> lhs.Patch == rhs.Patch ? +03197 lhs.TileId < rhs.TileId : +03198 lhs.Patch < rhs.Patch; +03199 }; +03200 +<a name="l03202"></a><a class="code" href="zone__lighter_8cpp.html#a6">03202</a> <font class="keyword">typedef</font> std::map<CTileOfPatch, NLMISC::CAABBox> <a class="code" href="zone__lighter_8cpp.html#a6">TTileOfPatchMap</a>; +03203 +<a name="l03205"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c19">03205</a> <font class="keywordtype">void</font> CZoneLighter::computeTileFlagsForPositionTowardWater(<font class="keyword">const</font> CLightDesc &lightDesc, +03206 std::vector<const CTessFace*> &tessFaces +03207 ) +03208 { +03209 uint numTileAbove = 0; +03210 uint numTileBelow = 0; +03211 uint numTileIntersect = 0; +03212 +03214 <a class="code" href="zone__lighter_8cpp.html#a6">TTileOfPatchMap</a> tiles; +03215 +03217 <font class="comment">// First, build the bbox for all tiles //</font> +03219 <font class="comment"></font> +03220 uint triCount = 0, totalTriCount = tessFaces.size(); +03221 +03222 <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">"Dealing with %d tessFaces"</font>, tessFaces.size()); +03223 <font class="keywordflow">for</font> (std::vector<const CTessFace*>::iterator it = tessFaces.begin(); it != tessFaces.end(); ++it, ++triCount) +03224 { +03226 <font class="keywordflow">if</font> ((*it)->Patch->getZone()->getZoneId() != <a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) <font class="keywordflow">continue</font>; +03228 <font class="keywordflow">if</font> ((*it)->Patch->Tiles[(*it)->TileId].getVegetableState() == CTileElement::VegetableDisabled) +03229 <font class="keywordflow">continue</font>; +03230 +03231 <a class="code" href="structCTileOfPatch.html">CTileOfPatch</a> top((*it)->TileId, (*it)->Patch); +03232 TTileOfPatchMap::iterator tileIt = tiles.find(top); +03233 +03235 <font class="keywordflow">if</font> (tileIt == tiles.end()) <font class="comment">// first time ?</font> +03236 { +03238 <a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> b; +03239 b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_3">setMinMax</a>((*it)->VBase->EndPos, (*it)->VLeft->EndPos); +03240 b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>((*it)->VRight->EndPos); +03241 b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>(b.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_1">getMax</a>() + lightDesc.VegetableHeight * <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>); <font class="comment">// adds vegetable height </font> +03242 tiles[top] = b; +03243 } +03244 <font class="keywordflow">else</font> <font class="comment">// extends the bbox with the given face</font> +03245 { +03246 <a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> &b = tileIt->second; +03247 b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>((*it)->VBase->EndPos); +03248 b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>((*it)->VRight->EndPos); +03249 b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>((*it)->VLeft->EndPos); +03250 } +03251 +03252 <font class="keywordflow">if</font> ((triCount % 100) == 0) +03253 { +03254 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Building bbox from tiles"</font>, (<font class="keywordtype">float</font>) triCount / totalTriCount); +03255 } +03256 } +03257 +03258 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Building bbox from tiles"</font>, 1.f); +03259 +03260 +03261 +03263 <font class="comment">// Now, check each tile bbox against water shapes //</font> +03265 <font class="comment"> NLMISC::CPolygon waterPoly;</font> +03266 <a class="code" href="classNLMISC_1_1CPolygon2D.html">NLMISC::CPolygon2D</a> tilePoly; +03267 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>.resize(4); +03268 +03269 uint tileCount = 0, totalTileCount = tiles.size(); +03270 +03271 <font class="keywordflow">for</font> (TTileOfPatchMap::iterator tileIt = tiles.begin(); tileIt != tiles.end(); ++tileIt, ++tileCount) +03272 { +03273 <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> v0 = tileIt->second.getMin(); +03274 <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> v1 = tileIt->second.getMax(); +03275 +03277 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>[0].set(v0.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, v0.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>); +03278 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>[1].set(v1.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, v0.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>); +03279 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>[2].set(v1.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, v1.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>); +03280 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>[3].set(v0.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, v1.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>); +03281 +03283 <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.clearSelection(); +03284 <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.select(tileIt->second.getMin(), tileIt->second.getMax()); +03285 +03286 CTileElement &te = tileIt->first.Patch->Tiles[tileIt->first.TileId]; <font class="comment">// alias to the current tile element</font> +03287 +03289 TWaterShapeQuadGrid::CIterator qgIt; +03290 <font class="keywordflow">for</font> (qgIt = <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.begin(); qgIt != <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.end(); ++qgIt) +03291 { +03292 +03293 (*qgIt)->getShapeInWorldSpace(waterPoly); +03294 <a class="code" href="classNLMISC_1_1CPolygon2D.html">NLMISC::CPolygon2D</a> poly(waterPoly); +03295 <font class="keywordflow">if</font> (poly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#a8">intersect</a>(tilePoly)) <font class="comment">// above or below a water surface ? </font> +03296 { +03298 <font class="keywordtype">float</font> waterHeight = waterPoly.Vertices[0].z; +03299 +03300 <font class="keywordflow">if</font> (v1.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a> < waterHeight) +03301 { +03302 <font class="comment">// below</font> +03303 te.setVegetableState(CTileElement::UnderWater); +03304 <font class="comment">//nlassert(te.getVegetableState() == CTileElement::UnderWater);</font> +03305 ++ numTileBelow; +03306 } +03307 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (v0. <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a> > waterHeight) +03308 { +03309 <font class="comment">// above</font> +03310 te.setVegetableState(CTileElement::AboveWater); +03311 <font class="comment">//nlassert(te.getVegetableState() == CTileElement::AboveWater);</font> +03312 ++ numTileAbove; +03313 } +03314 <font class="keywordflow">else</font> +03315 { +03316 <font class="comment">// intersect water</font> +03317 te.setVegetableState(CTileElement::IntersectWater); +03318 <font class="comment">//nlassert(te.getVegetableState() == CTileElement::IntersectWater);</font> +03319 ++ numTileIntersect; +03320 } +03321 <font class="keywordflow">break</font>; +03322 } +03323 } +03324 +03325 <font class="keywordflow">if</font> (qgIt == <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.end()) <font class="comment">// no intersection found ? if yes it's above water</font> +03326 { +03327 te.setVegetableState(CTileElement::AboveWater); +03328 <font class="comment">//nlassert(te.getVegetableState() == CTileElement::AboveWater);</font> +03329 ++ numTileAbove; +03330 } +03331 +03332 <font class="keywordflow">if</font> ((tileCount % 50) == 0) +03333 { +03334 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Computing tile position towards water"</font>, (<font class="keywordtype">float</font>) tileCount / totalTileCount); +03335 } +03336 } +03337 +03338 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Computing tile position towards water"</font>, 1.f); +03339 +03340 <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">" %d tiles are above water."</font>, numTileAbove); +03341 <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">" %d tiles are below water."</font>, numTileBelow); +03342 <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">" %d tiles intersect water."</font>, numTileIntersect); +03343 +03344 +03345 +03347 <a class="code" href="namespaceNLMISC.html#a222">NLMISC::contReset</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>); +03348 } +03349 +<a name="l03351"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c20">03351</a> <font class="keywordtype">void</font> CZoneLighter::setTileFlagsToDefault(std::vector<const CTessFace*> &tessFaces) +03352 { +03354 <font class="keywordflow">for</font> (std::vector<const CTessFace*>::iterator it = tessFaces.begin(); it != tessFaces.end(); ++it) +03355 { +03356 <font class="keywordflow">if</font> ((*it)->Patch->getZone()->getZoneId() != <a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) <font class="keywordflow">continue</font>; +03357 CTileElement &te = (*it)->Patch->Tiles[(*it)->TileId]; +03358 <font class="keywordflow">if</font> (te.getVegetableState() != CTileElement::VegetableDisabled) +03359 { +03360 te.setVegetableState(CTileElement::AboveWater); +03361 } +03362 } +03363 } +03364 +03365 +<a name="l03367"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c21">03367</a> uint CZoneLighter::getAPatch (uint process) +03368 { +03369 <font class="comment">// Accessor</font> +03370 CSynchronized<std::vector<bool> >::CAccessor access (&<a class="code" href="classNL3D_1_1CZoneLighter.html#o9">_PatchComputed</a>); +03371 +03372 <font class="comment">// Current index</font> +03373 uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> = <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>[process]; +03374 uint firstIndex = <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>; +03375 +03376 <font class="keywordflow">if</font> (access.value().size() == 0) +03377 <font class="comment">// no more patches</font> +03378 <font class="keywordflow">return</font> 0xffffffff; +03379 +03380 <font class="keywordflow">while</font> (access.value()[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]) +03381 { +03382 <font class="comment">// Next patch</font> +03383 <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>++; +03384 +03385 <font class="comment">// First ?</font> +03386 <font class="keywordflow">if</font> (firstIndex == <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>) +03387 <font class="comment">// no more patches</font> +03388 <font class="keywordflow">return</font> 0xffffffff; +03389 +03390 <font class="comment">// Last patch ?</font> +03391 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> == <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size()) +03392 <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> = 0; +03393 } +03394 +03395 <font class="comment">// Visited</font> +03396 access.value()[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>] = <font class="keyword">true</font>; +03397 +03398 <font class="comment">// Last index</font> +03399 <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>[process] = <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>; +03400 <a class="code" href="classNL3D_1_1CZoneLighter.html#o11">_NumberOfPatchComputed</a>++; +03401 +03402 <font class="comment">// Print</font> +03403 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Lighting patches"</font>, (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CZoneLighter.html#o11">_NumberOfPatchComputed</a>/(<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size()); +03404 +03405 <font class="comment">// Return the index</font> +03406 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>; +03407 } +</pre></div> + +<!-- footer --> +<BR><FONT Size=+5> </FONT> +</TD> +<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD> +</TR> +</TABLE> +</BODY> +</HTML> |