aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/vegetable__manager_8cpp-source.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--docs/doxygen/nel/vegetable__manager_8cpp-source.html2671
1 files changed, 2671 insertions, 0 deletions
diff --git a/docs/doxygen/nel/vegetable__manager_8cpp-source.html b/docs/doxygen/nel/vegetable__manager_8cpp-source.html
new file mode 100644
index 00000000..b1320d98
--- /dev/null
+++ b/docs/doxygen/nel/vegetable__manager_8cpp-source.html
@@ -0,0 +1,2671 @@
+<!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>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</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>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</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>
+&nbsp;
+
+<!-- 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>&nbsp;</td>
+</tr></table>
+<!-- Generated by Doxygen 1.2.14 -->
+<center>
+<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <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> &nbsp; </center>
+<hr><h1>vegetable_manager.cpp</h1><a href="vegetable__manager_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
+00007 <font class="comment">/* Copyright, 2001 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
+00029 <font class="preprocessor">#include "<a class="code" href="vegetable__manager_8h.html">3d/vegetable_manager.h</a>"</font>
+00030 <font class="preprocessor">#include "<a class="code" href="driver_8h.html">3d/driver.h</a>"</font>
+00031 <font class="preprocessor">#include "<a class="code" href="texture__file_8h.html">3d/texture_file.h</a>"</font>
+00032 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font>
+00033 <font class="preprocessor">#include "<a class="code" href="vegetable__quadrant_8h.html">3d/vegetable_quadrant.h</a>"</font>
+00034 <font class="preprocessor">#include "<a class="code" href="dru_8h.html">3d/dru.h</a>"</font>
+00035 <font class="preprocessor">#include "<a class="code" href="radix__sort_8h.html">3d/radix_sort.h</a>"</font>
+00036 <font class="preprocessor">#include "<a class="code" href="scene_8h.html">3d/scene.h</a>"</font>
+00037 <font class="preprocessor">#include "<a class="code" href="vegetable__blend__layer__model_8h.html">3d/vegetable_blend_layer_model.h</a>"</font>
+00038 <font class="preprocessor">#include "<a class="code" href="vegetable__light__ex_8h.html">3d/vegetable_light_ex.h</a>"</font>
+00039 <font class="preprocessor">#include "<a class="code" href="hierarchical__timer_8h.html">nel/misc/hierarchical_timer.h</a>"</font>
+00040
+00041 <font class="preprocessor">#include &lt;algorithm&gt;</font>
+00042
+00043
+00044 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
+00045 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
+00046
+00047
+00048 <font class="keyword">namespace </font>NL3D
+00049 {
+00050
+00051
+<a name="l00052"></a><a class="code" href="vegetable__manager_8cpp.html#a0">00052</a> <font class="preprocessor">#define NL3D_VEGETABLE_CLIP_BLOCK_BLOCKSIZE 16</font>
+<a name="l00053"></a><a class="code" href="vegetable__manager_8cpp.html#a1">00053</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_VEGETABLE_SORT_BLOCK_BLOCKSIZE 64</font>
+<a name="l00054"></a><a class="code" href="vegetable__manager_8cpp.html#a2">00054</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_VEGETABLE_INSTANCE_GROUP_BLOCKSIZE 128</font>
+00055 <font class="preprocessor"></font>
+00056
+00057 <font class="comment">// ***************************************************************************</font>
+<a name="l00058"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#a0">00058</a> CVegetableManager::CVegetableManager(uint maxVertexVbHardUnlit, uint maxVertexVbHardLighted,
+00059 uint nbBlendLayers, <font class="keywordtype">float</font> blendLayerDistMax) :
+00060 _ClipBlockMemory(<a class="code" href="vegetable__manager_8cpp.html#a0">NL3D_VEGETABLE_CLIP_BLOCK_BLOCKSIZE</a>),
+00061 _SortBlockMemory(<a class="code" href="vegetable__manager_8cpp.html#a1">NL3D_VEGETABLE_SORT_BLOCK_BLOCKSIZE</a>),
+00062 _InstanceGroupMemory(<a class="code" href="vegetable__manager_8cpp.html#a2">NL3D_VEGETABLE_INSTANCE_GROUP_BLOCKSIZE</a>),
+00063 _NumZSortBlendLayers(nbBlendLayers), _ZSortLayerDistMax(blendLayerDistMax),
+00064 _ZSortScene(NULL)
+00065 {
+00066 uint i;
+00067
+00068 <font class="comment">// Init all the allocators</font>
+00069 <a class="code" href="debug_8h.html#a6">nlassert</a>((uint)(CVegetableVBAllocator::VBTypeCount) == 2);
+00070 <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[CVegetableVBAllocator::VBTypeLighted].init( CVegetableVBAllocator::VBTypeLighted, maxVertexVbHardLighted );
+00071 <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[CVegetableVBAllocator::VBTypeUnlit].init( CVegetableVBAllocator::VBTypeUnlit, maxVertexVbHardUnlit );
+00072 <font class="comment">// Init soft one, with no vbHard vertices.</font>
+00073 <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[CVegetableVBAllocator::VBTypeLighted].init( CVegetableVBAllocator::VBTypeLighted, 0 );
+00074 <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[CVegetableVBAllocator::VBTypeUnlit].init( CVegetableVBAllocator::VBTypeUnlit, 0 );
+00075
+00076 <font class="comment">// NB Vertex programs are initilized during the first call to update driver.</font>
+00077
+00078 <font class="comment">// setup the material. Unlit (doesn't matter, lighting in VP) Alpha Test.</font>
+00079 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.initUnlit();
+00080 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setAlphaTest(<font class="keyword">true</font>);
+00081 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha);
+00082
+00083 <font class="comment">// default light.</font>
+00084 <a class="code" href="classNL3D_1_1CVegetableManager.html#o10">_DirectionalLight</a>= (CVector(0,1, -1)).normed();
+00085 <a class="code" href="classNL3D_1_1CVegetableManager.html#o11">_GlobalAmbient</a>.<a class="code" href="classNLMISC_1_1CRGBA.html#a10">set</a>(64, 64, 64, 255);
+00086 <a class="code" href="classNL3D_1_1CVegetableManager.html#o12">_GlobalDiffuse</a>.<a class="code" href="classNLMISC_1_1CRGBA.html#a10">set</a>(150, 150, 150, 255);
+00087
+00088 <font class="comment">// Wind.</font>
+00089 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_0">_WindDirection</a>.set(1,0,0);
+00090 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_1">_WindFrequency</a>= 1;
+00091 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_2">_WindPower</a>= 1;
+00092 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_3">_WindBendMin</a>= 0;
+00093 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_4">_Time</a>= 0;
+00094 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_5">_WindPrecRenderTime</a>= 0;
+00095 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_6">_WindAnimTime</a>= 0;
+00096
+00097 <font class="comment">// Init CosTable.</font>
+00098 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="vegetable__def_8h.html#a6">NL3D_VEGETABLE_VP_LUT_SIZE</a>; i++)
+00099 {
+00100 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_7">_CosTable</a>[i]= (float)cos( i*2*<a class="code" href="namespaceNLMISC.html#a7">Pi</a> / <a class="code" href="vegetable__def_8h.html#a6">NL3D_VEGETABLE_VP_LUT_SIZE</a> );
+00101 }
+00102
+00103 <font class="comment">// init to NULL _ZSortModelLayers.</font>
+00104 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>= max(1U, <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>);
+00105 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>.resize(<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>, NULL);
+00106 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>.resize(<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>, NULL);
+00107
+00108
+00109 <font class="comment">// UL</font>
+00110 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_6">_ULFrequency</a>= 0;
+00111 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_7">_ULNVerticesToUpdate</a>=0;
+00112 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_8">_ULNTotalVertices</a>= 0;
+00113 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>= NULL;
+00114 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>= 0;
+00115 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>= 0;
+00116 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_3">_ULPrecTime</a>= 0;
+00117 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_4">_ULPrecTimeInit</a>= <font class="keyword">false</font>;
+00118 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_5">_ULTime</a>= 0;
+00119
+00120 <font class="comment">// Misc.</font>
+00121 <a class="code" href="classNL3D_1_1CVegetableManager.html#o13">_NumVegetableFaceRendered</a>= 0;
+00122
+00123 std::fill(<a class="code" href="classNL3D_1_1CVegetableManager.html#o8">_VertexProgram</a>, <a class="code" href="classNL3D_1_1CVegetableManager.html#o8">_VertexProgram</a> + <a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>, (CVertexProgram *) NULL);
+00124
+00125 }
+00126
+00127
+00128 <font class="comment">// ***************************************************************************</font>
+<a name="l00129"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#a1">00129</a> CVegetableManager::~CVegetableManager()
+00130 {
+00131 <font class="comment">// delete All VP</font>
+00132 <font class="keywordflow">for</font>(sint i=0; i &lt;<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; i++)
+00133 {
+00134 <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o8">_VertexProgram</a>[i];
+00135 <a class="code" href="classNL3D_1_1CVegetableManager.html#o8">_VertexProgram</a>[i]= NULL;
+00136 }
+00137
+00138 <font class="comment">// delete ZSort models.</font>
+00139 <font class="keywordflow">if</font>(_ZSortScene)
+00140 {
+00141 <font class="comment">// remove models from scene.</font>
+00142 <font class="keywordflow">for</font>(uint i= 0; i&lt;<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>; i++)
+00143 {
+00144 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_4">_ZSortScene</a>-&gt;deleteModel(<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[i]);
+00145 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[i]= NULL;
+00146 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_4">_ZSortScene</a>-&gt;deleteModel(<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]);
+00147 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]= NULL;
+00148 }
+00149
+00150 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_4">_ZSortScene</a>= NULL;
+00151 }
+00152 }
+00153
+00154
+00155 <font class="comment">// ***************************************************************************</font>
+<a name="l00156"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#a2">00156</a> <font class="keywordtype">void</font> CVegetableManager::createVegetableBlendLayersModels(CScene *scene)
+00157 {
+00158 <font class="comment">// setup scene</font>
+00159 <a class="code" href="debug_8h.html#a6">nlassert</a>(scene);
+00160 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_4">_ZSortScene</a>= scene;
+00161
+00162 <font class="comment">// create the layers models.</font>
+00163 <font class="keywordflow">for</font>(uint i=0;i&lt;<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>; i++)
+00164 {
+00165 <font class="comment">// assert not already done.</font>
+00166 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[i]==NULL);
+00167 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]==NULL);
+00168
+00169 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[i]= (<a class="code" href="classNL3D_1_1CVegetableManager.html#l0">CVegetableBlendLayerModel</a>*)scene-&gt;createModel(<a class="code" href="namespaceNL3D.html#a278">VegetableBlendLayerModelId</a>);
+00170 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]= (<a class="code" href="classNL3D_1_1CVegetableManager.html#l0">CVegetableBlendLayerModel</a>*)scene-&gt;createModel(<a class="code" href="namespaceNL3D.html#a278">VegetableBlendLayerModelId</a>);
+00171 <font class="comment">// init owner.</font>
+00172 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[i]-&gt;VegetableManager= <font class="keyword">this</font>;
+00173 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]-&gt;VegetableManager= <font class="keyword">this</font>;
+00174
+00175 <font class="comment">// Set UnderWater layer for _ZSortModelLayersUW</font>
+00176 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]-&gt;setOrderingLayer(2);
+00177 }
+00178 }
+00179
+00180
+00181 <font class="comment">// ***************************************************************************</font>
+<a name="l00182"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#c1">00182</a> CVegetableVBAllocator &amp;CVegetableManager::getVBAllocatorForRdrPassAndVBHardMode(uint rdrPass, uint vbHardMode)
+00183 {
+00184 <font class="comment">// If software VB</font>
+00185 <font class="keywordflow">if</font>(vbHardMode==0)
+00186 {
+00187 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a1">NL3D_VEGETABLE_RDRPASS_LIGHTED</a>)
+00188 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[CVegetableVBAllocator::VBTypeLighted];
+00189 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a2">NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED</a>)
+00190 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[CVegetableVBAllocator::VBTypeLighted];
+00191 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a3">NL3D_VEGETABLE_RDRPASS_UNLIT</a>)
+00192 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[CVegetableVBAllocator::VBTypeUnlit];
+00193 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a4">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED</a>)
+00194 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[CVegetableVBAllocator::VBTypeUnlit];
+00195 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>)
+00196 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[CVegetableVBAllocator::VBTypeUnlit];
+00197 }
+00198 <font class="comment">// If hard VB</font>
+00199 <font class="keywordflow">else</font>
+00200 {
+00201 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a1">NL3D_VEGETABLE_RDRPASS_LIGHTED</a>)
+00202 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[CVegetableVBAllocator::VBTypeLighted];
+00203 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a2">NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED</a>)
+00204 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[CVegetableVBAllocator::VBTypeLighted];
+00205 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a3">NL3D_VEGETABLE_RDRPASS_UNLIT</a>)
+00206 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[CVegetableVBAllocator::VBTypeUnlit];
+00207 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a4">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED</a>)
+00208 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[CVegetableVBAllocator::VBTypeUnlit];
+00209 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>)
+00210 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[CVegetableVBAllocator::VBTypeUnlit];
+00211 }
+00212
+00213 <font class="comment">// abnormal case</font>
+00214 <a class="code" href="debug_8h.html#a12">nlstop</a>;
+00215 <font class="comment">// To avoid warning;</font>
+00216 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[0];
+00217 }
+00218
+00219
+00220
+00221 <font class="comment">// ***************************************************************************</font>
+00222 <font class="comment">// ***************************************************************************</font>
+00223 <font class="comment">// Vertex Program.</font>
+00224 <font class="comment">// ***************************************************************************</font>
+00225 <font class="comment">// ***************************************************************************</font>
+00226
+00227
+00228 <font class="comment">// ***************************************************************************</font>
+00229 <font class="comment">/*</font>
+00230 <font class="comment"> Vegetable, without bend for now.</font>
+00231 <font class="comment"></font>
+00232 <font class="comment"> Inputs</font>
+00233 <font class="comment"> --------</font>
+00234 <font class="comment"> v[0] == Pos to Center of the vegetable in world space.</font>
+00235 <font class="comment"> v[10] == Center of the vegetable in world space.</font>
+00236 <font class="comment"> v[2] == Normal (present if lighted only)</font>
+00237 <font class="comment"> v[3] == Color (if unlit) or DiffuseColor (if lighted)</font>
+00238 <font class="comment"> v[4] == SecondaryColor (==ambient if Lighted or backFace color if Unlit)</font>
+00239 <font class="comment"> v[8] == Tex0 (xy) </font>
+00240 <font class="comment"> v[9] == BendInfo (xyz) = {BendWeight/2, BendPhase, BendFrequencyFactor}</font>
+00241 <font class="comment"> NB: /2 because compute a quaternion</font>
+00242 <font class="comment"></font>
+00243 <font class="comment"> Changes: If unlit, then small changes:</font>
+00244 <font class="comment"> v[0] == Pos to center, with v[0].w == BendWeight * v[0].norm()</font>
+00245 <font class="comment"> v[9] == BendInfo/BlendInfo (xyzw) = {v[0].norm(), BendPhase, BendFrequencyFactor, BlendDist}</font>
+00246 <font class="comment"></font>
+00247 <font class="comment"> NB: v[9].w. is used only in Unlit+2Sided+AlphaBlend. But prefer do this for gestion purpose:</font>
+00248 <font class="comment"> to have only one VBAllocator for all modes.</font>
+00249 <font class="comment"></font>
+00250 <font class="comment"> NB: Color and Secondary color Alpha Part contains Dynamic LightMap UV, (in 8 bits).</font>
+00251 <font class="comment"></font>
+00252 <font class="comment"> Constant:</font>
+00253 <font class="comment"> --------</font>
+00254 <font class="comment"> Setuped at beginning of CVegetableManager::render()</font>
+00255 <font class="comment"> c[0..3]= ModelViewProjection Matrix.</font>
+00256 <font class="comment"> c[4..7]= ModelView Matrix (for Fog).</font>
+00257 <font class="comment"> c[8]= {0, 1, 0.5, 2}</font>
+00258 <font class="comment"> c[9]= unit world space Directionnal light.</font>
+00259 <font class="comment"> c[10]= camera pos in world space.</font>
+00260 <font class="comment"> c[11]= {1/DistBlendTransition}</font>
+00261 <font class="comment"> NB: DiffuseColor and AmbientColor of vertex must have been pre-multiplied by lightColor</font>
+00262 <font class="comment"></font>
+00263 <font class="comment"> // Bend:</font>
+00264 <font class="comment"> c[16]= quaternion axis. w==1, and z must be 0</font>
+00265 <font class="comment"> c[17]= { timeAnim , WindPower, WindPower*(1-WindBendMin)/2, 0 }</font>
+00266 <font class="comment"> c[18]= High order Taylor cos coefficient: { -1/2, 1/24, -1/720, 1/40320 }</font>
+00267 <font class="comment"> c[19]= Low order Taylor cos coefficient: { 1, -1/2, 1/24, -1/720 }</font>
+00268 <font class="comment"> c[20]= Low order Taylor sin coefficient: { 1, -1/6, 1/120, -1/5040 }</font>
+00269 <font class="comment"> c[21]= Special constant vector for quatToMatrix: { 0, 1, -1, 0 }</font>
+00270 <font class="comment"> c[22]= {0.5, Pi, 2*Pi, 1/(2*Pi)}</font>
+00271 <font class="comment"> c[23]= {64, 0, 0, 0} (size of the LUT)</font>
+00272 <font class="comment"></font>
+00273 <font class="comment"> // Bend Lut:</font>
+00274 <font class="comment"> c[32..95] 64 Lut entries for cos-like animation</font>
+00275 <font class="comment"></font>
+00276 <font class="comment"></font>
+00277 <font class="comment"> Fog Note:</font>
+00278 <font class="comment"> -----------</font>
+00279 <font class="comment"> Fog should be disabled, because not computed (for speed consideration and becasue micro-vegetation should never</font>
+00280 <font class="comment"> be in Fog).</font>
+00281 <font class="comment"></font>
+00282 <font class="comment"></font>
+00283 <font class="comment"> Speed Note:</font>
+00284 <font class="comment"> -----------</font>
+00285 <font class="comment"> Max program length (lighted/2Sided) is:</font>
+00286 <font class="comment"> 29 (bend-quaternion) + </font>
+00287 <font class="comment"> 16 (rotNormal + bend + lit 2Sided) + </font>
+00288 <font class="comment"> 5 (proj + tex)</font>
+00289 <font class="comment"> 2 (Dynamic lightmap copy)</font>
+00290 <font class="comment"> 51</font>
+00291 <font class="comment"></font>
+00292 <font class="comment"> Normal program length (unlit/2Sided/No Alpha Blend) is:</font>
+00293 <font class="comment"> 12 (bend-delta) + </font>
+00294 <font class="comment"> 2 (unlit 2Sided) + </font>
+00295 <font class="comment"> 5 (proj + tex)</font>
+00296 <font class="comment"> 2 (Dynamic lightmap copy)</font>
+00297 <font class="comment"> 21</font>
+00298 <font class="comment"></font>
+00299 <font class="comment"> AlphaBlend program length (unlit/2Sided/Alpha Blend) is:</font>
+00300 <font class="comment"> 12 (bend-delta) + </font>
+00301 <font class="comment"> 2 (unlit 2Sided) + </font>
+00302 <font class="comment"> 5 (Alpha Blend)</font>
+00303 <font class="comment"> 5 (proj + tex)</font>
+00304 <font class="comment"> 2 (Dynamic lightmap copy)</font>
+00305 <font class="comment"> 26</font>
+00306 <font class="comment"></font>
+00307 <font class="comment">*/</font>
+00308
+00309
+00310 <font class="comment">// ***********************</font>
+00311 <font class="comment">/*</font>
+00312 <font class="comment"> Fast (but less accurate) Bend program:</font>
+00313 <font class="comment"> Result: bend pos into R5, </font>
+00314 <font class="comment">*/</font>
+00315 <font class="comment">// ***********************</font>
+00316 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a279">NL3D_FastBendProgram</a>=
+00317 <font class="stringliteral">"!!VP1.0 \n\</font>
+00318 <font class="stringliteral"> # compute time of animation: time*freqfactor + phase. \n\</font>
+00319 <font class="stringliteral"> MAD R0.x, c[17].x, v[9].z, v[9].y; # R0.x= time of animation \n\</font>
+00320 <font class="stringliteral"> \n\</font>
+00321 <font class="stringliteral"> # animation: use the 64 LUT entries \n\</font>
+00322 <font class="stringliteral"> EXP R0.y, R0.x; # fract part=&gt; R0.y= [0,1[ \n\</font>
+00323 <font class="stringliteral"> MUL R0, R0.y, c[23].xyyy; # R0.x= [0,64[ \n\</font>
+00324 <font class="stringliteral"> ARL A0.x, R0.x; # A0.x= index in the LUT \n\</font>
+00325 <font class="stringliteral"> EXP R0.y, R0.x; # R0.y= R0.x-A0.x= fp (fract part) \n\</font>
+00326 <font class="stringliteral"> # lookup and lerp in one it: R0= value + fp * dv. \n\</font>
+00327 <font class="stringliteral"> MAD R0.xy, R0.y, c[A0.x+32].zwww, c[A0.x+32].xyww; \n\</font>
+00328 <font class="stringliteral"> \n\</font>
+00329 <font class="stringliteral"> # The direction and power of the wind is encoded in the LUT. \n\</font>
+00330 <font class="stringliteral"> # Scale now by vertex BendFactor (stored in v[0].w) \n\</font>
+00331 <font class="stringliteral"> MAD R5, R0, v[0].w, v[0].xyzw; \n\</font>
+00332 <font class="stringliteral"> # compute 1/norm, and multiply by original norm stored in v[9].x \n\</font>
+00333 <font class="stringliteral"> DP3 R0.x, R5, R5; \n\</font>
+00334 <font class="stringliteral"> RSQ R0.x, R0.x; \n\</font>
+00335 <font class="stringliteral"> MUL R0.x, R0.x, v[9].x; \n\</font>
+00336 <font class="stringliteral"> # mul by this factor, and add to center \n\</font>
+00337 <font class="stringliteral"> MAD R5, R0.xxxw, R5, v[10]; \n\</font>
+00338 <font class="stringliteral"> \n\</font>
+00339 <font class="stringliteral"> # make local to camera pos. Important for ZBuffer precision \n\</font>
+00340 <font class="stringliteral"> ADD R5, R5, -c[10]; \n\</font>
+00341 <font class="stringliteral">"</font>;
+00342
+00343
+00344 <font class="comment">// Test</font>
+00345 <font class="comment">/*const char* NL3D_FastBendProgram=</font>
+00346 <font class="comment">"!!VP1.0 \n\</font>
+00347 <font class="comment"> # compute time of animation: time + phase. \n\</font>
+00348 <font class="comment"> ADD R0.x, c[17].x, v[9].y; # R0.x= time of animation \n\</font>
+00349 <font class="comment"> \n\</font>
+00350 <font class="comment"> # animation: f(x)= cos(x). compute a high precision cosinus \n\</font>
+00351 <font class="comment"> EXP R0.y, R0.x; # fract part=&gt; R0.y= [0,1] &lt;=&gt; [-Pi, Pi] \n\</font>
+00352 <font class="comment"> MAD R0.x, R0.y, c[22].z, -c[22].y; # R0.x= a= [-Pi, Pi] \n\</font>
+00353 <font class="comment"> # R0 must get a2, a4, a6, a8 \n\</font>
+00354 <font class="comment"> MUL R0.x, R0.x, R0.x; # R0.x= a2 \n\</font>
+00355 <font class="comment"> MUL R0.y, R0.x, R0.x; # R0= a2, a4 \n\</font>
+00356 <font class="comment"> MUL R0.zw, R0.y, R0.xxxy; # R0= a2, a4, a6, a8 \n\</font>
+00357 <font class="comment"> # Taylor serie: cos(x)= 1 - (1/2) a2 + (1/24) a4 - (1/720) a6 + (1/40320) a8. \n\</font>
+00358 <font class="comment"> DP4 R0.x, R0, c[18]; # R0.x= cos(x) - 1. \n\</font>
+00359 <font class="comment"> \n\</font>
+00360 <font class="comment"> \n\</font>
+00361 <font class="comment"> # original norm \n\</font>
+00362 <font class="comment"> DP3 R2.x, v[0], v[0]; \n\</font>
+00363 <font class="comment"> RSQ R2.y, R2.x; \n\</font>
+00364 <font class="comment"> MUL R2.x, R2.x, R2.y; \n\</font>
+00365 <font class="comment"> # norm, mul by factor, and add to relpos \n\</font>
+00366 <font class="comment"> ADD R1.x, R0.x, c[8].w; \n\</font>
+00367 <font class="comment"> MUL R0.x, v[9].x, R2.x; \n\</font>
+00368 <font class="comment"> MUL R1, R1, R0.x; \n\</font>
+00369 <font class="comment"> ADD R5.xyz, R1, v[0]; \n\</font>
+00370 <font class="comment"> # mod norm \n\</font>
+00371 <font class="comment"> DP3 R0.x, R5, R5; \n\</font>
+00372 <font class="comment"> RSQ R0.x, R0.x; \n\</font>
+00373 <font class="comment"> MUL R0.x, R0.x, R2.x; \n\</font>
+00374 <font class="comment"> MAD R5, R0.x, R5, v[10]; \n\</font>
+00375 <font class="comment">";*/</font>
+00376
+00377
+00378
+00379 <font class="comment">// ***********************</font>
+00380 <font class="comment">/*</font>
+00381 <font class="comment"> Bend start program:</font>
+00382 <font class="comment"> Result: bend pos into R5, and R7,R8,R9 is the rotation matrix for possible normal lighting.</font>
+00383 <font class="comment">*/</font>
+00384 <font class="comment">// ***********************</font>
+00385 <font class="comment">// Splitted in 2 parts because of the 2048 char limit</font>
+00386 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a280">NL3D_BendProgramP0</a>=
+00387 <font class="stringliteral">"!!VP1.0 \n\</font>
+00388 <font class="stringliteral"> # compute time of animation: time*freqfactor + phase. \n\</font>
+00389 <font class="stringliteral"> MAD R0.x, c[17].x, v[9].z, v[9].y; # R0.x= time of animation \n\</font>
+00390 <font class="stringliteral"> \n\</font>
+00391 <font class="stringliteral"> # animation: f(x)= cos(x). compute a high precision cosinus \n\</font>
+00392 <font class="stringliteral"> EXP R0.y, R0.x; # fract part=&gt; R0.y= [0,1] &lt;=&gt; [-Pi, Pi] \n\</font>
+00393 <font class="stringliteral"> MAD R0.x, R0.y, c[22].z, -c[22].y; # R0.x= a= [-Pi, Pi] \n\</font>
+00394 <font class="stringliteral"> # R0 must get a2, a4, a6, a8 \n\</font>
+00395 <font class="stringliteral"> MUL R0.x, R0.x, R0.x; # R0.x= a2 \n\</font>
+00396 <font class="stringliteral"> MUL R0.y, R0.x, R0.x; # R0= a2, a4 \n\</font>
+00397 <font class="stringliteral"> MUL R0.zw, R0.y, R0.xxxy; # R0= a2, a4, a6, a8 \n\</font>
+00398 <font class="stringliteral"> # Taylor serie: cos(x)= 1 - (1/2) a2 + (1/24) a4 - (1/720) a6 + (1/40320) a8. \n\</font>
+00399 <font class="stringliteral"> DP4 R0.x, R0, c[18]; # R0.x= cos(x) - 1. \n\</font>
+00400 <font class="stringliteral"> \n\</font>
+00401 <font class="stringliteral"> # R0.x= [-2, 0]. And we want a result in BendWeight/2*WindPower*[WindBendMin, 1] \n\</font>
+00402 <font class="stringliteral"> MAD R0.x, R0.x, c[17].z, c[17].y; # R0.x= WindPower*[WindBendMin, 1] \n\</font>
+00403 <font class="stringliteral"> MUL R0.x, R0.x, v[9].x; # R0.x= angle= BendWeight/2*WindPower*[WindBendMin, 1] \n\</font>
+00404 <font class="stringliteral"> \n\</font>
+00405 <font class="stringliteral"> # compute good precision sinus and cosinus, in R0.xy. \n\</font>
+00406 <font class="stringliteral"> # suppose that BendWeightMax/2== 2Pi/3 =&gt; do not need to fmod() nor \n\</font>
+00407 <font class="stringliteral"> # to have high order taylor serie \n\</font>
+00408 <font class="stringliteral"> DST R1.xy, R0.x, R0.x; # R1= 1, a2 \n\</font>
+00409 <font class="stringliteral"> MUL R1.z, R1.y, R1.y; # R1= 1, a2, a4 \n\</font>
+00410 <font class="stringliteral"> MUL R1.w, R1.y, R1.z; # R1= 1, a2, a4, a6 (cos serie) \n\</font>
+00411 <font class="stringliteral"> MUL R2, R1, R0.x; # R2= a, a3, a5, a7 (sin serie) \n\</font>
+00412 <font class="stringliteral"> DP4 R0.x, R1, c[19]; # R0.x= cos(a) \n\</font>
+00413 <font class="stringliteral"> DP4 R0.y, R2, c[20]; # R0.y= sin(a) \n\</font>
+00414 <font class="stringliteral">"</font>;
+00415 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a281">NL3D_BendProgramP1</a>=
+00416 <font class="stringliteral">" \n\</font>
+00417 <font class="stringliteral"> # build our quaternion \n\</font>
+00418 <font class="stringliteral"> # multiply the angleAxis by sin(a) / cos(a), where a is actually a/2 \n\</font>
+00419 <font class="stringliteral"> # remind: c[16].z== angleAxis.z== 0 \n\</font>
+00420 <font class="stringliteral"> MUL R0, c[16], R0.yyyx; # R0= quaternion.xyzw \n\</font>
+00421 <font class="stringliteral"> \n\</font>
+00422 <font class="stringliteral"> # build our matrix from this quaternion, into R7,R8,R9 \n\</font>
+00423 <font class="stringliteral"> # Quaternion TO matrix 3x3 in 7 ope, with quat.z==0 \n\</font>
+00424 <font class="stringliteral"> MUL R1, R0, c[8].w; # R1= quat2= 2*quat == 2*x, 2*y, 0, 2*w \n\</font>
+00425 <font class="stringliteral"> MUL R2, R1, R0.x; # R2= quatX= xx, xy, 0, wx \n\</font>
+00426 <font class="stringliteral"> MUL R3, R1, R0.y; # R3= quatY= xy, yy, 0, wy \n\</font>
+00427 <font class="stringliteral"> # NB: c[21]= {0, 1, -1, 0} \n\</font>
+00428 <font class="stringliteral"> # Write to w, then w = 0, this avoid an unitialized component \n\</font>
+00429 <font class="stringliteral"> MAD R7.xyzw, c[21].zyyw, R3.yxww, c[21].yxxw; \n\</font>
+00430 <font class="stringliteral"> # R7.x= a11 = 1.0f - (yy) \n\</font>
+00431 <font class="stringliteral"> # R7.y= a12 = xy \n\</font>
+00432 <font class="stringliteral"> # R7.z= a13 = wy \n\</font>
+00433 <font class="stringliteral"> # NB: c[21]= {0, 1, -1, 0} \n\</font>
+00434 <font class="stringliteral"> # Write to w, then w = 0, this avoid an unitialized component \n\</font>
+00435 <font class="stringliteral"> MAD R8.xyzw, c[21].yzzw, R2.yxww, c[21].xyxw; \n\</font>
+00436 <font class="stringliteral"> # R8.x= a21 = xy \n\</font>
+00437 <font class="stringliteral"> # R8.y= a22 = 1.0f - (xx) \n\</font>
+00438 <font class="stringliteral"> # R8.z= a23 = - wx \n\</font>
+00439 <font class="stringliteral"> # NB: c[21]= {0, 1, -1, 0} \n\</font>
+00440 <font class="stringliteral"> # Write to w, then w = 0, this avoid an unitialized component \n\</font>
+00441 <font class="stringliteral"> ADD R9.xyzw, R2.zwxw, R3.wzyw; # a31= 0+wy, a32= wx+0, a33= xx + yy, because z==0 \n\</font>
+00442 <font class="stringliteral"> MAD R9.xyzw, R9.xyzw, c[21].zyzw, c[21].xxyw; \n\</font>
+00443 <font class="stringliteral"> # R9.x= a31 = - wy \n\</font>
+00444 <font class="stringliteral"> # R9.y= a32 = wx \n\</font>
+00445 <font class="stringliteral"> # R9.z= a33 = 1.0f - (xx + yy) \n\</font>
+00446 <font class="stringliteral"> # transform pos \n\</font>
+00447 <font class="stringliteral"> DP3 R5.x, R7, v[0]; \n\</font>
+00448 <font class="stringliteral"> DP3 R5.y, R8, v[0]; \n\</font>
+00449 <font class="stringliteral"> DP3 R5.z, R9, v[0]; # R5= bended relative pos to center. \n\</font>
+00450 <font class="stringliteral"> #temp, to optimize \n\</font>
+00451 <font class="stringliteral"> MOV R5.w, c[21].w; \n\</font>
+00452 <font class="stringliteral"> # add pos to center pos. \n\</font>
+00453 <font class="stringliteral"> ADD R5, R5, v[10]; # R5= world pos. R5.w= R5.w+v[10].w= 0+1= 1 \n\</font>
+00454 <font class="stringliteral"> # make local to camera pos. Important for ZBuffer precision \n\</font>
+00455 <font class="stringliteral"> ADD R5, R5, -c[10]; \n\</font>
+00456 <font class="stringliteral">"</font>;
+00457
+00458
+00459 <font class="comment">// Concat the 2 strings</font>
+00460 <font class="keyword">const</font> string <a class="code" href="namespaceNL3D.html#a282">NL3D_BendProgram</a>= string(<a class="code" href="namespaceNL3D.html#a280">NL3D_BendProgramP0</a>) + string(<a class="code" href="namespaceNL3D.html#a281">NL3D_BendProgramP1</a>);
+00461
+00462
+00463
+00464 <font class="comment">// ***********************</font>
+00465 <font class="comment">/*</font>
+00466 <font class="comment"> Lighted start program:</font>
+00467 <font class="comment"> bend pos and normal, normalize and lit</font>
+00468 <font class="comment">*/</font>
+00469 <font class="comment">// ***********************</font>
+00470 <font class="comment">// Common start program.</font>
+00471 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a283">NL3D_LightedStartVegetableProgram</a>=
+00472 <font class="stringliteral">" \n\</font>
+00473 <font class="stringliteral"> # bend Pos into R5. Now do it for normal \n\</font>
+00474 <font class="stringliteral"> DP3 R0.x, R7, v[2]; \n\</font>
+00475 <font class="stringliteral"> DP3 R0.y, R8, v[2]; \n\</font>
+00476 <font class="stringliteral"> DP3 R0.z, R9, v[2]; # R0= matRot * normal. \n\</font>
+00477 <font class="stringliteral"> # Do the rot 2 times for normal (works fine) \n\</font>
+00478 <font class="stringliteral"> DP3 R6.x, R7, R0; \n\</font>
+00479 <font class="stringliteral"> DP3 R6.y, R8, R0; \n\</font>
+00480 <font class="stringliteral"> DP3 R6.z, R9, R0; # R6= bended normal. \n\</font>
+00481 <font class="stringliteral"> \n\</font>
+00482 <font class="stringliteral"> # Normalize normal, and dot product, into R0.x \n\</font>
+00483 <font class="stringliteral"> # w hasn't been written \n\</font>
+00484 <font class="stringliteral"> DP3 R0.x, R6.xyzz, R6.xyzz; # R0.x= R6.sqrnorm() \n\</font>
+00485 <font class="stringliteral"> RSQ R0.x, R0.x; # R0.x= 1/norm() \n\</font>
+00486 <font class="stringliteral"> MUL R6, R6.xyzz, R0.x; # R6= R6.normed() \n\</font>
+00487 <font class="stringliteral"> DP3 R0.x, R6, c[9]; \n\</font>
+00488 <font class="stringliteral">"</font>;
+00489
+00490
+00491 <font class="comment">// 1Sided lighting.</font>
+00492 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a284">NL3D_LightedMiddle1SidedVegetableProgram</a>=
+00493 <font class="stringliteral">" #FrontFacing \n\</font>
+00494 <font class="stringliteral"> MAX R0.y, -R0.x, c[8].x; # R0.y= diffFactor= max(0, -R6*LightDir) \n\</font>
+00495 <font class="stringliteral"> MUL R1.xyz, R0.y, v[3]; # R7= diffFactor*DiffuseColor \n\</font>
+00496 <font class="stringliteral"> ADD o[COL0].xyz, R1, v[4]; # col0.RGB= AmbientColor + diffFactor*DiffuseColor \n\</font>
+00497 <font class="stringliteral">"</font>;
+00498
+00499
+00500 <font class="comment">// 2Sided lighting.</font>
+00501 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a285">NL3D_LightedMiddle2SidedVegetableProgram</a>=
+00502 <font class="stringliteral">" #FrontFacing \n\</font>
+00503 <font class="stringliteral"> MAX R0.y, -R0.x, c[8].x; # R0.y= diffFactor= max(0, -R6*LightDir) \n\</font>
+00504 <font class="stringliteral"> MUL R1.xyz, R0.y, v[3]; # R7= diffFactor*DiffuseColor \n\</font>
+00505 <font class="stringliteral"> ADD o[COL0].xyz, R1, v[4]; # col0.RGB= AmbientColor + diffFactor*DiffuseColor \n\</font>
+00506 <font class="stringliteral"> # BackFacing. \n\</font>
+00507 <font class="stringliteral"> MAX R0.y, R0.x, c[8].x; # R0.y= diffFactor= max(0, -(-R6)*LightDir) \n\</font>
+00508 <font class="stringliteral"> MUL R1.xyz, R0.y, v[3]; # R7= diffFactor*DiffuseColor \n\</font>
+00509 <font class="stringliteral"> ADD o[BFC0].xyz, R1, v[4]; # bfc0.RGB= AmbientColor + diffFactor*DiffuseColor \n\</font>
+00510 <font class="stringliteral">"</font>;
+00511
+00512
+00513 <font class="comment">// ***********************</font>
+00514 <font class="comment">/*</font>
+00515 <font class="comment"> Unlit start program:</font>
+00516 <font class="comment"> bend pos into R5, and copy color(s)</font>
+00517 <font class="comment">*/</font>
+00518 <font class="comment">// ***********************</font>
+00519
+00520
+00521 <font class="comment">// Common start program.</font>
+00522 <font class="comment">// nothing to add.</font>
+00523 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a286">NL3D_UnlitStartVegetableProgram</a>=
+00524 <font class="stringliteral">""</font>;
+00525
+00526
+00527 <font class="comment">// 1Sided "lighting".</font>
+00528 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a287">NL3D_UnlitMiddle1SidedVegetableProgram</a>=
+00529 <font class="stringliteral">" MOV o[COL0].xyz, v[3]; # col.RGBA= vertex color \n\</font>
+00530 <font class="stringliteral"> \n\</font>
+00531 <font class="stringliteral">"</font>;
+00532
+00533
+00534 <font class="comment">// 2Sided "lighting".</font>
+00535 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a288">NL3D_UnlitMiddle2SidedVegetableProgram</a>=
+00536 <font class="stringliteral">" MOV o[COL0].xyz, v[3]; # col.RGBA= vertex color \n\</font>
+00537 <font class="stringliteral"> MOV o[BFC0].xyz, v[4]; # bfc0.RGBA= bcf color \n\</font>
+00538 <font class="stringliteral"> \n\</font>
+00539 <font class="stringliteral">"</font>;
+00540
+00541
+00542 <font class="comment">// 2Sided "lighting" + AlphaBlend.</font>
+00543 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a289">NL3D_UnlitMiddle2SidedAlphaBlendVegetableProgram</a>=
+00544 <font class="stringliteral">" MOV o[COL0].xyz, v[3]; # col.RGBA= vertex color \n\</font>
+00545 <font class="stringliteral"> MOV o[BFC0].xyz, v[4]; # bfc0.RGBA= bcf color \n\</font>
+00546 <font class="stringliteral"> \n\</font>
+00547 <font class="stringliteral"> #Blend transition. NB: in R5, we already have the position relative to the camera \n\</font>
+00548 <font class="stringliteral"> DP3 R0.x, R5, R5; # R0.x= sqr(dist to viewer). \n\</font>
+00549 <font class="stringliteral"> RSQ R0.y, R0.x; \n\</font>
+00550 <font class="stringliteral"> MUL R0.x, R0.x, R0.y; # R0.x= dist to viewer \n\</font>
+00551 <font class="stringliteral"> # setup alpha Blending. Distance of appartition is encoded in the vertex. \n\</font>
+00552 <font class="stringliteral"> MAD o[COL0].w, R0.x, c[11].x, v[9].w; \n\</font>
+00553 <font class="stringliteral"> MAD o[BFC0].w, R0.x, c[11].x, v[9].w; \n\</font>
+00554 <font class="stringliteral">"</font>;
+00555
+00556
+00557 <font class="comment">// 1Sided "lighting" + AlphaBlend.</font>
+00558 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a290">NL3D_UnlitMiddle1SidedAlphaBlendVegetableProgram</a>=
+00559 <font class="stringliteral">" MOV o[COL0].xyz, v[3]; # col.RGBA= vertex color \n\</font>
+00560 <font class="stringliteral"> \n\</font>
+00561 <font class="stringliteral"> #Blend transition. NB: in R5, we already have the position relative to the camera \n\</font>
+00562 <font class="stringliteral"> DP3 R0.x, R5, R5; # R0.x= sqr(dist to viewer). \n\</font>
+00563 <font class="stringliteral"> RSQ R0.y, R0.x; \n\</font>
+00564 <font class="stringliteral"> MUL R0.x, R0.x, R0.y; # R0.x= dist to viewer \n\</font>
+00565 <font class="stringliteral"> # setup alpha Blending. Distance of appartition is encoded in the vertex. \n\</font>
+00566 <font class="stringliteral"> MAD o[COL0].w, R0.x, c[11].x, v[9].w; \n\</font>
+00567 <font class="stringliteral">"</font>;
+00568
+00569
+00570
+00571
+00572 <font class="comment">// ***********************</font>
+00573 <font class="comment">/*</font>
+00574 <font class="comment"> Common end of program: project, texture. Take pos from R5</font>
+00575 <font class="comment">*/</font>
+00576 <font class="comment">// ***********************</font>
+00577 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a291">NL3D_CommonEndVegetableProgram</a>=
+00578 <font class="stringliteral">" # compute in Projection space \n\</font>
+00579 <font class="stringliteral"> DP4 o[HPOS].x, c[0], R5; \n\</font>
+00580 <font class="stringliteral"> DP4 o[HPOS].y, c[1], R5; \n\</font>
+00581 <font class="stringliteral"> DP4 o[HPOS].z, c[2], R5; \n\</font>
+00582 <font class="stringliteral"> DP4 o[HPOS].w, c[3], R5; \n\</font>
+00583 <font class="stringliteral"> # copy Dynamic lightmap UV in stage0, from colors Alpha part. \n\</font>
+00584 <font class="stringliteral"> MOV o[TEX0].x, v[3].w; \n\</font>
+00585 <font class="stringliteral"> MOV o[TEX0].y, v[4].w; \n\</font>
+00586 <font class="stringliteral"> # copy diffuse texture uv to stage 1. \n\</font>
+00587 <font class="stringliteral"> MOV o[TEX1].xy, v[8]; \n\</font>
+00588 <font class="stringliteral"> END \n\</font>
+00589 <font class="stringliteral">"</font>;
+00590
+00591
+00592 <font class="comment">// ***********************</font>
+00593 <font class="comment">/* </font>
+00594 <font class="comment"> Speed test VP, No bend,no lighting.</font>
+00595 <font class="comment">*/</font>
+00596 <font class="comment">// ***********************</font>
+00597 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a292">NL3D_SimpleStartVegetableProgram</a>=
+00598 <font class="stringliteral">"!!VP1.0 \n\</font>
+00599 <font class="stringliteral"> # compute in Projection space \n\</font>
+00600 <font class="stringliteral"> MOV R5, v[0]; \n\</font>
+00601 <font class="stringliteral"> ADD R5.xyz, R5, v[10]; \n\</font>
+00602 <font class="stringliteral"> # make local to camera pos \n\</font>
+00603 <font class="stringliteral"> ADD R5, R5, -c[10]; \n\</font>
+00604 <font class="stringliteral"> MOV o[COL0], c[8].yyyy; \n\</font>
+00605 <font class="stringliteral"> MOV o[BFC0], c[8].xxyy; \n\</font>
+00606 <font class="stringliteral">"</font>;
+00607
+00608
+00609
+00610 <font class="comment">// ***************************************************************************</font>
+<a name="l00611"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#c2">00611</a> <font class="keywordtype">void</font> CVegetableManager::initVertexProgram(uint vpType)
+00612 {
+00613 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#o14">_LastDriver</a>); <font class="comment">// update driver should have been called at least once !</font>
+00614 <font class="comment">// Init the Vertex Program.</font>
+00615 string vpgram;
+00616 <font class="comment">// start always with Bend.</font>
+00617 <font class="keywordflow">if</font>( vpType==<a class="code" href="vegetable__def_8h.html#a1">NL3D_VEGETABLE_RDRPASS_LIGHTED</a> || vpType==<a class="code" href="vegetable__def_8h.html#a2">NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED</a> )
+00618 vpgram= <a class="code" href="namespaceNL3D.html#a282">NL3D_BendProgram</a>;
+00619 <font class="keywordflow">else</font>
+00620 vpgram= <a class="code" href="namespaceNL3D.html#a279">NL3D_FastBendProgram</a>;
+00621
+00622 <font class="comment">// If double sided V.P are not supported, switch to 1-sided version</font>
+00623 <font class="keywordtype">bool</font> doubleSided = <a class="code" href="classNL3D_1_1CVegetableManager.html#o14">_LastDriver</a>-&gt;supportVertexProgramDoubleSidedColor();
+00624
+00625 <font class="comment">// combine the VP according to Type</font>
+00626 <font class="keywordflow">switch</font>(vpType)
+00627 {
+00628 <font class="keywordflow">case</font> <a class="code" href="vegetable__def_8h.html#a1">NL3D_VEGETABLE_RDRPASS_LIGHTED</a>:
+00629 vpgram+= string(<a class="code" href="namespaceNL3D.html#a283">NL3D_LightedStartVegetableProgram</a>);
+00630 vpgram+= string(<a class="code" href="namespaceNL3D.html#a284">NL3D_LightedMiddle1SidedVegetableProgram</a>);
+00631 <font class="keywordflow">break</font>;
+00632 <font class="keywordflow">case</font> <a class="code" href="vegetable__def_8h.html#a2">NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED</a>:
+00633 vpgram+= string(<a class="code" href="namespaceNL3D.html#a283">NL3D_LightedStartVegetableProgram</a>);
+00634 vpgram+= string(doubleSided ? <a class="code" href="namespaceNL3D.html#a285">NL3D_LightedMiddle2SidedVegetableProgram</a>
+00635 : <a class="code" href="namespaceNL3D.html#a284">NL3D_LightedMiddle1SidedVegetableProgram</a>);
+00636 <font class="keywordflow">break</font>;
+00637 <font class="keywordflow">case</font> <a class="code" href="vegetable__def_8h.html#a3">NL3D_VEGETABLE_RDRPASS_UNLIT</a>:
+00638 vpgram+= string(<a class="code" href="namespaceNL3D.html#a286">NL3D_UnlitStartVegetableProgram</a>);
+00639 vpgram+= string(<a class="code" href="namespaceNL3D.html#a287">NL3D_UnlitMiddle1SidedVegetableProgram</a>);
+00640 <font class="keywordflow">break</font>;
+00641 <font class="keywordflow">case</font> <a class="code" href="vegetable__def_8h.html#a4">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED</a>:
+00642 vpgram+= string(<a class="code" href="namespaceNL3D.html#a286">NL3D_UnlitStartVegetableProgram</a>);
+00643 vpgram+= string(doubleSided ? <a class="code" href="namespaceNL3D.html#a288">NL3D_UnlitMiddle2SidedVegetableProgram</a>
+00644 : <a class="code" href="namespaceNL3D.html#a287">NL3D_UnlitMiddle1SidedVegetableProgram</a>
+00645 );
+00646 <font class="keywordflow">break</font>;
+00647 <font class="keywordflow">case</font> <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>:
+00648 vpgram+= string(<a class="code" href="namespaceNL3D.html#a286">NL3D_UnlitStartVegetableProgram</a>);
+00649 vpgram+= string(doubleSided ? <a class="code" href="namespaceNL3D.html#a289">NL3D_UnlitMiddle2SidedAlphaBlendVegetableProgram</a>
+00650 : <a class="code" href="namespaceNL3D.html#a290">NL3D_UnlitMiddle1SidedAlphaBlendVegetableProgram</a>
+00651 );
+00652 <font class="keywordflow">break</font>;
+00653 }
+00654
+00655 <font class="comment">// common end of VP</font>
+00656 vpgram+= string(<a class="code" href="namespaceNL3D.html#a291">NL3D_CommonEndVegetableProgram</a>);
+00657
+00658 <font class="comment">// create VP.</font>
+00659 <a class="code" href="classNL3D_1_1CVegetableManager.html#o8">_VertexProgram</a>[vpType]= <font class="keyword">new</font> CVertexProgram(vpgram.c_str());
+00660
+00661 }
+00662
+00663
+00664 <font class="comment">// ***************************************************************************</font>
+00665 <font class="comment">// ***************************************************************************</font>
+00666 <font class="comment">// Instanciation</font>
+00667 <font class="comment">// ***************************************************************************</font>
+00668 <font class="comment">// ***************************************************************************</font>
+00669
+00670
+00671 <font class="comment">// ***************************************************************************</font>
+<a name="l00672"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z882_0">00672</a> CVegetableClipBlock *CVegetableManager::createClipBlock()
+00673 {
+00674 <font class="comment">// create a clipblock</font>
+00675 CVegetableClipBlock *ret;
+00676 ret= <a class="code" href="classNL3D_1_1CVegetableManager.html#o0">_ClipBlockMemory</a>.<a class="code" href="classNLMISC_1_1CBlockMemory.html#a3">allocate</a>();
+00677
+00678 <font class="comment">// append to list.</font>
+00679 <a class="code" href="classNL3D_1_1CVegetableManager.html#o4">_EmptyClipBlockList</a>.append(ret);
+00680
+00681 <font class="keywordflow">return</font> ret;
+00682 }
+00683
+00684 <font class="comment">// ***************************************************************************</font>
+<a name="l00685"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z882_1">00685</a> <font class="keywordtype">void</font> CVegetableManager::deleteClipBlock(CVegetableClipBlock *clipBlock)
+00686 {
+00687 <font class="keywordflow">if</font>(!clipBlock)
+00688 <font class="keywordflow">return</font>;
+00689
+00690 <font class="comment">// verify no more sortBlocks in this clipblock</font>
+00691 <a class="code" href="debug_8h.html#a6">nlassert</a>(clipBlock-&gt;_SortBlockList.size() == 0);
+00692
+00693 <font class="comment">// unlink from _EmptyClipBlockList, because _InstanceGroupList.size() == 0 ...</font>
+00694 <a class="code" href="classNL3D_1_1CVegetableManager.html#o4">_EmptyClipBlockList</a>.remove(clipBlock);
+00695
+00696 <font class="comment">// delete</font>
+00697 <a class="code" href="classNL3D_1_1CVegetableManager.html#o0">_ClipBlockMemory</a>.<a class="code" href="classNLMISC_1_1CBlockMemory.html#a4">free</a>(clipBlock);
+00698 }
+00699
+00700
+00701 <font class="comment">// ***************************************************************************</font>
+<a name="l00702"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z882_2">00702</a> CVegetableSortBlock *CVegetableManager::createSortBlock(CVegetableClipBlock *clipBlock, <font class="keyword">const</font> CVector &amp;center, <font class="keywordtype">float</font> radius)
+00703 {
+00704 <a class="code" href="debug_8h.html#a6">nlassert</a>(clipBlock);
+00705
+00706 <font class="comment">// create a clipblock</font>
+00707 CVegetableSortBlock *ret;
+00708 ret= <a class="code" href="classNL3D_1_1CVegetableManager.html#o1">_SortBlockMemory</a>.<a class="code" href="classNLMISC_1_1CBlockMemory.html#a3">allocate</a>();
+00709 ret-&gt;_Owner= clipBlock;
+00710 ret-&gt;_Center= center;
+00711 ret-&gt;_Radius= radius;
+00712
+00713 <font class="comment">// append to list.</font>
+00714 clipBlock-&gt;_SortBlockList.append(ret);
+00715
+00716 <font class="keywordflow">return</font> ret;
+00717 }
+00718
+00719 <font class="comment">// ***************************************************************************</font>
+<a name="l00720"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z882_3">00720</a> <font class="keywordtype">void</font> CVegetableManager::deleteSortBlock(CVegetableSortBlock *sortBlock)
+00721 {
+00722 <font class="keywordflow">if</font>(!sortBlock)
+00723 <font class="keywordflow">return</font>;
+00724
+00725 <font class="comment">// verify no more IGs in this sortblock</font>
+00726 <a class="code" href="debug_8h.html#a6">nlassert</a>(sortBlock-&gt;_InstanceGroupList.size() == 0);
+00727
+00728 <font class="comment">// unlink from clipBlock</font>
+00729 sortBlock-&gt;_Owner-&gt;_SortBlockList.remove(sortBlock);
+00730
+00731 <font class="comment">// delete</font>
+00732 <a class="code" href="classNL3D_1_1CVegetableManager.html#o1">_SortBlockMemory</a>.<a class="code" href="classNLMISC_1_1CBlockMemory.html#a4">free</a>(sortBlock);
+00733 }
+00734
+00735
+00736 <font class="comment">// ***************************************************************************</font>
+<a name="l00737"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z882_4">00737</a> CVegetableInstanceGroup *CVegetableManager::createIg(CVegetableSortBlock *sortBlock)
+00738 {
+00739 <a class="code" href="debug_8h.html#a6">nlassert</a>(sortBlock);
+00740 CVegetableClipBlock *clipBlock= sortBlock-&gt;_Owner;
+00741
+00742
+00743 <font class="comment">// create an IG</font>
+00744 CVegetableInstanceGroup *ret;
+00745 ret= <a class="code" href="classNL3D_1_1CVegetableManager.html#o2">_InstanceGroupMemory</a>.<a class="code" href="classNLMISC_1_1CBlockMemory.html#a3">allocate</a>();
+00746 ret-&gt;_SortOwner= sortBlock;
+00747 ret-&gt;_ClipOwner= clipBlock;
+00748
+00749 <font class="comment">// if the clipBlock is empty, change list, because won't be no more.</font>
+00750 <font class="keywordflow">if</font>(clipBlock-&gt;_NumIgs==0)
+00751 {
+00752 <font class="comment">// remove from empty list</font>
+00753 <a class="code" href="classNL3D_1_1CVegetableManager.html#o4">_EmptyClipBlockList</a>.remove(clipBlock);
+00754 <font class="comment">// and append to not empty one.</font>
+00755 <a class="code" href="classNL3D_1_1CVegetableManager.html#o3">_ClipBlockList</a>.append(clipBlock);
+00756 }
+00757
+00758 <font class="comment">// inc the number of igs appended to the clipBlock.</font>
+00759 clipBlock-&gt;_NumIgs++;
+00760
+00761 <font class="comment">// link ig to sortBlock.</font>
+00762 sortBlock-&gt;_InstanceGroupList.append(ret);
+00763
+00764 <font class="comment">// Special Init: The ZSort rdrPass must start with the same HardMode than SortBlock.</font>
+00765 ret-&gt;_RdrPass[<a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>].HardMode= sortBlock-&gt;ZSortHardMode;
+00766
+00767 <font class="keywordflow">return</font> ret;
+00768 }
+00769
+00770 <font class="comment">// ***************************************************************************</font>
+<a name="l00771"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z882_5">00771</a> <font class="keywordtype">void</font> CVegetableManager::deleteIg(CVegetableInstanceGroup *ig)
+00772 {
+00773 <font class="keywordflow">if</font>(!ig)
+00774 <font class="keywordflow">return</font>;
+00775
+00776 <font class="comment">// update lighting mgt: no more vertices.</font>
+00777 <font class="comment">// -----------</font>
+00778 <font class="comment">// If I delete the ig which is the current root</font>
+00779 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a> == ig)
+00780 {
+00781 <font class="comment">// switch to next</font>
+00782 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>= ig-&gt;_ULNext;
+00783 <font class="comment">// if still the same, it means that the circular list is now empty</font>
+00784 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a> == ig)
+00785 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>= NULL;
+00786 <font class="comment">// Reset UL instance info.</font>
+00787 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>= 0;
+00788 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>= 0;
+00789 }
+00790 <font class="comment">// remove UL vertex count of the deleted ig</font>
+00791 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_8">_ULNTotalVertices</a>-= ig-&gt;_ULNumVertices;
+00792 <font class="comment">// unlink the ig for lighting update.</font>
+00793 ig-&gt;unlinkUL();
+00794
+00795
+00796 <font class="comment">// For all render pass of this instance, delete his vertices</font>
+00797 <font class="comment">// -----------</font>
+00798 <font class="keywordflow">for</font>(sint rdrPass=0; rdrPass &lt; <a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; rdrPass++)
+00799 {
+00800 <font class="comment">// rdrPass</font>
+00801 CVegetableInstanceGroup::CVegetableRdrPass &amp;vegetRdrPass= ig-&gt;_RdrPass[rdrPass];
+00802 <font class="comment">// which allocator?</font>
+00803 CVegetableVBAllocator &amp;vbAllocator= <a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPass, vegetRdrPass.HardMode);
+00804
+00805 <font class="comment">// For all vertices of this rdrPass, delete it</font>
+00806 sint numVertices;
+00807 numVertices= vegetRdrPass.Vertices.size();
+00808 <font class="comment">// all vertices must have been setuped.</font>
+00809 <a class="code" href="debug_8h.html#a6">nlassert</a>((uint)numVertices == vegetRdrPass.NVertices);
+00810 <font class="keywordflow">for</font>(sint i=0; i&lt;numVertices;i++)
+00811 {
+00812 vbAllocator.deleteVertex(vegetRdrPass.Vertices[i]);
+00813 }
+00814 vegetRdrPass.Vertices.clear();
+00815 }
+00816
+00817 CVegetableClipBlock *clipBlock= ig-&gt;_ClipOwner;
+00818 CVegetableSortBlock *sortBlock= ig-&gt;_SortOwner;
+00819
+00820 <font class="comment">// If I have got some faces in ZSort rdrPass</font>
+00821 <font class="keywordflow">if</font>(ig-&gt;_HasZSortPassInstances)
+00822 <font class="comment">// after my deletion, the sortBlock must be updated.</font>
+00823 sortBlock-&gt;_Dirty= <font class="keyword">true</font>;
+00824
+00825
+00826 <font class="comment">// unlink from sortBlock, and delete.</font>
+00827 sortBlock-&gt;_InstanceGroupList.remove(ig);
+00828 <a class="code" href="classNL3D_1_1CVegetableManager.html#o2">_InstanceGroupMemory</a>.<a class="code" href="classNLMISC_1_1CBlockMemory.html#a4">free</a>(ig);
+00829
+00830
+00831 <font class="comment">// decRef the clipBlock</font>
+00832 clipBlock-&gt;_NumIgs--;
+00833 <font class="comment">// if the clipBlock is now empty, change list</font>
+00834 <font class="keywordflow">if</font>(clipBlock-&gt;_NumIgs==0)
+00835 {
+00836 <font class="comment">// remove from normal list</font>
+00837 <a class="code" href="classNL3D_1_1CVegetableManager.html#o3">_ClipBlockList</a>.remove(clipBlock);
+00838 <font class="comment">// and append to empty list.</font>
+00839 <a class="code" href="classNL3D_1_1CVegetableManager.html#o4">_EmptyClipBlockList</a>.append(clipBlock);
+00840 }
+00841
+00842 }
+00843
+00844
+00845 <font class="comment">// ***************************************************************************</font>
+<a name="l00846"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z881_0">00846</a> CVegetableShape *CVegetableManager::getVegetableShape(<font class="keyword">const</font> std::string &amp;shape)
+00847 {
+00848 <a class="code" href="classNL3D_1_1CVegetableManager.html#u1">ItShapeMap</a> it= <a class="code" href="classNL3D_1_1CVegetableManager.html#o5">_ShapeMap</a>.find(shape);
+00849 <font class="comment">// if found</font>
+00850 <font class="keywordflow">if</font>(it != <a class="code" href="classNL3D_1_1CVegetableManager.html#o5">_ShapeMap</a>.end())
+00851 <font class="keywordflow">return</font> &amp;it-&gt;second;
+00852 <font class="comment">// else insert</font>
+00853 {
+00854 <font class="comment">// insert.</font>
+00855 CVegetableShape *ret;
+00856 it= ( <a class="code" href="classNL3D_1_1CVegetableManager.html#o5">_ShapeMap</a>.insert(make_pair(shape, CVegetableShape()) ) ).first;
+00857 ret= &amp;it-&gt;second;
+00858
+00859 <font class="comment">// fill.</font>
+00860 <font class="keywordflow">try</font>
+00861 {
+00862 ret-&gt;loadShape(shape);
+00863 }
+00864 <font class="keywordflow">catch</font> (Exception &amp;e)
+00865 {
+00866 <font class="comment">// Warning</font>
+00867 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"CVegetableManager::getVegetableShape error while loading shape file '%s' : '%s'"</font>, shape.c_str (), e.what ());
+00868
+00869 <font class="comment">// Remove from map</font>
+00870 <a class="code" href="classNL3D_1_1CVegetableManager.html#o5">_ShapeMap</a>.erase (shape);
+00871
+00872 <font class="comment">// Return NULL</font>
+00873 ret = NULL;
+00874 }
+00875
+00876 <font class="keywordflow">return</font> ret;
+00877 }
+00878 }
+00879
+00880
+00881 <font class="comment">// ***************************************************************************</font>
+<a name="l00882"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#c0">00882</a> uint CVegetableManager::getRdrPassInfoForShape(CVegetableShape *shape, TVegetableWater vegetWaterState,
+00883 <font class="keywordtype">bool</font> &amp;instanceLighted, <font class="keywordtype">bool</font> &amp;instanceDoubleSided, <font class="keywordtype">bool</font> &amp;instanceZSort,
+00884 <font class="keywordtype">bool</font> &amp;destLighted, <font class="keywordtype">bool</font> &amp;precomputeLighting)
+00885 {
+00886 instanceLighted= shape-&gt;Lighted;
+00887 instanceDoubleSided= shape-&gt;DoubleSided;
+00888 <font class="comment">// Disable ZSorting when we intersect water.</font>
+00889 instanceZSort= shape-&gt;AlphaBlend &amp;&amp; vegetWaterState!=<a class="code" href="classNL3D_1_1CVegetableManager.html#s4s2">IntersectWater</a>;
+00890 destLighted= instanceLighted &amp;&amp; !shape-&gt;PreComputeLighting;
+00891 precomputeLighting= instanceLighted &amp;&amp; shape-&gt;PreComputeLighting;
+00892
+00893 <font class="comment">// get correct rdrPass</font>
+00894 uint rdrPass;
+00895 <font class="comment">// get according to lighted / doubleSided state</font>
+00896 <font class="keywordflow">if</font>(destLighted)
+00897 {
+00898 <font class="keywordflow">if</font>(instanceDoubleSided)
+00899 rdrPass= <a class="code" href="vegetable__def_8h.html#a2">NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED</a>;
+00900 <font class="keywordflow">else</font>
+00901 rdrPass= <a class="code" href="vegetable__def_8h.html#a1">NL3D_VEGETABLE_RDRPASS_LIGHTED</a>;
+00902 }
+00903 <font class="keywordflow">else</font>
+00904 {
+00905 <font class="keywordflow">if</font>(instanceDoubleSided)
+00906 {
+00907 <font class="keywordflow">if</font>(instanceZSort)
+00908 rdrPass= <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>;
+00909 <font class="keywordflow">else</font>
+00910 rdrPass= <a class="code" href="vegetable__def_8h.html#a4">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED</a>;
+00911 }
+00912 <font class="keywordflow">else</font>
+00913 rdrPass= <a class="code" href="vegetable__def_8h.html#a3">NL3D_VEGETABLE_RDRPASS_UNLIT</a>;
+00914 }
+00915
+00916 <font class="keywordflow">return</font> rdrPass;
+00917 }
+00918
+00919
+00920 <font class="comment">// ***************************************************************************</font>
+<a name="l00921"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z883_0">00921</a> <font class="keywordtype">void</font> CVegetableManager::reserveIgAddInstances(CVegetableInstanceGroupReserve &amp;vegetIgReserve, CVegetableShape *shape, TVegetableWater vegetWaterState, uint numInstances)
+00922 {
+00923 <font class="keywordtype">bool</font> instanceLighted;
+00924 <font class="keywordtype">bool</font> instanceDoubleSided;
+00925 <font class="keywordtype">bool</font> instanceZSort;
+00926 <font class="keywordtype">bool</font> destLighted;
+00927 <font class="keywordtype">bool</font> precomputeLighting;
+00928
+00929 <font class="comment">// get correct rdrPass / info</font>
+00930 uint rdrPass;
+00931 rdrPass= <a class="code" href="classNL3D_1_1CVegetableManager.html#c0">getRdrPassInfoForShape</a>(shape, vegetWaterState, instanceLighted, instanceDoubleSided,
+00932 instanceZSort, destLighted, precomputeLighting);
+00933
+00934 <font class="comment">// veget rdrPass</font>
+00935 CVegetableInstanceGroupReserve::CVegetableRdrPass &amp;vegetRdrPass= vegetIgReserve._RdrPass[rdrPass];
+00936
+00937 <font class="comment">// Reserve space in the rdrPass.</font>
+00938 vegetRdrPass.NVertices+= numInstances * shape-&gt;VB.getNumVertices();
+00939 vegetRdrPass.NTriangles+= numInstances * shape-&gt;TriangleIndices.size()/3;
+00940 <font class="comment">// if the instances are lighted, reserve space for lighting updates</font>
+00941 <font class="keywordflow">if</font>(instanceLighted)
+00942 vegetRdrPass.NLightedInstances+= numInstances;
+00943 }
+00944
+00945
+00946 <font class="comment">// ***************************************************************************</font>
+<a name="l00947"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z883_1">00947</a> <font class="keywordtype">void</font> CVegetableManager::reserveIgCompile(CVegetableInstanceGroup *ig, <font class="keyword">const</font> CVegetableInstanceGroupReserve &amp;vegetIgReserve)
+00948 {
+00949 uint rdrPass;
+00950
+00951
+00952 <font class="comment">// Check.</font>
+00953 <font class="comment">//===========</font>
+00954 <font class="comment">// For all rdrPass of the ig, check empty</font>
+00955 <font class="keywordflow">for</font>(rdrPass= 0; rdrPass&lt;<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; rdrPass++)
+00956 {
+00957 CVegetableInstanceGroup::CVegetableRdrPass &amp;vegetRdrPass= ig-&gt;_RdrPass[rdrPass];
+00958 <a class="code" href="debug_8h.html#a6">nlassert</a>(vegetRdrPass.TriangleIndices.size()==0);
+00959 <a class="code" href="debug_8h.html#a6">nlassert</a>(vegetRdrPass.TriangleLocalIndices.size()==0);
+00960 <a class="code" href="debug_8h.html#a6">nlassert</a>(vegetRdrPass.Vertices.size()==0);
+00961 <a class="code" href="debug_8h.html#a6">nlassert</a>(vegetRdrPass.LightedInstances.size()==0);
+00962 }
+00963 <font class="comment">// Do the same for all quadrants of the zsort rdrPass.</font>
+00964 <a class="code" href="debug_8h.html#a6">nlassert</a>(ig-&gt;_TriangleQuadrantOrderArray.size()==0);
+00965 <a class="code" href="debug_8h.html#a6">nlassert</a>(ig-&gt;_TriangleQuadrantOrderNumTriangles==0);
+00966
+00967
+00968 <font class="comment">// Reserve.</font>
+00969 <font class="comment">//===========</font>
+00970 <font class="comment">// For all rdrPass of the ig, reserve.</font>
+00971 <font class="keywordflow">for</font>(rdrPass= 0; rdrPass&lt;<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; rdrPass++)
+00972 {
+00973 CVegetableInstanceGroup::CVegetableRdrPass &amp;vegetRdrPass= ig-&gt;_RdrPass[rdrPass];
+00974 uint numVertices= vegetIgReserve._RdrPass[rdrPass].NVertices;
+00975 uint numTris= vegetIgReserve._RdrPass[rdrPass].NTriangles;
+00976 uint numLightedInstances= vegetIgReserve._RdrPass[rdrPass].NLightedInstances;
+00977 <font class="comment">// reserve triangles indices and vertices for this rdrPass.</font>
+00978 vegetRdrPass.TriangleIndices.resize(numTris*3);
+00979 vegetRdrPass.TriangleLocalIndices.resize(numTris*3);
+00980 vegetRdrPass.Vertices.resize(numVertices);
+00981 <font class="comment">// reserve ligthedinstances space.</font>
+00982 vegetRdrPass.LightedInstances.resize(numLightedInstances);
+00983 }
+00984
+00985 <font class="comment">// Reserve space for the zsort rdrPass sorting.</font>
+00986 uint numZSortTris= vegetIgReserve._RdrPass[<a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>].NTriangles;
+00987 <font class="comment">// allocate sufficient space for all quadrants (1 alloc for all quadrants).</font>
+00988 ig-&gt;_TriangleQuadrantOrderArray.resize(numZSortTris * <a class="code" href="vegetable__def_8h.html#a10">NL3D_VEGETABLE_NUM_QUADRANT</a>);
+00989
+00990 <font class="comment">// And init ptrs.</font>
+00991 <font class="keywordflow">if</font>(numZSortTris&gt;0)
+00992 {
+00993 <font class="keywordtype">float</font> *start= ig-&gt;_TriangleQuadrantOrderArray.getPtr();
+00994 <font class="comment">// init ptr to each qaudrant</font>
+00995 <font class="keywordflow">for</font>(uint i=0; i&lt;<a class="code" href="vegetable__def_8h.html#a10">NL3D_VEGETABLE_NUM_QUADRANT</a>; i++)
+00996 {
+00997 ig-&gt;_TriangleQuadrantOrders[i]= start + i*numZSortTris;
+00998 }
+00999 }
+01000 }
+01001
+01002
+01003 <font class="comment">// ***************************************************************************</font>
+01004 <font class="keyword">inline</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a473">computeVegetVertexLighting</a>(<font class="keyword">const</font> CVector &amp;rotNormal, <font class="keywordtype">bool</font> instanceDoubleSided,
+01005 <font class="keyword">const</font> CVector &amp;sunDir, CRGBA primaryRGBA, CRGBA secondaryRGBA,
+01006 CVegetableLightEx &amp;vegetLex, CRGBA diffusePL[2],
+01007 CRGBA *dstFront, CRGBA *dstBack)
+01008 {
+01009 <font class="keywordtype">float</font> dpSun;
+01010 <font class="keywordtype">float</font> dpPL[2];
+01011 CRGBA col;
+01012 CRGBA resColor;
+01013
+01014
+01015 <font class="comment">// compute front-facing coloring.</font>
+01016 {
+01017 <font class="comment">// Compute Sun Light.</font>
+01018 dpSun= rotNormal*sunDir;
+01019 <font class="keywordtype">float</font> f= max(0.f, -dpSun);
+01020 col.modulateFromuiRGBOnly(primaryRGBA, <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01021 <font class="comment">// Add it with ambient</font>
+01022 resColor.addRGBOnly(col, secondaryRGBA);
+01023
+01024 <font class="comment">// Add influence of 2 lights only. (unrolled for better BTB use)</font>
+01025 <font class="comment">// Compute Light 0 ?</font>
+01026 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=1)
+01027 {
+01028 dpPL[0]= rotNormal*vegetLex.Direction[0];
+01029 f= max(0.f, -dpPL[0]);
+01030 col.modulateFromuiRGBOnly(diffusePL[0], <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01031 resColor.addRGBOnly(col, resColor);
+01032 <font class="comment">// Compute Light 1 ?</font>
+01033 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=2)
+01034 {
+01035 dpPL[1]= rotNormal*vegetLex.Direction[1];
+01036 f= max(0.f, -dpPL[1]);
+01037 col.modulateFromuiRGBOnly(diffusePL[1], <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01038 resColor.addRGBOnly(col, resColor);
+01039 }
+01040 }
+01041
+01042 <font class="comment">// Keep correct U of Dynamic Lightmap UV encoded in primaryRGBA Alpha part.</font>
+01043 resColor.A= primaryRGBA.A;
+01044
+01045 <font class="comment">// copy to dest</font>
+01046 *dstFront= resColor;
+01047 }
+01048
+01049 <font class="comment">// If 2Sided</font>
+01050 <font class="keywordflow">if</font>(instanceDoubleSided)
+01051 {
+01052 <font class="comment">// reuse dotproduct of front-facing computing.</font>
+01053
+01054 <font class="comment">// Compute Sun Light.</font>
+01055 <font class="keywordtype">float</font> f= max(0.f, dpSun);
+01056 col.modulateFromuiRGBOnly(primaryRGBA, <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01057 <font class="comment">// Add it with ambient</font>
+01058 resColor.addRGBOnly(col, secondaryRGBA);
+01059
+01060 <font class="comment">// Add influence of 2 lights only. (unrolled for better BTB use)</font>
+01061 <font class="comment">// Compute Light 0 ?</font>
+01062 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=1)
+01063 {
+01064 f= max(0.f, dpPL[0]);
+01065 col.modulateFromuiRGBOnly(diffusePL[0], <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01066 resColor.addRGBOnly(col, resColor);
+01067 <font class="comment">// Compute Light 1 ?</font>
+01068 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=2)
+01069 {
+01070 f= max(0.f, dpPL[1]);
+01071 col.modulateFromuiRGBOnly(diffusePL[1], <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01072 resColor.addRGBOnly(col, resColor);
+01073 }
+01074 }
+01075
+01076 <font class="comment">// Keep correct V of Dynamic Lightmap UV encoded in secondaryRGBA Alpha part.</font>
+01077 resColor.A= secondaryRGBA.A;
+01078
+01079 <font class="comment">// copy to dest</font>
+01080 *dstBack= resColor;
+01081 }
+01082 }
+01083
+01084
+01085 <font class="comment">// ***************************************************************************</font>
+01086 <font class="keyword">inline</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a474">computeVegetVertexLightingForceBestSided</a>(<font class="keyword">const</font> CVector &amp;rotNormal, <font class="keywordtype">bool</font> instanceDoubleSided,
+01087 <font class="keyword">const</font> CVector &amp;sunDir, CRGBA primaryRGBA, CRGBA secondaryRGBA,
+01088 CVegetableLightEx &amp;vegetLex, CRGBA diffusePL[2],
+01089 CRGBA *dstFront, CRGBA *dstBack)
+01090 {
+01091 <font class="keywordtype">float</font> dpSun;
+01092 <font class="keywordtype">float</font> dpPL[2];
+01093 CRGBA col;
+01094 CRGBA resColor;
+01095
+01096
+01097 <font class="comment">// compute front-facing coloring.</font>
+01098 {
+01099 <font class="comment">// Compute Sun Light.</font>
+01100 dpSun= rotNormal*sunDir;
+01101 <font class="comment">// ForceBestSided: take the absolute value (max of -val,val)</font>
+01102 <font class="keywordtype">float</font> f= (float)fabs(dpSun);
+01103 col.modulateFromuiRGBOnly(primaryRGBA, <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01104 <font class="comment">// Add it with ambient</font>
+01105 resColor.addRGBOnly(col, secondaryRGBA);
+01106
+01107 <font class="comment">// Add influence of 2 lights only. (unrolled for better BTB use)</font>
+01108 <font class="comment">// Compute Light 0 ?</font>
+01109 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=1)
+01110 {
+01111 dpPL[0]= rotNormal*vegetLex.Direction[0];
+01112 <font class="comment">// ForceBestSided: take the absolute value (max of -val,val)</font>
+01113 f= (float)fabs(dpPL[0]);
+01114 col.modulateFromuiRGBOnly(diffusePL[0], <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01115 resColor.addRGBOnly(col, resColor);
+01116 <font class="comment">// Compute Light 1 ?</font>
+01117 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=2)
+01118 {
+01119 dpPL[1]= rotNormal*vegetLex.Direction[1];
+01120 f= (float)fabs(dpPL[1]);
+01121 col.modulateFromuiRGBOnly(diffusePL[1], <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(f*256));
+01122 resColor.addRGBOnly(col, resColor);
+01123 }
+01124 }
+01125
+01126 <font class="comment">// Keep correct U of Dynamic Lightmap UV encoded in primaryRGBA Alpha part.</font>
+01127 resColor.A= primaryRGBA.A;
+01128
+01129 <font class="comment">// copy to dest</font>
+01130 *dstFront= resColor;
+01131 }
+01132
+01133 <font class="comment">// If 2Sided</font>
+01134 <font class="keywordflow">if</font>(instanceDoubleSided)
+01135 {
+01136 <font class="comment">// Since forceBestSided, same color as front_facing</font>
+01137
+01138 <font class="comment">// Keep correct V of Dynamic Lightmap UV encoded in secondaryRGBA Alpha part.</font>
+01139 resColor.A= secondaryRGBA.A;
+01140
+01141 <font class="comment">// copy to dest</font>
+01142 *dstBack= resColor;
+01143 }
+01144 }
+01145
+01146
+01147 <font class="comment">// ***************************************************************************</font>
+<a name="l01148"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z883_2">01148</a> <font class="keywordtype">void</font> CVegetableManager::addInstance(CVegetableInstanceGroup *ig,
+01149 CVegetableShape *shape, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> &amp;mat,
+01150 <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CRGBAF.html">NLMISC::CRGBAF</a> &amp;ambientColor, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CRGBAF.html">NLMISC::CRGBAF</a> &amp;diffuseColor,
+01151 <font class="keywordtype">float</font> bendFactor, <font class="keywordtype">float</font> bendPhase, <font class="keywordtype">float</font> bendFreqFactor, <font class="keywordtype">float</font> blendDistMax,
+01152 TVegetableWater vegetWaterState, CVegetableUV8 dlmUV)
+01153 {
+01154 sint i;
+01155
+01156
+01157 <font class="comment">// Some setup.</font>
+01158 <font class="comment">//--------------------</font>
+01159 <font class="keywordtype">bool</font> instanceLighted;
+01160 <font class="keywordtype">bool</font> instanceDoubleSided;
+01161 <font class="keywordtype">bool</font> instanceZSort;
+01162 <font class="keywordtype">bool</font> destLighted;
+01163 <font class="keywordtype">bool</font> precomputeLighting;
+01164
+01165 <font class="comment">// get correct rdrPass / info</font>
+01166 uint rdrPass;
+01167 rdrPass= <a class="code" href="classNL3D_1_1CVegetableManager.html#c0">getRdrPassInfoForShape</a>(shape, vegetWaterState, instanceLighted, instanceDoubleSided,
+01168 instanceZSort, destLighted, precomputeLighting);
+01169 <font class="comment">// bestSided Precompute lighting or not??</font>
+01170 <font class="keywordtype">bool</font> bestSidedPrecomputeLighting= precomputeLighting &amp;&amp; shape-&gt;BestSidedPreComputeLighting;
+01171
+01172
+01173 <font class="comment">// veget rdrPass</font>
+01174 CVegetableInstanceGroup::CVegetableRdrPass &amp;vegetRdrPass= ig-&gt;_RdrPass[rdrPass];
+01175
+01176 <font class="comment">// color.</font>
+01177 <font class="comment">// setup using OptFastFloor.</font>
+01178 CRGBA ambientRGBA, diffuseRGBA;
+01179 CRGBA primaryRGBA, secondaryRGBA;
+01180 <font class="comment">// diffuseColor</font>
+01181 diffuseRGBA.R= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(diffuseColor.<a class="code" href="classNLMISC_1_1CRGBAF.html#m0">R</a>*255);
+01182 diffuseRGBA.G= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(diffuseColor.<a class="code" href="classNLMISC_1_1CRGBAF.html#m1">G</a>*255);
+01183 diffuseRGBA.B= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(diffuseColor.<a class="code" href="classNLMISC_1_1CRGBAF.html#m2">B</a>*255);
+01184 diffuseRGBA.A= 255;
+01185 <font class="comment">// ambientColor</font>
+01186 ambientRGBA.R= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(ambientColor.<a class="code" href="classNLMISC_1_1CRGBAF.html#m0">R</a>*255);
+01187 ambientRGBA.G= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(ambientColor.<a class="code" href="classNLMISC_1_1CRGBAF.html#m1">G</a>*255);
+01188 ambientRGBA.B= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(ambientColor.<a class="code" href="classNLMISC_1_1CRGBAF.html#m2">B</a>*255);
+01189 ambientRGBA.A= 255;
+01190
+01191 <font class="comment">// For Unlit and Lighted, modulate with global light.</font>
+01192 primaryRGBA.modulateFromColorRGBOnly(diffuseRGBA, <a class="code" href="classNL3D_1_1CVegetableManager.html#o12">_GlobalDiffuse</a>);
+01193 secondaryRGBA.modulateFromColorRGBOnly(ambientRGBA, <a class="code" href="classNL3D_1_1CVegetableManager.html#o11">_GlobalAmbient</a>);
+01194
+01195 <font class="comment">// if the instance is not lighted, then suppose full lighting =&gt; add ambient and diffuse</font>
+01196 <font class="keywordflow">if</font>(!instanceLighted)
+01197 {
+01198 primaryRGBA.R= <a class="code" href="bit__set_8cpp.html#a0">min</a>(255, primaryRGBA.R + secondaryRGBA.R);
+01199 primaryRGBA.G= <a class="code" href="bit__set_8cpp.html#a0">min</a>(255, primaryRGBA.G + secondaryRGBA.G);
+01200 primaryRGBA.B= <a class="code" href="bit__set_8cpp.html#a0">min</a>(255, primaryRGBA.B + secondaryRGBA.B);
+01201 <font class="comment">// useFull if 2Sided</font>
+01202 secondaryRGBA= primaryRGBA;
+01203 }
+01204
+01205 <font class="comment">// Copy Dynamic Lightmap UV in Alpha part (save memory for an extra cost of 1 VP instruction)</font>
+01206 primaryRGBA.A= dlmUV.U;
+01207 secondaryRGBA.A= dlmUV.V;
+01208
+01209 <font class="comment">// get ref on the vegetLex.</font>
+01210 CVegetableLightEx &amp;vegetLex= ig-&gt;VegetableLightEx;
+01211 <font class="comment">// Color of pointLights modulated by diffuse.</font>
+01212 CRGBA diffusePL[2];
+01213 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=1)
+01214 {
+01215 diffusePL[0].modulateFromColorRGBOnly(diffuseRGBA, vegetLex.Color[0]);
+01216 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=2)
+01217 {
+01218 diffusePL[1].modulateFromColorRGBOnly(diffuseRGBA, vegetLex.Color[1]);
+01219 }
+01220 }
+01221
+01222 <font class="comment">// normalize bendFreqFactor</font>
+01223 bendFreqFactor*= <a class="code" href="vegetable__def_8h.html#a11">NL3D_VEGETABLE_FREQUENCY_FACTOR_PREC</a>;
+01224 bendFreqFactor= (float)floor(bendFreqFactor + 0.5f);
+01225 bendFreqFactor/= <a class="code" href="vegetable__def_8h.html#a11">NL3D_VEGETABLE_FREQUENCY_FACTOR_PREC</a>;
+01226
+01227
+01228 <font class="comment">// Get allocator, and manage VBhard overriding.</font>
+01229 <font class="comment">//--------------------</font>
+01230 CVegetableVBAllocator *allocator;
+01231 <font class="comment">// if still in Sfot mode, keep it.</font>
+01232 <font class="keywordflow">if</font>(!vegetRdrPass.HardMode)
+01233 {
+01234 <font class="comment">// get the soft allocator.</font>
+01235 allocator= &amp;<a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPass, 0);
+01236 }
+01237 <font class="keywordflow">else</font>
+01238 {
+01239 <font class="comment">// Get VB allocator Hard for this rdrPass</font>
+01240 allocator= &amp;<a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPass, 1);
+01241 <font class="comment">// Test if the instance don't add too many vertices for this VBHard</font>
+01242 <font class="keywordflow">if</font>(allocator-&gt;exceedMaxVertexInBufferHard(shape-&gt;VB.getNumVertices()))
+01243 {
+01244 <font class="comment">// if exceed, then must pass ALL the IG in software mode. vertices/faces are correclty updated.</font>
+01245 <font class="comment">// special: if rdrPass is the ZSort one, </font>
+01246 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>)
+01247 {
+01248 <a class="code" href="debug_8h.html#a6">nlassert</a>(ig-&gt;_SortOwner-&gt;ZSortHardMode);
+01249
+01250 <font class="comment">// must do it on ALL igs of the sortBlock, for less VBuffer mode switching.</font>
+01251 CVegetableInstanceGroup *pIg= ig-&gt;_SortOwner-&gt;_InstanceGroupList.begin();
+01252 <font class="keywordflow">while</font>(pIg)
+01253 {
+01254 <font class="comment">// let's pass them in software mode.</font>
+01255 <a class="code" href="classNL3D_1_1CVegetableManager.html#c4">swapIgRdrPassHardMode</a>(pIg, rdrPass);
+01256 <font class="comment">// next</font>
+01257 pIg= (CVegetableInstanceGroup*)pIg-&gt;Next;
+01258 }
+01259
+01260 <font class="comment">// Then all The sortBlock is in SoftMode.</font>
+01261 ig-&gt;_SortOwner-&gt;ZSortHardMode= <font class="keyword">false</font>;
+01262 }
+01263 <font class="keywordflow">else</font>
+01264 {
+01265 <font class="comment">// just do it on this Ig (can mix hardMode in a SortBlock for normal rdrPass)</font>
+01266 <a class="code" href="classNL3D_1_1CVegetableManager.html#c4">swapIgRdrPassHardMode</a>(ig, rdrPass);
+01267 }
+01268
+01269 <font class="comment">// now, we can use the software only Allocator to append our instance</font>
+01270 allocator= &amp;<a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPass, 0);
+01271 }
+01272 }
+01273
+01274
+01275 <font class="comment">// get correct dstVB</font>
+01276 <font class="keyword">const</font> CVertexBuffer &amp;dstVBInfo= allocator-&gt;getSoftwareVertexBuffer();
+01277
+01278
+01279 <font class="comment">// Transform vertices to a vegetable instance, and enlarge clipBlock</font>
+01280 <font class="comment">//--------------------</font>
+01281 <font class="comment">// compute matrix to multiply normals, ie (M-1)t</font>
+01282 CMatrix normalMat;
+01283 <font class="comment">// need just rotation scale matrix.</font>
+01284 normalMat.setRot(mat);
+01285 normalMat.invert();
+01286 normalMat.transpose();
+01287 <font class="comment">// compute Instance position</font>
+01288 CVector instancePos;
+01289 mat.<a class="code" href="classNLMISC_1_1CMatrix.html#z291_4">getPos</a>(instancePos);
+01290
+01291
+01292 <font class="comment">// At least, the bbox of the clipBlock must include the center of the shape.</font>
+01293 ig-&gt;_ClipOwner-&gt;extendSphere(instancePos);
+01294
+01295
+01296 <font class="comment">// Vertex/triangle Info.</font>
+01297 uint numNewVertices= shape-&gt;VB.getNumVertices();
+01298 uint numNewTris= shape-&gt;TriangleIndices.size()/3;
+01299 uint numNewIndices= shape-&gt;TriangleIndices.size();
+01300
+01301 <font class="comment">// src info.</font>
+01302 uint srcNormalOff= (instanceLighted? shape-&gt;VB.getNormalOff() : 0);
+01303 uint srcTex0Off= shape-&gt;VB.getTexCoordOff(0);
+01304 uint srcTex1Off= shape-&gt;VB.getTexCoordOff(1);
+01305
+01306 <font class="comment">// dst info</font>
+01307 uint dstNormalOff= (destLighted? dstVBInfo.getValueOffEx(<a class="code" href="vegetablevb__allocator_8h.html#a1">NL3D_VEGETABLE_VPPOS_NORMAL</a>) : 0);
+01308 <font class="comment">// got 2nd color if really lighted (for ambient) or if 2Sided.</font>
+01309 uint dstColor1Off= ( (destLighted||instanceDoubleSided)?
+01310 dstVBInfo.getValueOffEx(<a class="code" href="vegetablevb__allocator_8h.html#a3">NL3D_VEGETABLE_VPPOS_COLOR1</a>) : 0);
+01311 uint dstColor0Off= dstVBInfo.getValueOffEx(<a class="code" href="vegetablevb__allocator_8h.html#a2">NL3D_VEGETABLE_VPPOS_COLOR0</a>);
+01312 uint dstTex0Off= dstVBInfo.getValueOffEx(<a class="code" href="vegetablevb__allocator_8h.html#a4">NL3D_VEGETABLE_VPPOS_TEX0</a>);
+01313 uint dstBendOff= dstVBInfo.getValueOffEx(<a class="code" href="vegetablevb__allocator_8h.html#a5">NL3D_VEGETABLE_VPPOS_BENDINFO</a>);
+01314 uint dstCenterOff= dstVBInfo.getValueOffEx(<a class="code" href="vegetablevb__allocator_8h.html#a6">NL3D_VEGETABLE_VPPOS_CENTER</a>);
+01315
+01316
+01317 <font class="comment">// Usefull For !destLighted only.</font>
+01318 CVector deltaPos;
+01319 <font class="keywordtype">float</font> deltaPosNorm=0.0;
+01320
+01321
+01322 <font class="comment">// UseFull for ZSORT rdrPass, the worldVertices.</font>
+01323 <font class="keyword">static</font> vector&lt;CVector&gt; worldVertices;
+01324 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>)
+01325 {
+01326 worldVertices.resize(numNewVertices);
+01327 }
+01328
+01329
+01330 <font class="comment">// For all vertices of shape, transform and store manager indices in temp shape.</font>
+01331 <font class="keywordflow">for</font>(i=0; i&lt;(sint)numNewVertices;i++)
+01332 {
+01333 <font class="comment">// allocate a Vertex</font>
+01334 uint vid= allocator-&gt;allocateVertex();
+01335 <font class="comment">// store in tmp shape.</font>
+01336 shape-&gt;InstanceVertices[i]= vid;
+01337
+01338 <font class="comment">// Fill this vertex.</font>
+01339 uint8 *srcPtr= (uint8*)shape-&gt;VB.getVertexCoordPointer(i);
+01340 uint8 *dstPtr= (uint8*)allocator-&gt;getVertexPointer(vid);
+01341
+01342 <font class="comment">// Get bendWeight for this vertex.</font>
+01343 <font class="keywordtype">float</font> vertexBendWeight= ((CUV*)(srcPtr + srcTex1Off))-&gt;U * bendFactor;
+01344
+01345 <font class="comment">// Pos.</font>
+01346 <font class="comment">//-------</font>
+01347 <font class="comment">// Separate Center and relative pos.</font>
+01348 CVector relPos= mat.<a class="code" href="classNLMISC_1_1CMatrix.html#z294_0">mulVector</a>(*(CVector*)srcPtr); <font class="comment">// mulVector, because translation in v[center]</font>
+01349 <font class="comment">// compute bendCenterPos</font>
+01350 CVector bendCenterPos;
+01351 <font class="keywordflow">if</font>(shape-&gt;BendCenterMode == CVegetableShapeBuild::BendCenterNull)
+01352 bendCenterPos= CVector::Null;
+01353 <font class="keywordflow">else</font>
+01354 {
+01355 CVector <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>= *(CVector*)srcPtr;
+01356 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.z= 0;
+01357 bendCenterPos= mat.<a class="code" href="classNLMISC_1_1CMatrix.html#z294_0">mulVector</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>); <font class="comment">// mulVector, because translation in v[center]</font>
+01358 }
+01359 <font class="comment">// copy</font>
+01360 deltaPos= relPos-bendCenterPos;
+01361 *(CVector*)dstPtr= deltaPos;
+01362 *(CVector*)(dstPtr + dstCenterOff)= instancePos + bendCenterPos;
+01363 <font class="comment">// if !destLighted, then VP is different</font>
+01364 <font class="keywordflow">if</font>(!destLighted)
+01365 {
+01366 deltaPosNorm= deltaPos.norm();
+01367 <font class="comment">// copy bendWeight in v.w</font>
+01368 CVectorH *vh= (CVectorH*)dstPtr;
+01369 <font class="comment">// Mul by deltaPosNorm, to draw an arc circle.</font>
+01370 vh-&gt;w= vertexBendWeight * deltaPosNorm;
+01371 }
+01372
+01373 <font class="comment">// Enlarge the clipBlock of the IG.</font>
+01374 <font class="comment">// Since small shape, enlarge with each vertices. simpler and maybe faster.</font>
+01375 <font class="comment">// TODO_VEGET: bend and clipping ...</font>
+01376 ig-&gt;_ClipOwner-&gt;extendBBoxOnly(instancePos + relPos);
+01377
+01378 <font class="comment">// prepare for ZSort</font>
+01379 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>)
+01380 {
+01381 worldVertices[i]= instancePos + relPos;
+01382 }
+01383
+01384
+01385 <font class="comment">// Color-ligthing.</font>
+01386 <font class="comment">//-------</font>
+01387 <font class="keywordflow">if</font>(!precomputeLighting)
+01388 {
+01389 <font class="comment">// just copy the primary color (means diffuse part if lighted)</font>
+01390 *(CRGBA*)(dstPtr + dstColor0Off)= primaryRGBA;
+01391 <font class="comment">// normal and secondary color</font>
+01392 <font class="keywordflow">if</font>(destLighted)
+01393 {
+01394 <font class="comment">// normal</font>
+01395 *(CVector*)(dstPtr + dstNormalOff)= normalMat.mulVector( *(CVector*)(srcPtr + srcNormalOff) );
+01396 }
+01397 <font class="comment">// If destLighted, secondaryRGBA is the ambient</font>
+01398 <font class="comment">// else if(instanceDoubleSided), secondaryRGBA is backface color.</font>
+01399 <font class="comment">// else, still important to copy secondaryRGBA, because alpha part contains Dynamic LightMap V.</font>
+01400 *(CRGBA*)(dstPtr + dstColor1Off)= secondaryRGBA;
+01401 }
+01402 <font class="keywordflow">else</font>
+01403 {
+01404 <a class="code" href="debug_8h.html#a6">nlassert</a>(!destLighted);
+01405
+01406 <font class="comment">// compute normal.</font>
+01407 CVector rotNormal= normalMat.mulVector( *(CVector*)(srcPtr + srcNormalOff) );
+01408 <font class="comment">// must normalize() because scale is possible.</font>
+01409 rotNormal.normalize();
+01410
+01411 <font class="comment">// Do the compute.</font>
+01412 <font class="keywordflow">if</font>(!bestSidedPrecomputeLighting)
+01413 {
+01414 <a class="code" href="namespaceNL3D.html#a473">computeVegetVertexLighting</a>(rotNormal, instanceDoubleSided,
+01415 <a class="code" href="classNL3D_1_1CVegetableManager.html#o10">_DirectionalLight</a>, primaryRGBA, secondaryRGBA,
+01416 vegetLex, diffusePL,
+01417 (CRGBA*)(dstPtr + dstColor0Off), (CRGBA*)(dstPtr + dstColor1Off) );
+01418 }
+01419 <font class="keywordflow">else</font>
+01420 {
+01421 <a class="code" href="namespaceNL3D.html#a474">computeVegetVertexLightingForceBestSided</a>(rotNormal, instanceDoubleSided,
+01422 <a class="code" href="classNL3D_1_1CVegetableManager.html#o10">_DirectionalLight</a>, primaryRGBA, secondaryRGBA,
+01423 vegetLex, diffusePL,
+01424 (CRGBA*)(dstPtr + dstColor0Off), (CRGBA*)(dstPtr + dstColor1Off) );
+01425 }
+01426
+01427 }
+01428
+01429
+01430 <font class="comment">// Texture.</font>
+01431 <font class="comment">//-------</font>
+01432 *(CUV*)(dstPtr + dstTex0Off)= *(CUV*)(srcPtr + srcTex0Off);
+01433
+01434 <font class="comment">// Bend.</font>
+01435 <font class="comment">//-------</font>
+01436 CVector *dstBendPtr= (CVector*)(dstPtr + dstBendOff);
+01437 <font class="comment">// setup bend Phase.</font>
+01438 dstBendPtr-&gt;y= bendPhase;
+01439 <font class="comment">// setup bend Weight.</font>
+01440 <font class="comment">// if !destLighted, then VP is different, vertexBendWeight is stored in v[0].w</font>
+01441 <font class="keywordflow">if</font>(destLighted)
+01442 dstBendPtr-&gt;x= vertexBendWeight;
+01443 <font class="keywordflow">else</font>
+01444 <font class="comment">// the VP need the norm of relPos in v[9].x</font>
+01445 dstBendPtr-&gt;x= deltaPosNorm;
+01446 <font class="comment">// setup bendFreqFactor</font>
+01447 dstBendPtr-&gt;z= bendFreqFactor;
+01449 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>)
+01450 {
+01451 <font class="comment">// get ptr on v[9].w NB: in Unlit mode, it has 4 components.</font>
+01452 CVectorH *dstBendPtr= (CVectorH*)(dstPtr + dstBendOff);
+01453 <font class="comment">// setup the constant of linear formula:</font>
+01454 <font class="comment">// Alpha= -1/blendTransDist * dist + blendDistMax/blendTransDist</font>
+01455 dstBendPtr-&gt;w= blendDistMax/<a class="code" href="vegetable__def_8h.html#a9">NL3D_VEGETABLE_BLOCK_BLEND_TRANSITION_DIST</a>;
+01456 }
+01457
+01458
+01459 <font class="comment">// fill the vertex in AGP.</font>
+01460 <font class="comment">//-------</font>
+01461 allocator-&gt;flushVertex(vid);
+01462 }
+01463
+01464
+01465 <font class="comment">// must recompute the sphere according to the bbox.</font>
+01466 ig-&gt;_ClipOwner-&gt;updateSphere();
+01467
+01468
+01469 <font class="comment">// If ZSort, compute Triangle Centers and Orders for quadrant</font>
+01470 <font class="comment">//--------------------</font>
+01471 <font class="keywordflow">if</font>(rdrPass==<a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>)
+01472 {
+01473 <font class="comment">// inform the SB that it must be updated.</font>
+01474 ig-&gt;_SortOwner-&gt;_Dirty= <font class="keyword">true</font>;
+01475 <font class="comment">// For deletion, inform the ig that it has instances which impact the SB.</font>
+01476 ig-&gt;_HasZSortPassInstances= <font class="keyword">true</font>;
+01477
+01478 <font class="comment">// change UnderWater falg of the SB</font>
+01479 <font class="keywordflow">if</font>(vegetWaterState == <a class="code" href="classNL3D_1_1CVegetableManager.html#s4s0">AboveWater</a>)
+01480 ig-&gt;_SortOwner-&gt;_UnderWater= <font class="keyword">false</font>;
+01481 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(vegetWaterState == <a class="code" href="classNL3D_1_1CVegetableManager.html#s4s1">UnderWater</a>)
+01482 ig-&gt;_SortOwner-&gt;_UnderWater= <font class="keyword">true</font>;
+01483
+01484 <font class="comment">// static to avoid reallocation</font>
+01485 <font class="keyword">static</font> vector&lt;CVector&gt; triangleCenters;
+01486 triangleCenters.resize(numNewTris);
+01487
+01488 <font class="comment">// compute triangle centers</font>
+01489 <font class="keywordflow">for</font>(uint i=0; i&lt;numNewTris; i++)
+01490 {
+01491 <font class="comment">// get index in shape.</font>
+01492 uint v0= shape-&gt;TriangleIndices[i*3+0];
+01493 uint v1= shape-&gt;TriangleIndices[i*3+1];
+01494 uint v2= shape-&gt;TriangleIndices[i*3+2];
+01495
+01496 <font class="comment">// get world coord.</font>
+01497 <font class="keyword">const</font> CVector &amp;vert0= worldVertices[v0];
+01498 <font class="keyword">const</font> CVector &amp;vert1= worldVertices[v1];
+01499 <font class="keyword">const</font> CVector &amp;vert2= worldVertices[v2];
+01500
+01501 <font class="comment">// compute center</font>
+01502 triangleCenters[i]= (vert0 + vert1 + vert2) / 3;
+01503 <font class="comment">// relative to center of the sortBlock (for more precision, especially for radixSort)</font>
+01504 triangleCenters[i]-= ig-&gt;_SortOwner-&gt;_Center;
+01505 }
+01506
+01507
+01508 <font class="comment">// resize the array. Actually only modify the number of triangles really setuped.</font>
+01509 uint offTri= ig-&gt;_TriangleQuadrantOrderNumTriangles;
+01510 ig-&gt;_TriangleQuadrantOrderNumTriangles+= numNewTris;
+01511 <font class="comment">// verify user has correclty used reserveIg system.</font>
+01512 <a class="code" href="debug_8h.html#a6">nlassert</a>(ig-&gt;_TriangleQuadrantOrderNumTriangles * NL3D_VEGETABLE_NUM_QUADRANT &lt;= ig-&gt;_TriangleQuadrantOrderArray.size());
+01513
+01514
+01515 <font class="comment">// compute distance for each quadrant.</font>
+01516 <font class="keywordflow">for</font>(uint quadId=0; quadId&lt;<a class="code" href="vegetable__def_8h.html#a10">NL3D_VEGETABLE_NUM_QUADRANT</a>; quadId++)
+01517 {
+01518 <font class="keyword">const</font> CVector &amp;quadDir= CVegetableQuadrant::Dirs[quadId];
+01519
+01520 <font class="comment">// For all tris.</font>
+01521 <font class="keywordflow">for</font>(uint i=0; i&lt;numNewTris; i++)
+01522 {
+01523 <font class="comment">// compute the distance with orientation of the quadrant. (DotProduct)</font>
+01524 ig-&gt;_TriangleQuadrantOrders[quadId][offTri + i]= triangleCenters[i] * quadDir;
+01525 }
+01526 }
+01527 }
+01528
+01529
+01530 <font class="comment">// Append list of indices and list of triangles to the IG</font>
+01531 <font class="comment">//--------------------</font>
+01532
+01533 <font class="comment">// TODO_VEGET_OPTIM: system reallocation of array is very bad...</font>
+01534
+01535
+01536 <font class="comment">// compute dest start idx.</font>
+01537 uint offVertex= vegetRdrPass.NVertices;
+01538 uint offTri= vegetRdrPass.NTriangles;
+01539 uint offTriIdx= offTri*3;
+01540
+01541 <font class="comment">// verify user has correclty used reserveIg system.</font>
+01542 <a class="code" href="debug_8h.html#a6">nlassert</a>(offVertex + numNewVertices &lt;= vegetRdrPass.Vertices.size());
+01543 <a class="code" href="debug_8h.html#a6">nlassert</a>(offTriIdx + numNewIndices &lt;= vegetRdrPass.TriangleIndices.size());
+01544 <a class="code" href="debug_8h.html#a6">nlassert</a>(offTriIdx + numNewIndices &lt;= vegetRdrPass.TriangleLocalIndices.size());
+01545
+01546
+01547 <font class="comment">// insert list of vertices to delete in ig vertices.</font>
+01548 vegetRdrPass.Vertices.copy(offVertex, offVertex+numNewVertices, &amp;shape-&gt;InstanceVertices[0]);
+01549
+01550 <font class="comment">// insert array of triangles in ig.</font>
+01551 <font class="comment">// for all indices, fill IG</font>
+01552 <font class="keywordflow">for</font>(i=0; i&lt;(sint)numNewIndices; i++)
+01553 {
+01554 <font class="comment">// get the index of the vertex in the shape</font>
+01555 uint vid= shape-&gt;TriangleIndices[i];
+01556 <font class="comment">// re-direction, using InstanceVertices;</font>
+01557 vegetRdrPass.TriangleIndices[offTriIdx + i]= shape-&gt;InstanceVertices[vid];
+01558 <font class="comment">// local re-direction: adding vertexOffset.</font>
+01559 vegetRdrPass.TriangleLocalIndices[offTriIdx + i]= offVertex + vid;
+01560 }
+01561
+01562 <font class="comment">// new triangle and vertex size.</font>
+01563 vegetRdrPass.NTriangles+= numNewTris;
+01564 vegetRdrPass.NVertices+= numNewVertices;
+01565
+01566
+01567 <font class="comment">// if lighted, must add a lightedInstance for lighting update.</font>
+01568 <font class="comment">//--------------------</font>
+01569 <font class="keywordflow">if</font>(instanceLighted)
+01570 {
+01571 <font class="comment">// first, update Ig.</font>
+01572 ig-&gt;_ULNumVertices+= numNewVertices;
+01573 <font class="comment">// and update the vegetable manager.</font>
+01574 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_8">_ULNTotalVertices</a>+= numNewVertices;
+01575 <font class="comment">// link at the end of the circular list: link before the current root.</font>
+01576 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>==NULL)
+01577 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>= ig;
+01578 <font class="keywordflow">else</font>
+01579 ig-&gt;linkBeforeUL(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>);
+01580
+01581 <font class="comment">// check good use of reserveIg.</font>
+01582 <a class="code" href="debug_8h.html#a6">nlassert</a>(vegetRdrPass.NLightedInstances &lt; vegetRdrPass.LightedInstances.size());
+01583
+01584 <font class="comment">// Fill instance info</font>
+01585 CVegetableInstanceGroup::CVegetableLightedInstance &amp;vli=
+01586 vegetRdrPass.LightedInstances[vegetRdrPass.NLightedInstances];
+01587 vli.Shape= shape;
+01588 vli.NormalMat= normalMat;
+01589 <font class="comment">// copy colors unmodulated by global light.</font>
+01590 vli.MatAmbient= ambientRGBA;
+01591 vli.MatDiffuse= diffuseRGBA;
+01592 <font class="comment">// store dynamic lightmap UV</font>
+01593 vli.DlmUV= dlmUV;
+01594 <font class="comment">// where vertices of this instances are wrote in the VegetRdrPass</font>
+01595 vli.StartIdInRdrPass= offVertex;
+01596
+01597 <font class="comment">// Inc size setuped.</font>
+01598 vegetRdrPass.NLightedInstances++;
+01599 }
+01600
+01601 }
+01602
+01603
+01604 <font class="comment">// ***************************************************************************</font>
+<a name="l01605"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#c4">01605</a> <font class="keywordtype">void</font> CVegetableManager::swapIgRdrPassHardMode(CVegetableInstanceGroup *ig, uint rdrPass)
+01606 {
+01607 CVegetableInstanceGroup::CVegetableRdrPass &amp;vegetRdrPass= ig-&gt;_RdrPass[rdrPass];
+01608
+01609 <font class="comment">// the allocator where vertices come from</font>
+01610 CVegetableVBAllocator &amp;srcAllocator= <a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPass, vegetRdrPass.HardMode);
+01611 <font class="comment">// the allocator where vertices will go</font>
+01612 CVegetableVBAllocator &amp;dstAllocator= <a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPass, !vegetRdrPass.HardMode);
+01613
+01614 <font class="comment">// vertex size</font>
+01615 uint vbSize= srcAllocator.getSoftwareVertexBuffer().getVertexSize();
+01616 <a class="code" href="debug_8h.html#a6">nlassert</a>(vbSize == dstAllocator.getSoftwareVertexBuffer().getVertexSize());
+01617
+01618 <font class="comment">// for all vertices of the IG, change of VBAllocator</font>
+01619 uint i;
+01620 <font class="comment">// Do it only for current Vertices setuped!!! because a swapIgRdrPassHardMode awlays arise when the ig is </font>
+01621 <font class="comment">// in construcion.</font>
+01622 <font class="comment">// Hence here, we may have vegetRdrPass.NVertices &lt; vegetRdrPass.Vertices.size() !!!</font>
+01623 <font class="keywordflow">for</font>(i=0;i&lt;vegetRdrPass.NVertices;i++)
+01624 {
+01625 <font class="comment">// get idx in src allocator.</font>
+01626 uint srcId= vegetRdrPass.Vertices[i];
+01627 <font class="comment">// allocate a verex in the dst allocator.</font>
+01628 uint dstId= dstAllocator.allocateVertex();
+01629
+01630 <font class="comment">// copy from VBsoft of src to dst.</font>
+01631 <font class="keywordtype">void</font> *vbSrc= srcAllocator.getVertexPointer(srcId);
+01632 <font class="keywordtype">void</font> *vbDst= dstAllocator.getVertexPointer(dstId);
+01633 memcpy(vbDst, vbSrc, vbSize);
+01634 <font class="comment">// release src vertex.</font>
+01635 srcAllocator.deleteVertex(srcId);
+01636
+01637 <font class="comment">// and copy new dest id in Vertices array.</font>
+01638 vegetRdrPass.Vertices[i]= dstId;
+01639
+01640 <font class="comment">// and flush this vertex into VBHard (if dst is aVBHard).</font>
+01641 dstAllocator.flushVertex(dstId);
+01642 }
+01643
+01644 <font class="comment">// For all triangles, bind correct triangles.</font>
+01645 <a class="code" href="debug_8h.html#a6">nlassert</a>(vegetRdrPass.TriangleIndices.size() == vegetRdrPass.TriangleLocalIndices.size());
+01646 <font class="comment">// Do it only for current Triangles setuped!!! same reason as vertices</font>
+01647 <font class="comment">// For all setuped triangles indices</font>
+01648 <font class="keywordflow">for</font>(i=0;i&lt;vegetRdrPass.NTriangles*3;i++)
+01649 {
+01650 <font class="comment">// get the index in Vertices.</font>
+01651 uint localVid= vegetRdrPass.TriangleLocalIndices[i];
+01652 <font class="comment">// get the index in new VBufffer (dstAllocator), and copy to TriangleIndices</font>
+01653 vegetRdrPass.TriangleIndices[i]= vegetRdrPass.Vertices[localVid];
+01654 }
+01655
+01656 <font class="comment">// Since change is made, flag the IG rdrpass</font>
+01657 vegetRdrPass.HardMode= !vegetRdrPass.HardMode;
+01658 }
+01659
+01660
+01661 <font class="comment">// ***************************************************************************</font>
+01662 <font class="comment">// ***************************************************************************</font>
+01663 <font class="comment">// Render</font>
+01664 <font class="comment">// ***************************************************************************</font>
+01665 <font class="comment">// ***************************************************************************</font>
+01666
+01667
+01668 <font class="comment">// ***************************************************************************</font>
+<a name="l01669"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#f0">01669</a> <font class="keywordtype">bool</font> CVegetableManager::doubleSidedRdrPass(uint rdrPass)
+01670 {
+01671 <a class="code" href="debug_8h.html#a6">nlassert</a>(rdrPass&lt;<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>);
+01672 <font class="keywordflow">return</font> (rdrPass == <a class="code" href="vegetable__def_8h.html#a2">NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED</a>) ||
+01673 (rdrPass == <a class="code" href="vegetable__def_8h.html#a4">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED</a>) ||
+01674 (rdrPass == <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>);
+01675 }
+01676
+01677 <font class="comment">// ***************************************************************************</font>
+<a name="l01678"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z884_0">01678</a> <font class="keywordtype">void</font> CVegetableManager::updateDriver(IDriver *driver)
+01679 {
+01680 <font class="comment">// update all driver</font>
+01681 uint i;
+01682 <font class="keywordflow">for</font>(i=0; i &lt;CVegetableVBAllocator::VBTypeCount; i++)
+01683 {
+01684 <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[i].updateDriver(driver);
+01685 <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[i].updateDriver(driver);
+01686 }
+01687
+01688 <font class="comment">// if driver changed, recreate vertex programs</font>
+01689 <font class="keywordflow">if</font> (driver != <a class="code" href="classNL3D_1_1CVegetableManager.html#o14">_LastDriver</a>)
+01690 {
+01691 <a class="code" href="classNL3D_1_1CVegetableManager.html#o14">_LastDriver</a> = driver;
+01692 <font class="keywordflow">for</font>(i=0; i &lt;<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; i++)
+01693 {
+01694 <a class="code" href="classNL3D_1_1CVegetableManager.html#c2">initVertexProgram</a>(i);
+01695 }
+01696 }
+01697 }
+01698
+01699
+01700 <font class="comment">// ***************************************************************************</font>
+01701 <font class="keywordtype">void</font> CVegetableManager::loadTexture(<font class="keyword">const</font> string &amp;texName)
+01702 {
+01703 <font class="comment">// setup a CTextureFile (smartPtr-ized).</font>
+01704 ITexture *tex= <font class="keyword">new</font> CTextureFile(texName);
+01705 <a class="code" href="classNL3D_1_1CVegetableManager.html#z884_1">loadTexture</a>(tex);
+01706 <font class="comment">// setup good params.</font>
+01707 tex-&gt;setFilterMode(ITexture::Linear, ITexture::LinearMipMapLinear);
+01708 tex-&gt;setWrapS(ITexture::Clamp);
+01709 tex-&gt;setWrapT(ITexture::Clamp);
+01710 }
+01711
+01712 <font class="comment">// ***************************************************************************</font>
+<a name="l01713"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z884_2">01713</a> <font class="keywordtype">void</font> CVegetableManager::loadTexture(ITexture *itex)
+01714 {
+01715 <font class="comment">// setup a ITexture (smartPtr-ized).</font>
+01716 <font class="comment">// Store in stage1, for dynamicLightmaping</font>
+01717 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setTexture(1, itex);
+01718 }
+01719
+01720 <font class="comment">// ***************************************************************************</font>
+<a name="l01721"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z884_3">01721</a> <font class="keywordtype">void</font> CVegetableManager::setDirectionalLight(<font class="keyword">const</font> CRGBA &amp;ambient, <font class="keyword">const</font> CRGBA &amp;diffuse, <font class="keyword">const</font> CVector &amp;light)
+01722 {
+01723 <a class="code" href="classNL3D_1_1CVegetableManager.html#o10">_DirectionalLight</a>= light;
+01724 <a class="code" href="classNL3D_1_1CVegetableManager.html#o10">_DirectionalLight</a>.normalize();
+01725 <font class="comment">// Setup ambient/Diffuse.</font>
+01726 <a class="code" href="classNL3D_1_1CVegetableManager.html#o11">_GlobalAmbient</a>= ambient;
+01727 <a class="code" href="classNL3D_1_1CVegetableManager.html#o12">_GlobalDiffuse</a>= diffuse;
+01728 }
+01729
+01730 <font class="comment">// ***************************************************************************</font>
+<a name="l01731"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z884_4">01731</a> <font class="keywordtype">void</font> CVegetableManager::lockBuffers()
+01732 {
+01733 <font class="comment">// lock all buffers</font>
+01734 <font class="keywordflow">for</font>(uint i=0; i &lt;CVegetableVBAllocator::VBTypeCount; i++)
+01735 {
+01736 <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[i].lockBuffer();
+01737 <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[i].lockBuffer();
+01738 }
+01739 }
+01740
+01741 <font class="comment">// ***************************************************************************</font>
+<a name="l01742"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z884_5">01742</a> <font class="keywordtype">void</font> CVegetableManager::unlockBuffers()
+01743 {
+01744 <font class="comment">// unlock all buffers</font>
+01745 <font class="keywordflow">for</font>(uint i=0; i &lt;CVegetableVBAllocator::VBTypeCount; i++)
+01746 {
+01747 <a class="code" href="classNL3D_1_1CVegetableManager.html#o6">_VBHardAllocator</a>[i].unlockBuffer();
+01748 <a class="code" href="classNL3D_1_1CVegetableManager.html#o7">_VBSoftAllocator</a>[i].unlockBuffer();
+01749 }
+01750 }
+01751
+01752
+01753 <font class="comment">// ***************************************************************************</font>
+<a name="l01754"></a><a class="code" href="classNL3D_1_1CSortVSB.html">01754</a> <font class="keyword">class </font>CSortVSB
+01755 {
+01756 <font class="keyword">public</font>:
+<a name="l01757"></a><a class="code" href="classNL3D_1_1CSortVSB.html#m0">01757</a> CVegetableSortBlock *<a class="code" href="classNL3D_1_1CSortVSB.html#m0">Sb</a>;
+01758
+<a name="l01759"></a><a class="code" href="classNL3D_1_1CSortVSB.html#a0">01759</a> <a class="code" href="classNL3D_1_1CSortVSB.html#a0">CSortVSB</a>() : <a class="code" href="classNL3D_1_1CSortVSB.html#m0">Sb</a>(NULL) {}
+<a name="l01760"></a><a class="code" href="classNL3D_1_1CSortVSB.html#a1">01760</a> <a class="code" href="classNL3D_1_1CSortVSB.html#a0">CSortVSB</a>(CVegetableSortBlock *sb) : <a class="code" href="classNL3D_1_1CSortVSB.html#m0">Sb</a>(sb) {}
+01761
+01762
+01763 <font class="comment">// for sort()</font>
+<a name="l01764"></a><a class="code" href="classNL3D_1_1CSortVSB.html#a2">01764</a> <font class="keywordtype">bool</font> <a class="code" href="classNL3D_1_1CSortVSB.html#a2">operator&lt;</a>(<font class="keyword">const</font> <a class="code" href="classNL3D_1_1CSortVSB.html#a0">CSortVSB</a> &amp;o)<font class="keyword"> const</font>
+01765 <font class="keyword"> </font>{
+01766 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CSortVSB.html#m0">Sb</a>-&gt;_SortKey&gt;o.Sb-&gt;_SortKey;
+01767 }
+01768
+01769 };
+01770
+01771
+01772 <font class="comment">// ***************************************************************************</font>
+<a name="l01773"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#c3">01773</a> <font class="keywordtype">void</font> CVegetableManager::setupVertexProgramConstants(IDriver *driver)
+01774 {
+01775 <font class="comment">// Standard</font>
+01776 <font class="comment">// setup VertexProgram constants.</font>
+01777 <font class="comment">// c[0..3] take the ModelViewProjection Matrix. After setupModelMatrix();</font>
+01778 driver-&gt;setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity);
+01779 <font class="comment">// c[4..7] take the ModelView Matrix. After setupModelMatrix();</font>
+01780 driver-&gt;setConstantMatrix(4, IDriver::ModelView, IDriver::Identity);
+01781 <font class="comment">// c[8] take usefull constants.</font>
+01782 driver-&gt;setConstant(8, 0, 1, 0.5f, 2);
+01783 <font class="comment">// c[9] take normalized directional light</font>
+01784 driver-&gt;setConstant(9, <a class="code" href="classNL3D_1_1CVegetableManager.html#o10">_DirectionalLight</a>);
+01785 <font class="comment">// c[10] take pos of camera</font>
+01786 driver-&gt;setConstant(10, <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_1">_ViewCenter</a>);
+01787 <font class="comment">// c[11] take factor for Blend formula</font>
+01788 driver-&gt;setConstant(11, -1.f/<a class="code" href="vegetable__def_8h.html#a9">NL3D_VEGETABLE_BLOCK_BLEND_TRANSITION_DIST</a>, 0, 0, 0);
+01789
+01790
+01791
+01792 <font class="comment">// Bend.</font>
+01793 <font class="comment">// c[16]= quaternion axis. w==1, and z must be 0</font>
+01794 driver-&gt;setConstant( 16, <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_0">_AngleAxis</a>.x, <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_0">_AngleAxis</a>.y, <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_0">_AngleAxis</a>.z, 1);
+01795 <font class="comment">// c[17]= {timeAnim, WindPower, WindPower*(1-WindBendMin)/2, 0)}</font>
+01796 driver-&gt;setConstant( 17, (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_6">_WindAnimTime</a>, <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_2">_WindPower</a>, <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_2">_WindPower</a>*(1-<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_3">_WindBendMin</a>)/2, 0 );
+01797 <font class="comment">// c[18]= High order Taylor cos coefficient: { -1/2, 1/24, -1/720, 1/40320 }</font>
+01798 driver-&gt;setConstant( 18, -1/2.f, 1/24.f, -1/720.f, 1/40320.f );
+01799 <font class="comment">// c[19]= Low order Taylor cos coefficient: { 1, -1/2, 1/24, -1/720 }</font>
+01800 driver-&gt;setConstant( 19, 1, -1/2.f, 1/24.f, -1/720.f );
+01801 <font class="comment">// c[20]= Low order Taylor sin coefficient: { 1, -1/6, 1/120, -1/5040 }</font>
+01802 driver-&gt;setConstant( 20, 1, -1/6.f, 1/120.f, -1/5040.f );
+01803 <font class="comment">// c[21]= Special constant vector for quatToMatrix: { 0, 1, -1, 0 }</font>
+01804 driver-&gt;setConstant( 21, 0.f, 1.f, -1.f, 0.f);
+01805 <font class="comment">// c[22]= {0.5f, Pi, 2*Pi, 1/(2*Pi)}</font>
+01806 driver-&gt;setConstant( 22, 0.5f, (<font class="keywordtype">float</font>)<a class="code" href="namespaceNLMISC.html#a7">Pi</a>, (<font class="keywordtype">float</font>)(2*<a class="code" href="namespaceNLMISC.html#a7">Pi</a>), (<font class="keywordtype">float</font>)(1/(2*<a class="code" href="namespaceNLMISC.html#a7">Pi</a>)) );
+01807 <font class="comment">// c[23]= {NL3D_VEGETABLE_VP_LUT_SIZE, 0, 0, 0}. NL3D_VEGETABLE_VP_LUT_SIZE==64.</font>
+01808 driver-&gt;setConstant( 23, <a class="code" href="vegetable__def_8h.html#a6">NL3D_VEGETABLE_VP_LUT_SIZE</a>, 0.f, 0.f, 0.f );
+01809
+01810
+01811 <font class="comment">// Fill constant. Start at 32.</font>
+01812 <font class="keywordflow">for</font>(uint i=0; i&lt;<a class="code" href="vegetable__def_8h.html#a6">NL3D_VEGETABLE_VP_LUT_SIZE</a>; i++)
+01813 {
+01814 CVector2f cur= <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_8">_WindTable</a>[i];
+01815 CVector2f delta= <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_9">_WindDeltaTable</a>[i];
+01816 driver-&gt;setConstant( 32+i, cur.x, cur.y, delta.x, delta.y );
+01817 }
+01818 }
+01819
+01820
+01821 <font class="comment">// ***************************************************************************</font>
+<a name="l01822"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z884_6">01822</a> <font class="keywordtype">void</font> CVegetableManager::render(<font class="keyword">const</font> CVector &amp;viewCenter, <font class="keyword">const</font> CVector &amp;frontVector, <font class="keyword">const</font> std::vector&lt;CPlane&gt; &amp;pyramid,
+01823 ITexture *textureDLM, IDriver *driver)
+01824 {
+01825 <a class="code" href="hierarchical__timer_8h.html#a4">H_AUTO</a>( NL3D_Vegetable_Render );
+01826
+01827 CVegetableClipBlock *rootToRender= NULL;
+01828
+01829 <font class="comment">// get normalized front vector.</font>
+01830 CVector frontVectorNormed= frontVector.normed();
+01831
+01832 <font class="comment">// For Speed debug only.</font>
+01833 <font class="comment">/*extern bool YOYO_ATTest;</font>
+01834 <font class="comment"> if(YOYO_ATTest)</font>
+01835 <font class="comment"> return;</font>
+01836 <font class="comment"> */</font>
+01837
+01838 <font class="comment">// Clip.</font>
+01839 <font class="comment">//--------------------</font>
+01840 <font class="comment">// For all current not empty clipBlocks, clip against pyramid, and insert visibles in list.</font>
+01841 CVegetableClipBlock *ptrClipBlock= <a class="code" href="classNL3D_1_1CVegetableManager.html#o3">_ClipBlockList</a>.begin();
+01842 <font class="keywordflow">while</font>(ptrClipBlock)
+01843 {
+01844 <font class="comment">// if the clipBlock is visible and not empty</font>
+01845 <font class="keywordflow">if</font>(ptrClipBlock-&gt;clip(pyramid))
+01846 {
+01847 <font class="comment">// insert into visible list.</font>
+01848 ptrClipBlock-&gt;_RenderNext= rootToRender;
+01849 rootToRender= ptrClipBlock;
+01850 }
+01851
+01852 <font class="comment">// next</font>
+01853 ptrClipBlock= (CVegetableClipBlock*)ptrClipBlock-&gt;Next;
+01854 }
+01855
+01856
+01857 <font class="comment">// If no clip block visible, just skip!!</font>
+01858 <font class="keywordflow">if</font>(rootToRender==NULL)
+01859 <font class="keywordflow">return</font>;
+01860
+01861
+01862 <font class="comment">// Prepare Render</font>
+01863 <font class="comment">//--------------------</font>
+01864
+01865 <font class="comment">// profile.</font>
+01866 CPrimitiveProfile ppIn, ppOut;
+01867 driver-&gt;profileRenderedPrimitives(ppIn, ppOut);
+01868 uint precNTriRdr= ppOut.NTriangles;
+01869
+01870
+01871 <font class="comment">// Disable Fog.</font>
+01872 <font class="keywordtype">bool</font> bkupFog;
+01873 bkupFog= driver-&gt;fogEnabled();
+01874 driver-&gt;enableFog(<font class="keyword">false</font>);
+01875
+01876
+01877 <font class="comment">// Used by setupVertexProgramConstants(). The center of camera.</font>
+01878 <font class="comment">// Used for AlphaBlending, and for ZBuffer precision problems.</font>
+01879 <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_1">_ViewCenter</a>= viewCenter;
+01880
+01881
+01882 <font class="comment">// The manager is identity in essence. But for ZBuffer improvements, must set it as close</font>
+01883 <font class="comment">// to the camera. In the VertexProgram, _ViewCenter is substracted from bent vertex pos. So take it as position.</font>
+01884 <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_3">_ManagerMatrix</a>.<a class="code" href="classNLMISC_1_1CMatrix.html#z290_0">identity</a>();
+01885 <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_3">_ManagerMatrix</a>.<a class="code" href="classNLMISC_1_1CMatrix.html#z290_6">setPos</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z889_1">_ViewCenter</a>);
+01886
+01887
+01888 <font class="comment">// set model matrix to the manager matrix.</font>
+01889 driver-&gt;setupModelMatrix(<a class="code" href="classNL3D_1_1CVegetableManager.html#z889_3">_ManagerMatrix</a>);
+01890
+01891
+01892 <font class="comment">// set the driver for all allocators</font>
+01893 <a class="code" href="classNL3D_1_1CVegetableManager.html#z884_0">updateDriver</a>(driver);
+01894
+01895
+01896 <font class="comment">// Compute Bend Anim.</font>
+01897
+01898 <font class="comment">// AnimFrequency factor.</font>
+01899 <font class="comment">// Doing it incrementaly allow change of of frequency each frame with good results.</font>
+01900 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_6">_WindAnimTime</a>+= (<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_4">_Time</a> - <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_5">_WindPrecRenderTime</a>)*<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_1">_WindFrequency</a>;
+01901 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_6">_WindAnimTime</a>= fmod(<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_6">_WindAnimTime</a>, (<font class="keywordtype">float</font>)<a class="code" href="vegetable__def_8h.html#a11">NL3D_VEGETABLE_FREQUENCY_FACTOR_PREC</a>);
+01902 <font class="comment">// NB: Leave timeBend (_WindAnimTime) as a time (ie [0..1]), because VP do a "EXP time".</font>
+01903 <font class="comment">// For incremental computing.</font>
+01904 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_5">_WindPrecRenderTime</a>= <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_4">_Time</a>;
+01905
+01906
+01907 <font class="comment">// compute the angleAxis corresponding to direction</font>
+01908 <font class="comment">// perform a 90° rotation to get correct angleAxis</font>
+01909 <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_0">_AngleAxis</a>.set(-<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_0">_WindDirection</a>.y,<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_0">_WindDirection</a>.x,0);
+01910
+01911
+01912 <font class="comment">// Fill LUT WindTable.</font>
+01913 uint i;
+01914 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="vegetable__def_8h.html#a6">NL3D_VEGETABLE_VP_LUT_SIZE</a>; i++)
+01915 {
+01916 <font class="comment">/* NB: this formula works quite well, because vertex BendFactor is expressed in Radian/2.</font>
+01917 <font class="comment"> And since animFactor==(_CosTable[i] + 1) E [0..2], we have here an arc-cirle computing:</font>
+01918 <font class="comment"> dmove= Radius * AngleRadian/2 * animFactor. So at max of animFactor (ie 2), we have:</font>
+01919 <font class="comment"> dmove= Radius * AngleRadian, which is by definition an arc-cirle computing...</font>
+01920 <font class="comment"> And so this approximate the Bend-quaternion Vertex Program.</font>
+01921 <font class="comment"> */</font>
+01922 <font class="keywordtype">float</font> windForce= (<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_7">_CosTable</a>[(i+32)%64] + 1);
+01923 <font class="comment">// Modify with _WindPower / _WindBendMin.</font>
+01924 windForce= <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_3">_WindBendMin</a>*2 + windForce * (1-<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_3">_WindBendMin</a>);
+01925 windForce*= <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_2">_WindPower</a>;
+01926 <font class="comment">// Compute direction of the wind, and multiply by windForce.</font>
+01927 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_8">_WindTable</a>[i]= CVector2f(<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_0">_WindDirection</a>.x, <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_0">_WindDirection</a>.y) * windForce;
+01928 }
+01929 <font class="comment">// compute delta</font>
+01930 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="vegetable__def_8h.html#a6">NL3D_VEGETABLE_VP_LUT_SIZE</a>; i++)
+01931 {
+01932 CVector2f cur= <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_8">_WindTable</a>[i];
+01933 CVector2f delta= <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_8">_WindTable</a>[ (i+1)%<a class="code" href="vegetable__def_8h.html#a6">NL3D_VEGETABLE_VP_LUT_SIZE</a> ] - cur;
+01934 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_9">_WindDeltaTable</a>[i]= delta;
+01935 }
+01936
+01937
+01938 <font class="comment">// setup VP constants.</font>
+01939 <a class="code" href="classNL3D_1_1CVegetableManager.html#c3">setupVertexProgramConstants</a>(driver);
+01940
+01941
+01942 <font class="comment">// Setup TexEnvs for Dynamic lightmapping</font>
+01943 <font class="comment">//--------------------</font>
+01944 <font class="comment">// if the dynamic lightmap is provided</font>
+01945 <font class="keywordflow">if</font>(textureDLM)
+01946 {
+01947 <font class="comment">// stage0 RGB is Diffuse + DLM.</font>
+01948 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setTexture(0, textureDLM);
+01949 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvOpRGB(0, CMaterial::Add);
+01950 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvArg0RGB(0, CMaterial::Texture, CMaterial::SrcColor);
+01951 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvArg1RGB(0, CMaterial::Diffuse, CMaterial::SrcColor);
+01952 <font class="comment">// stage1 RGB is Previous * Texture</font>
+01953 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvOpRGB(1, CMaterial::Modulate);
+01954 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvArg0RGB(1, CMaterial::Texture, CMaterial::SrcColor);
+01955 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvArg1RGB(1, CMaterial::Previous, CMaterial::SrcColor);
+01956 }
+01957 <font class="keywordflow">else</font>
+01958 {
+01959 <font class="comment">// reset stage0 (to skip it)</font>
+01960 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setTexture(0, NULL);
+01961 <font class="comment">// stage1 RGB is Diffuse * Texture</font>
+01962 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvOpRGB(1, CMaterial::Modulate);
+01963 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvArg0RGB(1, CMaterial::Texture, CMaterial::SrcColor);
+01964 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvArg1RGB(1, CMaterial::Diffuse, CMaterial::SrcColor);
+01965 }
+01966 <font class="comment">// stage1 Alpha is always "Modulate texture with diffuse Alpha"</font>
+01967 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvOpAlpha(1, CMaterial::Modulate);
+01968 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvArg0Alpha(1, CMaterial::Texture, CMaterial::SrcAlpha);
+01969 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.texEnvArg1Alpha(1, CMaterial::Diffuse, CMaterial::SrcAlpha);
+01970
+01971
+01972
+01973 <font class="comment">// Render !ZSORT pass</font>
+01974 <font class="comment">//--------------------</font>
+01975
+01976 <font class="comment">// setup material (may have change because of ZSORT / alphaBlend pass)</font>
+01977 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setBlend(<font class="keyword">false</font>);
+01978 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setZWrite(<font class="keyword">true</font>);
+01979 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setAlphaTestThreshold(0.5f);
+01980
+01981
+01982 <font class="comment">/*</font>
+01983 <font class="comment"> Prefer sort with Soft / Hard first.</font>
+01984 <font class="comment"> Also, Prefer do VBsoft last, for better GPU //ism with Landscape.</font>
+01985 <font class="comment"> */</font>
+01986 <font class="comment">// For both allocators: Hard(1) then Soft(0)</font>
+01987 <font class="keywordflow">for</font>(sint vbHardMode= 1; vbHardMode&gt;=0; vbHardMode--)
+01988 {
+01989 <font class="comment">// For all renderPass.</font>
+01990 <font class="keywordflow">for</font>(sint rdrPass=0; rdrPass &lt; <a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; rdrPass++)
+01991 {
+01992 <font class="comment">// skip ZSORT rdrPass, done after.</font>
+01993 <font class="keywordflow">if</font>(rdrPass == <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>)
+01994 <font class="keywordflow">continue</font>;
+01995
+01996 <font class="comment">// which allocator?</font>
+01997 CVegetableVBAllocator &amp;vbAllocator= <a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPass, vbHardMode);
+01998
+01999 <font class="comment">// Do the pass only if there is some vertices to draw.</font>
+02000 <font class="keywordflow">if</font>(vbAllocator.getNumUserVerticesAllocated()&gt;0)
+02001 {
+02002 <font class="comment">// additional setup to the material</font>
+02003 <font class="keywordtype">bool</font> doubleSided= <a class="code" href="classNL3D_1_1CVegetableManager.html#f0">doubleSidedRdrPass</a>(rdrPass);
+02004 <font class="comment">// set the 2Sided flag in the material</font>
+02005 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setDoubleSided( doubleSided );
+02006 <font class="comment">// must enable VP DoubleSided coloring</font>
+02007 driver-&gt;enableVertexProgramDoubleSidedColor(doubleSided);
+02008
+02009
+02010 <font class="comment">// Activate the unique material.</font>
+02011 driver-&gt;setupMaterial(<a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>);
+02012
+02013 <font class="comment">// activate Vertex program first.</font>
+02014 <font class="comment">//nlinfo("\nSTARTVP\n%s\nENDVP\n", _VertexProgram[rdrPass]-&gt;getProgram().c_str());</font>
+02015 <a class="code" href="debug_8h.html#a9">nlverify</a>(driver-&gt;activeVertexProgram(<a class="code" href="classNL3D_1_1CVegetableManager.html#o8">_VertexProgram</a>[rdrPass]));
+02016
+02017 <font class="comment">// Activate the good VBuffer</font>
+02018 vbAllocator.activate();
+02019
+02020 <font class="comment">// For all visibles clipBlock, render their instance groups.</font>
+02021 ptrClipBlock= rootToRender;
+02022 <font class="keywordflow">while</font>(ptrClipBlock)
+02023 {
+02024 <font class="comment">// For all sortBlock of the clipBlock</font>
+02025 CVegetableSortBlock *ptrSortBlock= ptrClipBlock-&gt;_SortBlockList.begin();
+02026 <font class="keywordflow">while</font>(ptrSortBlock)
+02027 {
+02028 <font class="comment">// For all igs of the sortBlock</font>
+02029 CVegetableInstanceGroup *ptrIg= ptrSortBlock-&gt;_InstanceGroupList.begin();
+02030 <font class="keywordflow">while</font>(ptrIg)
+02031 {
+02032 <font class="comment">// rdrPass</font>
+02033 CVegetableInstanceGroup::CVegetableRdrPass &amp;vegetRdrPass= ptrIg-&gt;_RdrPass[rdrPass];
+02034
+02035 <font class="comment">// if this rdrPass is in same HardMode as we process now.</font>
+02036 <font class="keywordflow">if</font>( (vegetRdrPass.HardMode &amp;&amp; vbHardMode==1) || (!vegetRdrPass.HardMode &amp;&amp; vbHardMode==0) )
+02037 {
+02038 <font class="comment">// Ok, Render the faces.</font>
+02039 <font class="keywordflow">if</font>(vegetRdrPass.NTriangles)
+02040 {
+02041 driver-&gt;renderSimpleTriangles(&amp;vegetRdrPass.TriangleIndices[0],
+02042 vegetRdrPass.NTriangles);
+02043 }
+02044 }
+02045
+02046 <font class="comment">// next ig.</font>
+02047 ptrIg= (CVegetableInstanceGroup*)ptrIg-&gt;Next;
+02048 }
+02049
+02050 <font class="comment">// next sortBlock</font>
+02051 ptrSortBlock= (CVegetableSortBlock *)(ptrSortBlock-&gt;Next);
+02052 }
+02053
+02054 <font class="comment">// next clipBlock to render </font>
+02055 ptrClipBlock= ptrClipBlock-&gt;_RenderNext;
+02056 }
+02057 }
+02058
+02059 }
+02060
+02061 }
+02062
+02063 <font class="comment">// Render ZSort pass.</font>
+02064 <font class="comment">//--------------------</font>
+02065
+02066 <font class="comment">// Debug Quadrants.</font>
+02067 <font class="comment">/*static vector&lt;CVector&gt; p0DebugLines;</font>
+02068 <font class="comment"> static vector&lt;CVector&gt; p1DebugLines;</font>
+02069 <font class="comment"> p0DebugLines.clear();</font>
+02070 <font class="comment"> p1DebugLines.clear();*/</font>
+02071
+02072 <font class="comment">// For all Blend model Layers, clear Sort Block list and setup.</font>
+02073 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>;i++)
+02074 {
+02075 <font class="comment">// must have been created.</font>
+02076 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[i]);
+02077 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]);
+02078 <font class="comment">// NB: don't refresh list, it is done in CVegetableBlendLayerModel.</font>
+02079 <font class="comment">// We must do it here, because if vegetableManger::render() is no more called (eg: disabled),</font>
+02080 <font class="comment">// then the models must do nothing.</font>
+02081
+02082 <font class="comment">// To get layers correclty sorted from fornt to back, must init their pos</font>
+02083 <font class="comment">// because it is the renderTraversal which sort them.</font>
+02084 <font class="comment">// compute distance to camera of this layer.</font>
+02085 <font class="keywordtype">float</font> layerZ= i * <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_3">_ZSortLayerDistMax</a> / <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>;
+02086 <font class="comment">// compute position of this layer.</font>
+02087 CVector pos= viewCenter + frontVector * layerZ;
+02088 <font class="comment">// special setup in the layer.</font>
+02089 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[i]-&gt;setWorldPos(pos);
+02090 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]-&gt;setWorldPos(pos);
+02091 }
+02092
+02093 <font class="comment">// If some vertices in arrays for ZSort rdrPass</font>
+02094 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(<a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>, 0).getNumUserVerticesAllocated()&gt;0 ||
+02095 <a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(<a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>, 1).getNumUserVerticesAllocated()&gt;0 )
+02096 {
+02097 uint rdrPass= <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>;
+02098
+02099 <font class="comment">// sort</font>
+02100 <font class="comment">//-------------</font>
+02101 <font class="comment">// Array for sorting. (static to avoid reallocation)</font>
+02102 <font class="keyword">static</font> vector&lt;CSortVSB&gt; sortVegetSbs;
+02103 sortVegetSbs.clear();
+02104
+02105 <font class="comment">// For all visibles clipBlock</font>
+02106 ptrClipBlock= rootToRender;
+02107 <font class="keywordflow">while</font>(ptrClipBlock)
+02108 {
+02109 <font class="comment">// For all sortBlock, prepare to sort them</font>
+02110 CVegetableSortBlock *ptrSortBlock= ptrClipBlock-&gt;_SortBlockList.begin();
+02111 <font class="keywordflow">while</font>(ptrSortBlock)
+02112 {
+02113 <font class="comment">// if the sortBlock has some sorted faces to render</font>
+02114 <font class="keywordflow">if</font>(ptrSortBlock-&gt;_NTriangles != 0)
+02115 {
+02116 <font class="comment">// Compute Distance to Viewer.</font>
+02117 <font class="comment">/* NB: compute radial distance (with norm()) instead of linear distance </font>
+02118 <font class="comment"> (DotProduct with front vector) get less "ZSort poping".</font>
+02119 <font class="comment"> */</font>
+02120 CVector dirToSb= ptrSortBlock-&gt;_Center - viewCenter;
+02121 <font class="keywordtype">float</font> distToViewer= dirToSb.norm();
+02122 <font class="comment">// SortKey change if the center is behind the camera.</font>
+02123 <font class="keywordflow">if</font>(dirToSb * frontVectorNormed&lt;0)
+02124 {
+02125 ptrSortBlock-&gt;_SortKey= - distToViewer;
+02126 }
+02127 <font class="keywordflow">else</font>
+02128 {
+02129 ptrSortBlock-&gt;_SortKey= distToViewer;
+02130 }
+02131
+02132 <font class="comment">// Choose the quadrant for this sortBlock</font>
+02133 sint bestDirIdx= 0;
+02134 <font class="keywordtype">float</font> bestDirVal= -FLT_MAX;
+02135 <font class="comment">// If too near, must take the frontVector as key, to get better sort.</font>
+02136 <font class="comment">// use ptrSortBlock-&gt;_SortKey to get correct negative values.</font>
+02137 <font class="keywordflow">if</font>(ptrSortBlock-&gt;_SortKey &lt; ptrSortBlock-&gt;_Radius)
+02138 {
+02139 dirToSb= frontVectorNormed;
+02140 }
+02141
+02142 <font class="comment">// NB: no need to normalize dirToSb, because need only to sort with DP</font>
+02143 <font class="comment">// choose the good list of triangles according to quadrant.</font>
+02144 <font class="keywordflow">for</font>(uint dirIdx=0; dirIdx&lt;<a class="code" href="vegetable__def_8h.html#a10">NL3D_VEGETABLE_NUM_QUADRANT</a>; dirIdx++)
+02145 {
+02146 <font class="keywordtype">float</font> dirVal= CVegetableQuadrant::Dirs[dirIdx] * dirToSb;
+02147 <font class="keywordflow">if</font>(dirVal&gt;bestDirVal)
+02148 {
+02149 bestDirVal= dirVal;
+02150 bestDirIdx= dirIdx;
+02151 }
+02152 }
+02153
+02154 <font class="comment">// set the result.</font>
+02155 ptrSortBlock-&gt;_QuadrantId= bestDirIdx;
+02156
+02157 <font class="comment">// insert in list to sort.</font>
+02158 sortVegetSbs.push_back(CSortVSB(ptrSortBlock));
+02159
+02160 <font class="comment">// Debug Quadrants</font>
+02161 <font class="comment">/*p0DebugLines.push_back(ptrSortBlock-&gt;_Center);</font>
+02162 <font class="comment"> p1DebugLines.push_back(ptrSortBlock-&gt;_Center + CVegetableQuadrant::Dirs[bestDirIdx]);*/</font>
+02163 }
+02164
+02165 <font class="comment">// next sortBlock</font>
+02166 ptrSortBlock= (CVegetableSortBlock *)(ptrSortBlock-&gt;Next);
+02167 }
+02168
+02169 <font class="comment">// next clipBlock to render </font>
+02170 ptrClipBlock= ptrClipBlock-&gt;_RenderNext;
+02171 }
+02172
+02173 <font class="comment">// sort!</font>
+02174 <font class="comment">// QSort. (I tried, better than radix sort, guckk!!)</font>
+02175 sort(sortVegetSbs.begin(), sortVegetSbs.end());
+02176
+02177
+02178 <font class="comment">// setup material for this rdrPass. NB: rendered after (in LayerModels).</font>
+02179 <font class="comment">//-------------</font>
+02180 <font class="keywordtype">bool</font> doubleSided= <a class="code" href="classNL3D_1_1CVegetableManager.html#f0">doubleSidedRdrPass</a>(rdrPass);
+02181 <font class="comment">// set the 2Sided flag in the material</font>
+02182 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setDoubleSided( doubleSided );
+02183
+02184 <font class="comment">// setup the unique material.</font>
+02185 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setBlend(<font class="keyword">true</font>);
+02186 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setZWrite(<font class="keyword">false</font>);
+02187 <font class="comment">// leave AlphaTest but still kick low alpha values (for fillRate performance)</font>
+02188 <a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>.setAlphaTestThreshold(0.1f);
+02189
+02190
+02191
+02192 <font class="comment">// order them in Layers.</font>
+02193 <font class="comment">//-------------</font>
+02194
+02195 <font class="comment">// render from back to front, to keep correct Z order in a single layer.</font>
+02196 <font class="keywordflow">for</font>(uint i=0; i&lt;sortVegetSbs.size();i++)
+02197 {
+02198 CVegetableSortBlock *ptrSortBlock= sortVegetSbs[i].Sb;
+02199
+02200 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>= ptrSortBlock-&gt;_SortKey;
+02201 <font class="comment">// compute in which layer must store this SB.</font>
+02202 <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>*<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a> / <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_3">_ZSortLayerDistMax</a>;
+02203 <font class="comment">// Avoid a floor(), using an OptFastFloor, but without the OptFastFloorBegin() End() group.</font>
+02204 <font class="comment">// =&gt; avoid the imprecision with such a trick; *256, then divide the integer by 256.</font>
+02205 sint layer= <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>*256) &gt;&gt; 8;
+02206 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(layer, 0, (sint)<a class="code" href="classNL3D_1_1CVegetableManager.html#z890_2">_NumZSortBlendLayers</a>-1);
+02207
+02208 <font class="comment">// Range in correct layer, according to water ordering</font>
+02209 <font class="keywordflow">if</font>(ptrSortBlock-&gt;_UnderWater)
+02210 <font class="comment">// range in the correct layermodel (NB: keep the same layer internal order).</font>
+02211 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[layer]-&gt;SortBlocks.push_back(ptrSortBlock);
+02212 <font class="keywordflow">else</font>
+02213 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[layer]-&gt;SortBlocks.push_back(ptrSortBlock);
+02214 }
+02215
+02216 }
+02217
+02218
+02219 <font class="comment">// Quit</font>
+02220 <font class="comment">//--------------------</font>
+02221
+02222 <font class="comment">// disable VertexProgram.</font>
+02223 driver-&gt;activeVertexProgram(NULL);
+02224
+02225 <font class="comment">// reset state to default.</font>
+02226 driver-&gt;enableVertexProgramDoubleSidedColor(<font class="keyword">false</font>);
+02227
+02228
+02229 <font class="comment">// restore Fog.</font>
+02230 driver-&gt;enableFog(bkupFog);
+02231
+02232
+02233 <font class="comment">// Debug Quadrants</font>
+02234 <font class="comment">/*for(uint l=0; l&lt;p0DebugLines.size();l++)</font>
+02235 <font class="comment"> {</font>
+02236 <font class="comment"> CVector dv= CVector::K;</font>
+02237 <font class="comment"> CDRU::drawLine(p0DebugLines[l]+dv, p1DebugLines[l]+dv, CRGBA(255,0,0), *driver);</font>
+02238 <font class="comment"> }*/</font>
+02239
+02240 <font class="comment">// profile: compute number of triangles rendered with vegetable manager.</font>
+02241 driver-&gt;profileRenderedPrimitives(ppIn, ppOut);
+02242 <a class="code" href="classNL3D_1_1CVegetableManager.html#o13">_NumVegetableFaceRendered</a>= ppOut.NTriangles-precNTriRdr;
+02243
+02244 }
+02245
+02246
+02247 <font class="comment">// ***************************************************************************</font>
+<a name="l02248"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z890_0">02248</a> <font class="keywordtype">void</font> CVegetableManager::setupRenderStateForBlendLayerModel(IDriver *driver)
+02249 {
+02250 <font class="comment">// Setup Global.</font>
+02251 <font class="comment">//=============</font>
+02252 <font class="comment">// disable fog, for faster VP.</font>
+02253 <a class="code" href="classNL3D_1_1CVegetableManager.html#z889_2">_BkupFog</a>= driver-&gt;fogEnabled();
+02254 driver-&gt;enableFog(<font class="keyword">false</font>);
+02255
+02256 <font class="comment">// set model matrix to the manager matrix.</font>
+02257 driver-&gt;setupModelMatrix(<a class="code" href="classNL3D_1_1CVegetableManager.html#z889_3">_ManagerMatrix</a>);
+02258
+02259 <font class="comment">// setup VP constants.</font>
+02260 <a class="code" href="classNL3D_1_1CVegetableManager.html#c3">setupVertexProgramConstants</a>(driver);
+02261
+02262 <font class="comment">// Setup RdrPass.</font>
+02263 <font class="comment">//=============</font>
+02264 uint rdrPass= <a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>;
+02265
+02266 <font class="comment">// setup doubleSidedmaterial for this rdrPass.</font>
+02267 <font class="keywordtype">bool</font> doubleSided= <a class="code" href="classNL3D_1_1CVegetableManager.html#f0">doubleSidedRdrPass</a>(rdrPass);
+02268 <font class="comment">// must enable VP DoubleSided coloring</font>
+02269 driver-&gt;enableVertexProgramDoubleSidedColor(doubleSided);
+02270
+02271 <font class="comment">// Activate the unique material (correclty setuped for AlphaBlend in render()).</font>
+02272 driver-&gt;setupMaterial(<a class="code" href="classNL3D_1_1CVegetableManager.html#o9">_VegetableMaterial</a>);
+02273
+02274 <font class="comment">// activate Vertex program first.</font>
+02275 <font class="comment">//nlinfo("\nSTARTVP\n%s\nENDVP\n", _VertexProgram[rdrPass]-&gt;getProgram().c_str());</font>
+02276 <a class="code" href="debug_8h.html#a9">nlverify</a>(driver-&gt;activeVertexProgram(<a class="code" href="classNL3D_1_1CVegetableManager.html#o8">_VertexProgram</a>[rdrPass]));
+02277
+02278 }
+02279
+02280
+02281 <font class="comment">// ***************************************************************************</font>
+<a name="l02282"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z887_0">02282</a> <font class="keywordtype">void</font> CVegetableManager::resetNumVegetableFaceRendered()
+02283 {
+02284 <a class="code" href="classNL3D_1_1CVegetableManager.html#o13">_NumVegetableFaceRendered</a>= 0;
+02285 }
+02286
+02287
+02288 <font class="comment">// ***************************************************************************</font>
+<a name="l02289"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z887_1">02289</a> uint CVegetableManager::getNumVegetableFaceRendered()<font class="keyword"> const</font>
+02290 <font class="keyword"></font>{
+02291 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CVegetableManager.html#o13">_NumVegetableFaceRendered</a>;
+02292 }
+02293
+02294
+02295 <font class="comment">// ***************************************************************************</font>
+<a name="l02296"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z890_1">02296</a> <font class="keywordtype">void</font> CVegetableManager::exitRenderStateForBlendLayerModel(IDriver *driver)
+02297 {
+02298 <font class="comment">// disable VertexProgram.</font>
+02299 driver-&gt;activeVertexProgram(NULL);
+02300
+02301 <font class="comment">// reset state to default.</font>
+02302 driver-&gt;enableVertexProgramDoubleSidedColor(<font class="keyword">false</font>);
+02303
+02304 <font class="comment">// restore Fog.</font>
+02305 driver-&gt;enableFog(<a class="code" href="classNL3D_1_1CVegetableManager.html#z889_2">_BkupFog</a>);
+02306 }
+02307
+02308
+02309
+02310 <font class="comment">// ***************************************************************************</font>
+<a name="l02311"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z885_0">02311</a> <font class="keywordtype">void</font> CVegetableManager::setWind(<font class="keyword">const</font> CVector &amp;windDir, <font class="keywordtype">float</font> windFreq, <font class="keywordtype">float</font> windPower, <font class="keywordtype">float</font> windBendMin)
+02312 {
+02313 <font class="comment">// Keep only XY component of the Wind direction (because VP only support z==0 quaternions).</font>
+02314 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_0">_WindDirection</a>= windDir;
+02315 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_0">_WindDirection</a>.z= 0;
+02316 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_0">_WindDirection</a>.normalize();
+02317 <font class="comment">// copy setup</font>
+02318 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_1">_WindFrequency</a>= windFreq;
+02319 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_2">_WindPower</a>= windPower;
+02320 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_3">_WindBendMin</a>= windBendMin;
+02321 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z888_3">_WindBendMin</a>, 0, 1);
+02322 }
+02323
+02324 <font class="comment">// ***************************************************************************</font>
+<a name="l02325"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z885_1">02325</a> <font class="keywordtype">void</font> CVegetableManager::setTime(<font class="keywordtype">double</font> time)
+02326 {
+02327 <font class="comment">// copy time</font>
+02328 <a class="code" href="classNL3D_1_1CVegetableManager.html#z888_4">_Time</a>= time;
+02329 }
+02330
+02331
+02332 <font class="comment">// ***************************************************************************</font>
+02333 <font class="comment">// ***************************************************************************</font>
+02334 <font class="comment">// Lighting part.</font>
+02335 <font class="comment">// ***************************************************************************</font>
+02336 <font class="comment">// ***************************************************************************</font>
+02337
+02338
+02339 <font class="comment">// ***************************************************************************</font>
+<a name="l02340"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z886_0">02340</a> <font class="keywordtype">void</font> CVegetableManager::setUpdateLightingTime(<font class="keywordtype">double</font> time)
+02341 {
+02342 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_5">_ULTime</a>= time;
+02343 }
+02344
+02345
+02346 <font class="comment">// ***************************************************************************</font>
+<a name="l02347"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z886_1">02347</a> <font class="keywordtype">void</font> CVegetableManager::updateLighting()
+02348 {
+02349 <font class="comment">// first time in this method??</font>
+02350 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_4">_ULPrecTimeInit</a>)
+02351 {
+02352 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_4">_ULPrecTimeInit</a>= <font class="keyword">true</font>;
+02353 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_3">_ULPrecTime</a>= <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_5">_ULTime</a>;
+02354 }
+02355 <font class="comment">// compute delta time from last update.</font>
+02356 <font class="keywordtype">float</font> dt= float(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_5">_ULTime</a> - <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_3">_ULPrecTime</a>);
+02357 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_3">_ULPrecTime</a>= <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_5">_ULTime</a>;
+02358
+02359 <font class="comment">// compute number of vertices to update.</font>
+02360 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_7">_ULNVerticesToUpdate</a>+= dt*<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_6">_ULFrequency</a> * <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_8">_ULNTotalVertices</a>;
+02361 <font class="comment">// maximize, so at max, it computes all Igs, just one time.</font>
+02362 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_7">_ULNVerticesToUpdate</a>= <a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_7">_ULNVerticesToUpdate</a>, (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_8">_ULNTotalVertices</a>);
+02363
+02364 <font class="comment">// go.</font>
+02365 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_0">doUpdateLighting</a>();
+02366 }
+02367
+02368
+02369 <font class="comment">// ***************************************************************************</font>
+<a name="l02370"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z886_3">02370</a> <font class="keywordtype">void</font> CVegetableManager::updateLightingAll()
+02371 {
+02372 <font class="comment">// maximize, so at max, it computes all Igs</font>
+02373 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_7">_ULNVerticesToUpdate</a>= (float)<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_8">_ULNTotalVertices</a>;
+02374
+02375 <font class="comment">// go.</font>
+02376 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_0">doUpdateLighting</a>();
+02377 }
+02378
+02379
+02380 <font class="comment">// ***************************************************************************</font>
+<a name="l02381"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z891_0">02381</a> <font class="keywordtype">void</font> CVegetableManager::doUpdateLighting()
+02382 {
+02383 <font class="comment">// while there is still some vertices to update.</font>
+02384 <font class="keywordflow">while</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_7">_ULNVerticesToUpdate</a> &gt; 0 &amp;&amp; <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>)
+02385 {
+02386 <font class="comment">// update the current ig. if all updated, skip to next one.</font>
+02387 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_1">updateLightingIGPart</a>())
+02388 {
+02389 <font class="comment">// next</font>
+02390 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>= <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>-&gt;_ULNext;
+02391 }
+02392 }
+02393
+02394 <font class="comment">// Now, _ULNVerticesToUpdate should be &lt;=0. (most of the time &lt; 0)</font>
+02395 }
+02396
+02397
+02398 <font class="comment">// ***************************************************************************</font>
+<a name="l02399"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z886_2">02399</a> <font class="keywordtype">void</font> CVegetableManager::setUpdateLightingFrequency(<font class="keywordtype">float</font> freq)
+02400 {
+02401 freq= max(freq, 0.f);
+02402 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_6">_ULFrequency</a>= freq;
+02403 }
+02404
+02405
+02406 <font class="comment">// ***************************************************************************</font>
+<a name="l02407"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z891_1">02407</a> <font class="keywordtype">bool</font> CVegetableManager::updateLightingIGPart()
+02408 {
+02409 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>);
+02410
+02411
+02412 <font class="comment">// First, update lighting info global to the ig, ie update current </font>
+02413 <font class="comment">// colros of the PointLights which influence the ig.</font>
+02414 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>-&gt;VegetableLightEx.computeCurrentColors();
+02415
+02416 <font class="comment">// while there is some vertices to update</font>
+02417 <font class="keywordflow">while</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_7">_ULNVerticesToUpdate</a>&gt;0)
+02418 {
+02419 <font class="comment">// if all rdrPass of the ig are processed.</font>
+02420 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>&gt;= <a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>)
+02421 {
+02422 <font class="comment">// All this Ig is updated.</font>
+02423 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>= 0;
+02424 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>= 0;
+02425 <font class="comment">// skip to next Ig.</font>
+02426 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+02427 }
+02428 CVegetableInstanceGroup::CVegetableRdrPass &amp;vegetRdrPass= <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>-&gt;_RdrPass[<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>];
+02429
+02430 <font class="comment">// if all instances are processed for this pass (especially if size()==0 !!)</font>
+02431 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>&gt;= vegetRdrPass.LightedInstances.size())
+02432 {
+02433 <font class="comment">// skip to the next rdrPass.</font>
+02434 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>++;
+02435 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>= 0;
+02436 <font class="keywordflow">continue</font>;
+02437 }
+02438
+02439 <font class="comment">// Process this instance.</font>
+02440 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_7">_ULNVerticesToUpdate</a>-= <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_2">updateInstanceLighting</a>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>, <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>, <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>);
+02441
+02442 <font class="comment">// next instance.</font>
+02443 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>++;
+02444
+02445 <font class="comment">// if all instances are processed for this pass</font>
+02446 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>&gt;= vegetRdrPass.LightedInstances.size())
+02447 {
+02448 <font class="comment">// skip to the next rdrPass.</font>
+02449 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>++;
+02450 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>= 0;
+02451 }
+02452 }
+02453
+02454 <font class="comment">// If all rdrPass of the ig are processed.</font>
+02455 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>&gt;= <a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>)
+02456 {
+02457 <font class="comment">// All this Ig is updated.</font>
+02458 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_10">_ULCurrentIgRdrPass</a>= 0;
+02459 <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_11">_ULCurrentIgInstance</a>= 0;
+02460 <font class="comment">// skip to next Ig.</font>
+02461 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+02462 }
+02463 <font class="keywordflow">else</font>
+02464 {
+02465 <font class="comment">// The Ig is not entirely updated.</font>
+02466 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+02467 }
+02468
+02469 }
+02470
+02471
+02472 <font class="comment">// ***************************************************************************</font>
+<a name="l02473"></a><a class="code" href="classNL3D_1_1CVegetableManager.html#z891_2">02473</a> uint CVegetableManager::updateInstanceLighting(CVegetableInstanceGroup *ig, uint rdrPassId, uint instanceId)
+02474 {
+02475 <a class="code" href="debug_8h.html#a6">nlassert</a>(ig);
+02476 <font class="comment">// get the rdrPass.</font>
+02477 <a class="code" href="debug_8h.html#a6">nlassert</a>(rdrPassId&lt;<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>);
+02478 CVegetableInstanceGroup::CVegetableRdrPass &amp;vegetRdrPass= ig-&gt;_RdrPass[rdrPassId];
+02479 <font class="comment">// get the lighted instance.</font>
+02480 <a class="code" href="debug_8h.html#a6">nlassert</a>(instanceId&lt;vegetRdrPass.LightedInstances.size());
+02481 CVegetableInstanceGroup::CVegetableLightedInstance &amp;vegetLI= vegetRdrPass.LightedInstances[instanceId];
+02482
+02483 <font class="comment">// get the shape</font>
+02484 CVegetableShape *shape= vegetLI.Shape;
+02485 <font class="comment">// it must be lighted.</font>
+02486 <a class="code" href="debug_8h.html#a6">nlassert</a>(shape-&gt;Lighted);
+02487 <font class="keywordtype">bool</font> instanceLighted= <font class="keyword">true</font>;
+02488
+02489
+02490 <font class="comment">// get ref on the vegetLex.</font>
+02491 CVegetableLightEx &amp;vegetLex= ig-&gt;VegetableLightEx;
+02492 <font class="comment">// Color of pointLights modulated by diffuse.</font>
+02493 CRGBA diffusePL[2];
+02494 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=1)
+02495 {
+02496 diffusePL[0].modulateFromColorRGBOnly(vegetLI.MatDiffuse, vegetLex.Color[0]);
+02497 <font class="keywordflow">if</font>(vegetLex.NumLights&gt;=2)
+02498 {
+02499 diffusePL[1].modulateFromColorRGBOnly(vegetLI.MatDiffuse, vegetLex.Color[1]);
+02500 }
+02501 }
+02502
+02503 <font class="comment">// Recompute lighting</font>
+02504 <font class="comment">//===========</font>
+02505
+02506 <font class="comment">// setup for this instance.</font>
+02507 <font class="comment">//---------</font>
+02508 <font class="comment">// 2Sided</font>
+02509 <font class="keywordtype">bool</font> instanceDoubleSided= shape-&gt;DoubleSided;
+02510 <font class="comment">// Precompute lighting or not??</font>
+02511 <font class="keywordtype">bool</font> precomputeLighting= instanceLighted &amp;&amp; shape-&gt;PreComputeLighting;
+02512 <font class="comment">// bestSided Precompute lighting or not??</font>
+02513 <font class="keywordtype">bool</font> bestSidedPrecomputeLighting= precomputeLighting &amp;&amp; shape-&gt;BestSidedPreComputeLighting;
+02514 <font class="comment">// destLighted?</font>
+02515 <font class="keywordtype">bool</font> destLighted= instanceLighted &amp;&amp; !shape-&gt;PreComputeLighting;
+02516 <font class="comment">// Diffuse and ambient, modulated by current GlobalAmbient and GlobalDiffuse.</font>
+02517 CRGBA primaryRGBA, secondaryRGBA;
+02518 primaryRGBA.modulateFromColorRGBOnly(vegetLI.MatDiffuse, <a class="code" href="classNL3D_1_1CVegetableManager.html#o12">_GlobalDiffuse</a>);
+02519 secondaryRGBA.modulateFromColorRGBOnly(vegetLI.MatAmbient, <a class="code" href="classNL3D_1_1CVegetableManager.html#o11">_GlobalAmbient</a>);
+02520 <font class="comment">// get normal matrix</font>
+02521 CMatrix &amp;normalMat= vegetLI.NormalMat;
+02522 <font class="comment">// array of vertex id to update</font>
+02523 uint32 *ptrVid= vegetRdrPass.Vertices.getPtr() + vegetLI.StartIdInRdrPass;
+02524 uint numVertices= shape-&gt;InstanceVertices.size();
+02525
+02526 <font class="comment">// Copy Dynamic Lightmap UV in Alpha part (save memory for an extra cost of 1 VP instruction)</font>
+02527 primaryRGBA.A= vegetLI.DlmUV.U;
+02528 secondaryRGBA.A= vegetLI.DlmUV.V;
+02529
+02530
+02531 <font class="comment">// get VertexBuffer info.</font>
+02532 CVegetableVBAllocator *allocator;
+02533 allocator= &amp;<a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPassId, vegetRdrPass.HardMode);
+02534 <font class="keyword">const</font> CVertexBuffer &amp;dstVBInfo= allocator-&gt;getSoftwareVertexBuffer();
+02535
+02536 uint srcNormalOff= (instanceLighted? shape-&gt;VB.getNormalOff() : 0);
+02537
+02538 <font class="comment">// got 2nd color if really lighted (for ambient) or if 2Sided.</font>
+02539 uint dstColor1Off= ( (destLighted||instanceDoubleSided)?
+02540 dstVBInfo.getValueOffEx(<a class="code" href="vegetablevb__allocator_8h.html#a3">NL3D_VEGETABLE_VPPOS_COLOR1</a>) : 0);
+02541 uint dstColor0Off= dstVBInfo.getValueOffEx(<a class="code" href="vegetablevb__allocator_8h.html#a2">NL3D_VEGETABLE_VPPOS_COLOR0</a>);
+02542
+02543
+02544
+02545 <font class="comment">// For all vertices, recompute lighting.</font>
+02546 <font class="comment">//---------</font>
+02547 <font class="keywordflow">for</font>(sint i=0; i&lt;(sint)numVertices;i++)
+02548 {
+02549 <font class="comment">// get the Vertex in the VB.</font>
+02550 uint vid= ptrVid[i];
+02551 <font class="comment">// store in tmp shape.</font>
+02552 shape-&gt;InstanceVertices[i]= vid;
+02553
+02554 <font class="comment">// Fill this vertex.</font>
+02555 uint8 *srcPtr= (uint8*)shape-&gt;VB.getVertexCoordPointer(i);
+02556 uint8 *dstPtr= (uint8*)allocator-&gt;getVertexPointer(vid);
+02557
+02558
+02559 <font class="comment">// if !precomputeLighting (means destLighted...)</font>
+02560 <font class="keywordflow">if</font>(!precomputeLighting)
+02561 {
+02562 <font class="comment">// just copy the primary and secondary color</font>
+02563 *(CRGBA*)(dstPtr + dstColor0Off)= primaryRGBA;
+02564 *(CRGBA*)(dstPtr + dstColor1Off)= secondaryRGBA;
+02565 }
+02566 <font class="keywordflow">else</font>
+02567 {
+02568 <a class="code" href="debug_8h.html#a6">nlassert</a>(!destLighted);
+02569
+02570 <font class="comment">// compute normal.</font>
+02571 CVector rotNormal= normalMat.mulVector( *(CVector*)(srcPtr + srcNormalOff) );
+02572 <font class="comment">// must normalize() because scale is possible.</font>
+02573 rotNormal.normalize();
+02574
+02575 <font class="comment">// Do the compute.</font>
+02576 <font class="keywordflow">if</font>(!bestSidedPrecomputeLighting)
+02577 {
+02578 <a class="code" href="namespaceNL3D.html#a473">computeVegetVertexLighting</a>(rotNormal, instanceDoubleSided,
+02579 <a class="code" href="classNL3D_1_1CVegetableManager.html#o10">_DirectionalLight</a>, primaryRGBA, secondaryRGBA,
+02580 vegetLex, diffusePL,
+02581 (CRGBA*)(dstPtr + dstColor0Off), (CRGBA*)(dstPtr + dstColor1Off) );
+02582 }
+02583 <font class="keywordflow">else</font>
+02584 {
+02585 <a class="code" href="namespaceNL3D.html#a474">computeVegetVertexLightingForceBestSided</a>(rotNormal, instanceDoubleSided,
+02586 <a class="code" href="classNL3D_1_1CVegetableManager.html#o10">_DirectionalLight</a>, primaryRGBA, secondaryRGBA,
+02587 vegetLex, diffusePL,
+02588 (CRGBA*)(dstPtr + dstColor0Off), (CRGBA*)(dstPtr + dstColor1Off) );
+02589 }
+02590
+02591 }
+02592
+02593 <font class="comment">// flust the vertex in AGP.</font>
+02594 allocator-&gt;flushVertex(vid);
+02595 }
+02596
+02597
+02598 <font class="comment">// numVertices vertices are updated</font>
+02599 <font class="keywordflow">return</font> numVertices;
+02600 }
+02601
+02602
+02603 } <font class="comment">// NL3D</font>
+</pre></div>
+
+<!-- footer -->
+<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>