aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/meshvp__per__pixel__light_8cpp-source.html
blob: dc5eb7eedc577c6d6e4a92b9ba9500ceddd49de3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<!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="/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="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/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="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/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="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/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="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/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="/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:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>meshvp_per_pixel_light.cpp</h1><a href="meshvp__per__pixel__light_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2000-2002 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025 
00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
00027 
00028 <font class="preprocessor">#include "<a class="code" href="meshvp__per__pixel__light_8h.html">3d/meshvp_per_pixel_light.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="mesh__base__instance_8h.html">3d/mesh_base_instance.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="scene_8h.html">3d/scene.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="render__trav_8h.html">3d/render_trav.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="render__trav_8h.html">3d/render_trav.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="vertex__program__parse_8h.html">3d/vertex_program_parse.h</a>"</font>
00035 
00036 
00037 
00038 <font class="preprocessor">#include &lt;string&gt;</font>
00039 
00040 
00041 
00042 <font class="keyword">namespace </font>NL3D 
00043 {
<a name="l00044"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#r0">00044</a> std::auto_ptr&lt;CVertexProgram&gt;   CMeshVPPerPixelLight::_VertexProgram[NumVp];
00045 
00046 <font class="comment">// ***************************************************************************</font>
00047 <font class="comment">// Light VP fragment constants start at 24</font>
00048 <font class="keyword">static</font>  <font class="keyword">const</font> uint      VPLightConstantStart = 24;
00049 
00050 
00051 
00052 <font class="comment">// ***************************************************************************</font>
00053 <font class="comment">// ***************************************************************************</font>
00054 
00056 <font class="comment">// omni lights //</font>
00058 <font class="comment"></font>
00064 <font class="comment"></font><font class="comment">// omni light + specular, no normalization</font>
00065 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a146">PPLightingVPCodeBegin</a> =
00066 <font class="stringliteral">"!!VP1.0                                                                                                                                                                \n\</font>
00067 <font class="stringliteral">#compute B = N ^ T                                                                                                                                              \n\</font>
00068 <font class="stringliteral">MOV R6, v[2];                                                                                                                                                   \n\</font>
00069 <font class="stringliteral">MUL R1, R6.yzxw, v[9].zxyw;                                                                                                                             \n\</font>
00070 <font class="stringliteral">MAD R1, v[9].yzxw, -R6.zxyw, R1;                                                                                                                \n\</font>
00071 <font class="stringliteral">#vector in tangent space = [ T B N ] * L                                                                                                \n\</font>
00072 <font class="stringliteral">ADD R2, c[4], -v[0];                       # compute L                                                                                  \n\</font>
00073 <font class="stringliteral">DP3 R3, R2, R2;                                    # get L normalized                                                                   \n\</font>
00074 <font class="stringliteral">RSQ R3, R3.x;                                                                                                                                                   \n\</font>
00075 <font class="stringliteral">MUL R2, R3, R2;                                                                                                                                                 \n\</font>
00076 <font class="stringliteral">DP3 o[TEX0].x, v[9], R2;                   # get x of light vector in tangent space             \n\</font>
00077 <font class="stringliteral">DP3 o[TEX0].y, R1, R2;             # get y                                                                                              \n\</font>
00078 <font class="stringliteral">DP3 o[TEX0].z, R6, R2;                     # get z                                                                                              \n\</font>
00079 <font class="stringliteral">#specular part                                                                                                                                                  \n\</font>
00080 <font class="stringliteral">ADD R3, c[5], - v[0];                      # compute V (return to eye)                                                  \n\</font>
00081 <font class="stringliteral">#compute inverse norm of V                                                                                                                              \n\</font>
00082 <font class="stringliteral">DP3 R4, R3, R3;                                                                                                                                                 \n\</font>
00083 <font class="stringliteral">RSQ R4, R4.x;                                                                                                                                                   \n\</font>
00084 <font class="stringliteral">#we normalize V and add it to L                                                                                                                 \n\</font>
00085 <font class="stringliteral">MAD R2, R4, R3, R2; #H in R1                                                                                                                    \n\</font>
00086 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00087 <font class="stringliteral">#normalize H                                                                                                                                                    \n\</font>
00088 <font class="stringliteral">DP3 R3, R2, R2;                                                                                                                                                 \n\</font>
00089 <font class="stringliteral">RSQ R3, R3.x;                                                                                                                                                   \n\</font>
00090 <font class="stringliteral">MUL R2, R3, R2;                                                                                                                                                 \n\</font>
00091 <font class="stringliteral">#compute H in tangent space                                                                                                                             \n\</font>
00092 <font class="stringliteral">DP3 o[TEX2].x, v[9], R2;                                                                                                                                \n\</font>
00093 <font class="stringliteral">DP3 o[TEX2].y, R1, R2;                                                                                                                                  \n\</font>
00094 <font class="stringliteral">DP3 o[TEX2].z, R6, R2;                                                                                                                                  \n\</font>
00095 <font class="stringliteral"># Position in R5 for additionnal lighting                                               \n\</font>
00096 <font class="stringliteral">MOV R5, v[0];                                                                                                                                                   \n\</font>
00097 <font class="stringliteral"># Normal is in R6 for additionnal lighting                                                                                              \n\</font>
00098 <font class="stringliteral">"</font>;
00099 
00101 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a147">PPLightingVPNormalizeCodeBegin</a> =
00102 <font class="stringliteral">"!!VP1.0                                                                                                                                                                \n\</font>
00103 <font class="stringliteral">#normalize the normal                                                                                                                                   \n\</font>
00104 <font class="stringliteral">DP3 R1, v[2], v[2];                                                                                                                                             \n\</font>
00105 <font class="stringliteral">RSQ R1, R1.x;                                                                                                                                                   \n\</font>
00106 <font class="stringliteral">MUL R6, v[2], R1;                                                                                                                                                       \n\</font>
00107 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00108 <font class="stringliteral">#normalize the second vector                                                                                                                    \n\</font>
00109 <font class="stringliteral">DP3     R1, R6, v[9];                                                                                                                                           \n\</font>
00110 <font class="stringliteral">MAD     R1, R6, -R1, v[9]; #subtract the normal component                                                                       \n\</font>
00111 <font class="stringliteral">DP3 R2, R1, R1;                                                                                                                                                 \n\</font>
00112 <font class="stringliteral">RSQ     R2, R2.x;                                                                                                                                                       \n\</font>
00113 <font class="stringliteral">MUL R5, R1, R2; #second basis vector in R5                                                                                              \n\</font>
00114 <font class="stringliteral">#compute B = N ^ T                                                                                                                                              \n\</font>
00115 <font class="stringliteral">MUL R1, R6.yzxw, R5.zxyw;                                                                                                                               \n\</font>
00116 <font class="stringliteral">MAD R1, R5.yzxw, -R6.zxyw, R1; #third basis vector in R1                                                                \n\</font>
00117 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00118 <font class="stringliteral">#vector in tangent space = [ T B N ] * L                                                                                                \n\</font>
00119 <font class="stringliteral">ADD R2, c[4], -v[0];                       # compute L                                                                                  \n\</font>
00120 <font class="stringliteral">DP3 R3, R2, R2;                                    # get L normalized                                                                   \n\</font>
00121 <font class="stringliteral">RSQ R3, R3.x;                                                                                                                                                   \n\</font>
00122 <font class="stringliteral">MUL R2, R3, R2;                                                                                                                                                 \n\</font>
00123 <font class="stringliteral">DP3 o[TEX0].x, R5, R2;                     # get x of light vector in tangent space                             \n\</font>
00124 <font class="stringliteral">DP3 o[TEX0].y, R1, R2;             # get y                                                                                              \n\</font>
00125 <font class="stringliteral">DP3 o[TEX0].z, R6, R2;                     # get z                                                                                              \n\</font>
00126 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00127 <font class="stringliteral">#specular part                                                                                                                                                  \n\</font>
00128 <font class="stringliteral">ADD R3, c[5], - v[0];                      # compute V (return to eye)                                                  \n\</font>
00129 <font class="stringliteral">#compute inverse norm of V                                                                                                                              \n\</font>
00130 <font class="stringliteral">DP3 R4, R3, R3;                                                                                                                                                 \n\</font>
00131 <font class="stringliteral">RSQ R4, R4.x;                                                                                                                                                   \n\</font>
00132 <font class="stringliteral">#we normalize V and add it to L                                                                                                                 \n\</font>
00133 <font class="stringliteral">MAD R2, R4, R3, R2; #H in R1                                                                                                                    \n\</font>
00134 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00135 <font class="stringliteral">#normalize H                                                                                                                                                    \n\</font>
00136 <font class="stringliteral">DP3 R3, R2, R2;                                                                                                                                                 \n\</font>
00137 <font class="stringliteral">RSQ R3, R3.x;                                                                                                                                                   \n\</font>
00138 <font class="stringliteral">MUL R2, R3, R2;                                                                                                                                                 \n\</font>
00139 <font class="stringliteral">#compute H in tangent space                                                                                                                             \n\</font>
00140 <font class="stringliteral">DP3 o[TEX2].x, R5, R2;                                                                                                                                  \n\</font>
00141 <font class="stringliteral">DP3 o[TEX2].y, R1, R2;                                                                                                                                  \n\</font>
00142 <font class="stringliteral">DP3 o[TEX2].z, R6, R2;                                                                                                                                  \n\</font>
00143 <font class="stringliteral"># Position in R5 for additionnal lighting                                               \n\</font>
00144 <font class="stringliteral">MOV R5, v[0];                                                                                                                                                   \n\</font>
00145 <font class="stringliteral"># Normal is in R6 for additionnal lighting                                                                                              \n\</font>
00146 <font class="stringliteral">"</font>;
00147 
00148 
00149 <font class="comment">// Omni light, no specular</font>
00150 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a148">PPLightingNoSpecVPCodeBegin</a> =
00151 <font class="stringliteral">"!!VP1.0                                                                                                                                                                \n\</font>
00152 <font class="stringliteral">#compute B = N ^ T                                                                                                                                              \n\</font>
00153 <font class="stringliteral">MOV R6, v[2];                                                                                                                                                   \n\</font>
00154 <font class="stringliteral">MUL R1, R6.yzxw, v[9].zxyw;                                                                                                                             \n\</font>
00155 <font class="stringliteral">MAD R1, v[9].yzxw, -R6.zxyw, R1;                                                                                                                \n\</font>
00156 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00157 <font class="stringliteral">#vector in tangent space = [ T B N ] * L                                                                                                \n\</font>
00158 <font class="stringliteral">ADD R2, c[4], -v[0];                       # compute L                                                                                  \n\</font>
00159 <font class="stringliteral">DP3 R3, R2, R2;                                    # get L normalized                                                                   \n\</font>
00160 <font class="stringliteral">RSQ R3, R3.x;                                                                                                                                                   \n\</font>
00161 <font class="stringliteral">MUL R2, R3, R2;                                                                                                                                                 \n\</font>
00162 <font class="stringliteral">DP3 o[TEX0].x, v[9], R2;                   # get x of light vector in tangent space             \n\</font>
00163 <font class="stringliteral">DP3 o[TEX0].y, R1, R2;             # get y                                                                                              \n\</font>
00164 <font class="stringliteral">DP3 o[TEX0].z, R6, R2;                     # get z                                                                                              \n\</font>
00165 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00166 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00167 <font class="stringliteral"># Normal is in R6 for additionnal lighting                                                                                              \n\</font>
00168 <font class="stringliteral"># Position in R5 for additionnal lighting                                               \n\</font>
00169 <font class="stringliteral">MOV R5, v[0];                                                                                                                                                   \n\</font>
00170 <font class="stringliteral">"</font>;
00171 
00173 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a149">PPLightingVPNormalizeNoSpecCodeBegin</a> =
00174 <font class="stringliteral">"!!VP1.0                                                                                                                                                                \n\</font>
00175 <font class="stringliteral">#normalize the normal                                                                                                                                   \n\</font>
00176 <font class="stringliteral">DP3 R1, v[2], v[2];                                                                                                                                             \n\</font>
00177 <font class="stringliteral">RSQ R1, R1.x;                                                                                                                                                   \n\</font>
00178 <font class="stringliteral">MUL R6, v[2], R1;                                                                                                                                                       \n\</font>
00179 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00180 <font class="stringliteral">#normalize the second vector                                                                                                                    \n\</font>
00181 <font class="stringliteral">DP3     R1, R6, v[9];                                                                                                                                           \n\</font>
00182 <font class="stringliteral">MAD     R1, R6, -R1, v[9]; #subtract the normal component                                                                       \n\</font>
00183 <font class="stringliteral">DP3 R2, R1, R1;                                                                                                                                                 \n\</font>
00184 <font class="stringliteral">RSQ     R2, R2.x;                                                                                                                                                       \n\</font>
00185 <font class="stringliteral">MUL R5, R1, R2; #second basis vector in R5                                                                                              \n\</font>
00186 <font class="stringliteral">#compute B = N ^ T                                                                                                                                              \n\</font>
00187 <font class="stringliteral">MUL R1, R6.yzxw, R5.zxyw;                                                                                                                               \n\</font>
00188 <font class="stringliteral">MAD R1, R5.yzxw, -R6.zxyw, R1; #third basis vector in R1                                                                \n\</font>
00189 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00190 <font class="stringliteral">#vector in tangent space = [ T B N ] * L                                                                                                \n\</font>
00191 <font class="stringliteral">ADD R2, c[4], -v[0];                       # compute L                                                                                  \n\</font>
00192 <font class="stringliteral">DP3 R3, R2, R2;                                    # get L normalized                                                                   \n\</font>
00193 <font class="stringliteral">RSQ R3, R3.x;                                                                                                                                                   \n\</font>
00194 <font class="stringliteral">MUL R2, R3, R2;                                                                                                                                                 \n\</font>
00195 <font class="stringliteral">DP3 o[TEX0].x, R5, R2;                     # get x of light vector in tangent space                             \n\</font>
00196 <font class="stringliteral">DP3 o[TEX0].y, R1, R2;             # get y                                                                                              \n\</font>
00197 <font class="stringliteral">DP3 o[TEX0].z, R6, R2;                     # get z                                                                                              \n\</font>
00198 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00199 <font class="stringliteral"># Normal is in R6 for additionnal lighting                                                                                              \n\</font>
00200 <font class="stringliteral"># Position in R5 for additionnal lighting                                               \n\</font>
00201 <font class="stringliteral">MOV R5, v[0];                                                                                                                                                   \n\</font>
00202 <font class="stringliteral">"</font>;
00203 
00204 
00206 <font class="comment">// directionnal lights //</font>
00208 <font class="comment"></font>
00211 <font class="comment"></font>
00212 <font class="comment">// directionnal, no normalization</font>
00213 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a150">PPLightingDirectionnalVPCodeBegin</a> =
00214 <font class="stringliteral">"!!VP1.0                                                                                                                                                                \n\</font>
00215 <font class="stringliteral">#compute B = N ^ T                                                                                                                                              \n\</font>
00216 <font class="stringliteral">MOV R6, v[2];                                                                                                                                                   \n\</font>
00217 <font class="stringliteral">MUL R1, R6.yzxw, v[9].zxyw;                                                                                                                             \n\</font>
00218 <font class="stringliteral">MAD R1, v[9].yzxw, -R6.zxyw, R1;                                                                                                                \n\</font>
00219 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00220 <font class="stringliteral">#vector in tangent space = [ T B N ] * L                                                                                                \n\</font>
00221 <font class="stringliteral">DP3 o[TEX0].x, v[9], -c[4];                # get x of light vector in tangent space             \n\</font>
00222 <font class="stringliteral">DP3 o[TEX0].y, R1, -c[4];           # get y                                                                                             \n\</font>
00223 <font class="stringliteral">DP3 o[TEX0].z, R6, -c[4];                  # get z                                                                                              \n\</font>
00224 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00225 <font class="stringliteral">#specular part                                                                                                                                                  \n\</font>
00226 <font class="stringliteral">ADD R3, c[5], - v[0];                      # compute V (return to eye)                                                  \n\</font>
00227 <font class="stringliteral">#compute inverse norm of V                                                                                                                              \n\</font>
00228 <font class="stringliteral">DP3 R4, R3, R3;                                                                                                                                                 \n\</font>
00229 <font class="stringliteral">RSQ R4, R4.x;                                                                                                                                                   \n\</font>
00230 <font class="stringliteral">#we normalize V and add it to L. It gives H unnormalized                                                                \n\</font>
00231 <font class="stringliteral">MAD R2, R4, R3, -c[4]; #H in R1                                                                                                                 \n\</font>
00232 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00233 <font class="stringliteral">#normalize H                                                                                                                                                    \n\</font>
00234 <font class="stringliteral">DP3 R3, R2, R2;                                                                                                                                                 \n\</font>
00235 <font class="stringliteral">RSQ R3, R3.x;                                                                                                                                                   \n\</font>
00236 <font class="stringliteral">MUL R2, R3, R2;                                                                                                                                                 \n\</font>
00237 <font class="stringliteral">#compute H in tangent space                                                                                                                             \n\</font>
00238 <font class="stringliteral">DP3 o[TEX2].x, v[9], R2;                                                                                                                                \n\</font>
00239 <font class="stringliteral">DP3 o[TEX2].y, R1, R2;                                                                                                                                  \n\</font>
00240 <font class="stringliteral">DP3 o[TEX2].z, R6, R2;                                                                                                                                  \n\</font>
00241 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00242 <font class="stringliteral"># Normal is in R6 for additionnal lighting                                                                                              \n\</font>
00243 <font class="stringliteral"># Position in R5 for additionnal lighting                                               \n\</font>
00244 <font class="stringliteral">MOV R5, v[0];                                                                                                                                                   \n\</font>
00245 <font class="stringliteral">"</font>;
00246 
00247 <font class="comment">// directionnal + normalization</font>
00248 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a151">PPLightingDirectionnalVPNormalizeCodeBegin</a> =
00249 <font class="stringliteral">"!!VP1.0                                                                                                                                                                \n\</font>
00250 <font class="stringliteral">#normalize the normal                                                                                                                                   \n\</font>
00251 <font class="stringliteral">DP3 R1, v[2], v[2];                                                                                                                                             \n\</font>
00252 <font class="stringliteral">RSQ R1, R1.x;                                                                                                                                                   \n\</font>
00253 <font class="stringliteral">MUL R6, v[2], R1;                                                                                                                                               \n\</font>
00254 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00255 <font class="stringliteral">#normalize the second vector                                                                                                                    \n\</font>
00256 <font class="stringliteral">DP3     R1, R6, v[9];                                                                                                                                           \n\</font>
00257 <font class="stringliteral">MAD     R1, R6, -R1, v[9]; #subtract the normal component                                                                       \n\</font>
00258 <font class="stringliteral">DP3 R2, R1, R1;                                                                                                                                                 \n\</font>
00259 <font class="stringliteral">RSQ     R2, R2.x;                                                                                                                                                       \n\</font>
00260 <font class="stringliteral">MUL R5, R1, R2; #second basis vector in R5                                                                                              \n\</font>
00261 <font class="stringliteral">#compute B = N ^ T                                                                                                                                              \n\</font>
00262 <font class="stringliteral">MUL R1, R6.yzxw, R5.zxyw;                                                                                                                               \n\</font>
00263 <font class="stringliteral">MAD R1, R5.yzxw, -R6.zxyw, R1; #third basis vector in R1                                                                \n\</font>
00264 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00265 <font class="stringliteral">#vector in tangent space = [ T B N ] * L                                                                                                \n\</font>
00266 <font class="stringliteral">DP3 o[TEX0].x, R5, -c[4];                          # get x of light vector in tangent space                     \n\</font>
00267 <font class="stringliteral">DP3 o[TEX0].y, R1, -c[4];               # get y                                                                                 \n\</font>
00268 <font class="stringliteral">DP3 o[TEX0].z, R6, -c[4];                          # get z                                                                                      \n\</font>
00269 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00270 <font class="stringliteral">#specular part                                                                                                                                                  \n\</font>
00271 <font class="stringliteral">ADD R3, c[5], - v[0];                      # compute V (return to eye)                                                  \n\</font>
00272 <font class="stringliteral">#compute inverse norm of V                                                                                                                              \n\</font>
00273 <font class="stringliteral">DP3 R4, R3, R3;                                                                                                                                                 \n\</font>
00274 <font class="stringliteral">RSQ R4, R4.x;                                                                                                                                                   \n\</font>
00275 <font class="stringliteral">#we normalize V and add it to L                                                                                                                 \n\</font>
00276 <font class="stringliteral">MAD R2, R4, R3, -c[4]; #H in R1                                                                                                                 \n\</font>
00277 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00278 <font class="stringliteral">#normalize H                                                                                                                                                    \n\</font>
00279 <font class="stringliteral">DP3 R3, R2, R2;                                                                                                                                                 \n\</font>
00280 <font class="stringliteral">RSQ R3, R3.x;                                                                                                                                                   \n\</font>
00281 <font class="stringliteral">MUL R2, R3, R2;                                                                                                                                                 \n\</font>
00282 <font class="stringliteral">#compute H in tangent space                                                                                                                             \n\</font>
00283 <font class="stringliteral">DP3 o[TEX2].x, R5, R2;                                                                                                                                  \n\</font>
00284 <font class="stringliteral">DP3 o[TEX2].y, R1, R2;                                                                                                                                  \n\</font>
00285 <font class="stringliteral">DP3 o[TEX2].z, R6, R2;                                                                                                                                  \n\</font>
00286 <font class="stringliteral"># Normal is in R6 for additionnal lighting                                                                                              \n\</font>
00287 <font class="stringliteral"># Position in R5 for additionnal lighting                                               \n\</font>
00288 <font class="stringliteral">MOV R5, v[0];                                                                                                                                                   \n\</font>
00289 <font class="stringliteral">"</font>;
00290 
00291 
00292 <font class="comment">// directionnal, no normalization, no specular</font>
00293 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a152">PPLightingDirectionnalNoSpecVPCodeBegin</a> =
00294 <font class="stringliteral">"!!VP1.0                                                                                                                                                                \n\</font>
00295 <font class="stringliteral">#compute B = N ^ T                                                                                                                                              \n\</font>
00296 <font class="stringliteral">MOV R6, v[2];                                                                                                                                                   \n\</font>
00297 <font class="stringliteral">MUL R1, R6.yzxw, v[9].zxyw;                                                                                                                             \n\</font>
00298 <font class="stringliteral">MAD R1, v[9].yzxw, -R6.zxyw, R1;                                                                                                                \n\</font>
00299 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00300 <font class="stringliteral">#vector in tangent space = [ T B N ] * L                                                                                                \n\</font>
00301 <font class="stringliteral">DP3 o[TEX0].x, v[9], -c[4];                # get x of light vector in tangent space             \n\</font>
00302 <font class="stringliteral">DP3 o[TEX0].y, R1, -c[4];           # get y                                                                                             \n\</font>
00303 <font class="stringliteral">DP3 o[TEX0].z, R6, -c[4];                  # get z                                                                                              \n\</font>
00304 <font class="stringliteral"># Normal is in R6 for additionnal lighting                                                                                              \n\</font>
00305 <font class="stringliteral"># Position in R5 for additionnal lighting                                               \n\</font>
00306 <font class="stringliteral">MOV R5, v[0];                                                                                                                                                   \n\</font>
00307 <font class="stringliteral">"</font>;
00308 
00309 <font class="comment">// directionnal + normalization, no specular</font>
00310 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a153">PPLightingDirectionnalNoSpecVPNormalizeCodeBegin</a> =
00311 <font class="stringliteral">"!!VP1.0                                                                                                                                                                \n\</font>
00312 <font class="stringliteral">#normalize the normal                                                                                                                                   \n\</font>
00313 <font class="stringliteral">DP3 R1, v[2], v[2];                                                                                                                                             \n\</font>
00314 <font class="stringliteral">RSQ R1, R1.x;                                                                                                                                                   \n\</font>
00315 <font class="stringliteral">MUL R6, v[2], R1;                                                                                                                                               \n\</font>
00316 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00317 <font class="stringliteral">#normalize the second vector                                                                                                                    \n\</font>
00318 <font class="stringliteral">DP3     R1, R6, v[9];                                                                                                                                           \n\</font>
00319 <font class="stringliteral">MAD     R1, R6, -R1, v[9]; #subtract the normal component                                                                       \n\</font>
00320 <font class="stringliteral">DP3 R2, R1, R1;                                                                                                                                                 \n\</font>
00321 <font class="stringliteral">RSQ     R2, R2.x;                                                                                                                                                       \n\</font>
00322 <font class="stringliteral">MUL R5, R1, R2; #second basis vector in R5                                                                                              \n\</font>
00323 <font class="stringliteral">#compute B = N ^ T                                                                                                                                              \n\</font>
00324 <font class="stringliteral">MUL R1, R6.yzxw, R5.zxyw;                                                                                                                               \n\</font>
00325 <font class="stringliteral">MAD R1, R5.yzxw, -R6.zxyw, R1; #third basis vector in R1                                                                \n\</font>
00326 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00327 <font class="stringliteral">#vector in tangent space = [ T B N ] * L                                                                                                \n\</font>
00328 <font class="stringliteral">DP3 o[TEX0].x, R5, -c[4];                          # get x of light vector in tangent space                     \n\</font>
00329 <font class="stringliteral">DP3 o[TEX0].y, R1, -c[4];               # get y                                                                                 \n\</font>
00330 <font class="stringliteral">DP3 o[TEX0].z, R6, -c[4];                          # get z                                                                                      \n\</font>
00331 <font class="stringliteral">                                                                                                                                                                                \n\</font>
00332 <font class="stringliteral"># Normal is in R6 for additionnal lighting                                                                                              \n\</font>
00333 <font class="stringliteral"># Position in R5 for additionnal lighting                                               \n\</font>
00334 <font class="stringliteral">MOV R5, v[0];                                                                                                                                                   \n\</font>
00335 <font class="stringliteral">"</font>;
00336 
00337 
00338 
00339 <font class="comment">// End of per pixel lighting code : compute pos and setup texture</font>
00340 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>*      <a class="code" href="namespaceNL3D.html#a154">PPLightingVPCodeEnd</a>=
00341 <font class="stringliteral">"       # compute in Projection space                                                                                                           \n\</font>
00342 <font class="stringliteral">        DP4 o[HPOS].x, c[0], v[0];                                                                                                                      \n\</font>
00343 <font class="stringliteral">        DP4 o[HPOS].y, c[1], v[0];                                                                                                                      \n\</font>
00344 <font class="stringliteral">        DP4 o[HPOS].z, c[2], v[0];                                                                                                                      \n\</font>
00345 <font class="stringliteral">        DP4 o[HPOS].w, c[3], v[0];                                                                                                                      \n\</font>
00346 <font class="stringliteral">        MOV o[TEX1].xy, v[8];                                                                                                                           \n\</font>
00347 <font class="stringliteral">        END                                                                                                                                                                     \n\</font>
00348 <font class="stringliteral">"</font>;
00349 
00350 <font class="comment">/***************************************************************/</font>
00351 <font class="comment">/******************* THE FOLLOWING CODE IS COMMENTED OUT *******/</font>
00352 <font class="comment">/***************************************************************</font>
00353 <font class="comment"></font>
00354 <font class="comment">// Test code : map the tangent space vector as the diffuse color</font>
00355 <font class="comment">static const char*      PPLightingVPCodeTest =</font>
00356 <font class="comment">"!!VP1.0                                                                                                                                                        \n\</font>
00357 <font class="comment"> # compute in Projection space                                                                                                          \n\</font>
00358 <font class="comment"> DP4 o[HPOS].x, c[0], v[0];                                                                                                                     \n\</font>
00359 <font class="comment"> DP4 o[HPOS].y, c[1], v[0];                                                                                                                     \n\</font>
00360 <font class="comment"> DP4 o[HPOS].z, c[2], v[0];                                                                                                                     \n\</font>
00361 <font class="comment"> DP4 o[HPOS].w, c[3], v[0];                                                                                                                     \n\</font>
00362 <font class="comment"> MOV o[COL0], v[9];                                                                                                                                     \n\</font>
00363 <font class="comment"> END                                                                                                                                                            \n\</font>
00364 <font class="comment">";</font>
00365 <font class="comment">***************************************************************/</font>
00366 
00367 
00368 
00369 
00370 <font class="comment">//=================================================================================</font>
<a name="l00371"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#z609_0">00371</a> <font class="keywordtype">void</font>    CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi)
00372 {
00373         <font class="comment">// init the vertexProgram code.</font>
00374         <font class="keyword">static</font>  <font class="keywordtype">bool</font>    vpCreated= <font class="keyword">false</font>;
00375         <font class="keywordflow">if</font>(!vpCreated)
00376         {
00377                 vpCreated= <font class="keyword">true</font>;                
00378 
00379                 <font class="comment">// Gives each vp name</font>
00380                 <font class="comment">// Bit 0 : 1 when it is a directionnal light</font>
00381                 <font class="comment">// Bit 1 : 1 when specular is needed</font>
00382                 <font class="comment">// Bit 2 : 1 when normalization of the tangent space is needed</font>
00383                 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font> *vpName[] =
00384                 {
00385                         <font class="comment">//  no spec</font>
00386                         <a class="code" href="namespaceNL3D.html#a152">PPLightingDirectionnalNoSpecVPCodeBegin</a>, 
00387                         <a class="code" href="namespaceNL3D.html#a148">PPLightingNoSpecVPCodeBegin</a>,
00388                         <font class="comment">// specular</font>
00389                         <a class="code" href="namespaceNL3D.html#a150">PPLightingDirectionnalVPCodeBegin</a>,
00390                         <a class="code" href="namespaceNL3D.html#a146">PPLightingVPCodeBegin</a>,                                                                  
00392                         <font class="comment">// no spec</font>
00393                         <a class="code" href="namespaceNL3D.html#a153">PPLightingDirectionnalNoSpecVPNormalizeCodeBegin</a>,
00394                         <a class="code" href="namespaceNL3D.html#a149">PPLightingVPNormalizeNoSpecCodeBegin</a>,
00395                         <font class="comment">// spec</font>
00396                         <a class="code" href="namespaceNL3D.html#a151">PPLightingDirectionnalVPNormalizeCodeBegin</a>,
00397                         <a class="code" href="namespaceNL3D.html#a147">PPLightingVPNormalizeCodeBegin</a>,                                         
00398                 };
00399 
00400                 uint numvp  = <font class="keyword">sizeof</font>(vpName) / <font class="keyword">sizeof</font>(<font class="keyword">const</font> <font class="keywordtype">char</font> *);
00401                 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#u1u0">NumVp</a> == numvp); <font class="comment">// make sure that it is in sync with header..todo : compile time assert :)</font>
00402                 <font class="keywordflow">for</font> (uint vp = 0; vp &lt; <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#u1u0">NumVp</a>; ++vp)
00403                 {
00404                         <font class="comment">// \todo yoyo TODO_OPTIM Manage different number of pointLights</font>
00405                         <font class="comment">// NB: never call getLightVPFragment() with normalize, because already done by PerPixel fragment before.</font>
00406                         std::string vpCode      = std::string(vpName[vp])
00407                                                                   + std::string(<font class="stringliteral">"# ***************"</font>) <font class="comment">// temp for debug</font>
00408                                                                   + CRenderTrav::getLightVPFragment(CRenderTrav::MaxVPLight-1, VPLightConstantStart, (vp &amp; 2) != 0, <font class="keyword">false</font>)
00409                                                                   + std::string(<font class="stringliteral">"# ***************"</font>) <font class="comment">// temp for debug</font>
00410                                                                   + std::string(<a class="code" href="namespaceNL3D.html#a154">PPLightingVPCodeEnd</a>);
00411 <font class="preprocessor">                        #ifdef NL_DEBUG</font>
00412 <font class="preprocessor"></font>
00417                                 <a class="code" href="classCVPParser.html">CVPParser</a>                       vpParser;
00418                                 <a class="code" href="classCVPParser.html#s0">CVPParser::TProgram</a> result;
00419                                 std::string          parseOutput;
00420                                 <font class="keywordflow">if</font> (!vpParser.<a class="code" href="classCVPParser.html#a0">parse</a>(vpCode.c_str(), result, parseOutput))
00421                                 {                                       
00422                                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(parseOutput.c_str());
00423                                         <a class="code" href="debug_8h.html#a6">nlassert</a>(0);
00424                                 }
00425 <font class="preprocessor">                        #endif</font>
00426 <font class="preprocessor"></font>                        <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#r0">_VertexProgram</a>[vp]= std::auto_ptr&lt;CVertexProgram&gt;(<font class="keyword">new</font> CVertexProgram(vpCode.c_str()));
00427                 }
00428                                 
00429         }
00430 }
00431 
00432 <font class="comment">//=================================================================================</font>
<a name="l00433"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#z609_1">00433</a> <font class="keywordtype">bool</font>    CMeshVPPerPixelLight::begin(IDriver *drv,
00434                                                                         CScene *scene, CMeshBaseInstance *mbi,
00435                                                                         <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> &amp;invertedModelMat,
00436                                                                         <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;viewerPos)
00437 {
00438         <font class="comment">// test if supported by driver</font>
00439         <font class="keywordflow">if</font> (!
00440                  (drv-&gt;isVertexProgramSupported() 
00441                   &amp;&amp; !drv-&gt;isVertexProgramEmulated()
00442                   &amp;&amp;  drv-&gt;supportPerPixelLighting(<a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#m0">SpecularLighting</a>)
00443                  )
00444            )
00445         {
00446                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00447         }
00448         <font class="comment">//                      </font>
00449         CRenderTrav             *renderTrav= scene-&gt;getRenderTrav();                    
00451         renderTrav-&gt;beginVPLightSetup(VPLightConstantStart,
00452                                                                   <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#m0">SpecularLighting</a>,
00453                                                                   invertedModelMat);
00454         <font class="comment">//</font>
00455         sint strongestLightIndex = renderTrav-&gt;getStrongestLightIndex();
00456         <font class="keywordflow">if</font> (strongestLightIndex == -1) <font class="keywordflow">return</font> <font class="keyword">false</font>; <font class="comment">// if no strongest light, disable this vertex program              </font>
00457         <font class="comment">// setup the strongest light</font>
00459 <font class="comment">        const CLight &amp;strongestLight  = renderTrav-&gt;getDriverLight(strongestLightIndex);</font>
00460 
00461         <font class="keywordflow">switch</font> (strongestLight.getMode())
00462         {
00463                 <font class="keywordflow">case</font> CLight::DirectionalLight:
00464                 {
00465                         <font class="comment">// put light direction in object space</font>
00466                         <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> lPos = invertedModelMat.<a class="code" href="classNLMISC_1_1CMatrix.html#z294_0">mulVector</a>(strongestLight.getDirection());
00467                         drv-&gt;setConstant(4, lPos);
00468                         <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#o1">_IsPointLight</a> = <font class="keyword">false</font>;
00469                 }
00470                 <font class="keywordflow">break</font>;
00471                 <font class="keywordflow">case</font> CLight::PointLight:
00472                 {
00473                         <font class="comment">// put light in object space</font>
00474                         <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> lPos = invertedModelMat * strongestLight.getPosition();
00475                         drv-&gt;setConstant(4, lPos);
00476                         <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#o1">_IsPointLight</a> = <font class="keyword">true</font>;
00477                 }
00478                 <font class="keywordflow">break</font>;
00479                 <font class="keywordflow">default</font>:
00480                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00481                 <font class="keywordflow">break</font>;
00482         }
00483                                 
00484         
00485         <font class="keywordflow">if</font> (SpecularLighting)
00486         {
00487                 <font class="comment">// viewer pos in object space</font>
00488                 <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> vPos = invertedModelMat * viewerPos;
00489                 drv-&gt;setConstant(5, vPos);
00490         }
00491                 
00492         <font class="comment">// c[0..3] take the ModelViewProjection Matrix. After setupModelMatrix();</font>
00493         drv-&gt;setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity);                     
00494         <font class="comment">//      </font>
00495         <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#c0">enable</a>(<font class="keyword">true</font>, drv); <font class="comment">// must enable the vertex program before the vb is activated</font>
00496         <font class="comment">//</font>
00497         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00498 }
00499 
00500 
00501 <font class="comment">//=================================================================================</font>
<a name="l00502"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#z609_2">00502</a> <font class="keywordtype">void</font>    CMeshVPPerPixelLight::end(IDriver *drv)
00503 {
00504         <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#c0">enable</a>(<font class="keyword">false</font>, drv);
00505 }
00506 
00507 
00508 <font class="comment">//=================================================================================</font>
<a name="l00509"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#z609_3">00509</a> <font class="keywordtype">void</font>    CMeshVPPerPixelLight::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f) <font class="keywordflow">throw</font>(NLMISC::EStream)
00510 {
00511         (void)f.serialVersion(0);
00512         f.serial(SpecularLighting);     
00513 }       
00514 
00515 
00516 <font class="comment">//=================================================================================</font>
<a name="l00517"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#c0">00517</a> <font class="keywordtype">void</font>    CMeshVPPerPixelLight::enable(<font class="keywordtype">bool</font> enabled, IDriver *drv)
00518 {
00519         <font class="keywordflow">if</font> (enabled != <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#o0">_Enabled</a>)
00520         {
00521                 <a class="code" href="debug_8h.html#a6">nlassert</a>(drv);
00522                 <font class="keywordflow">if</font> (enabled)
00523                 {
00524                         <font class="comment">/* for (uint k = 0; k &lt; NumVp; ++k)</font>
00525 <font class="comment">                        {</font>
00526 <font class="comment">                                nlinfo("test vp %d", k);</font>
00527 <font class="comment">                                drv-&gt;activeVertexProgram(_VertexProgram[k].get());</font>
00528 <font class="comment">                        } */</font>
00529                         uint    idVP =   (drv-&gt;isForceNormalize() ? 4 : 0) 
00530                                                    | (<a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#m0">SpecularLighting</a>        ? 2 : 0)
00531                                                    | (<a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#o1">_IsPointLight</a>                   ? 1 : 0);
00532                         <font class="comment">//</font>
00533                         drv-&gt;activeVertexProgram(<a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#r0">_VertexProgram</a>[idVP].get());
00534                 }
00535                 <font class="keywordflow">else</font>
00536                 {
00537                         drv-&gt;activeVertexProgram(NULL);
00538                 }
00539                 <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#o0">_Enabled</a> = enabled;
00540         }
00541 }
00542 
00543 <font class="comment">//=================================================================================</font>
<a name="l00544"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#c1">00544</a> <font class="keywordtype">bool</font>  CMeshVPPerPixelLight::setupForMaterial(<font class="keyword">const</font> CMaterial &amp;mat,
00545                                                                                          IDriver *drv,
00546                                                                                          CScene *scene
00547                                                                                         )
00548 {
00549         <font class="keywordtype">bool</font> enabled = (mat.getShader() == CMaterial::PerPixelLighting || mat.getShader() == CMaterial::PerPixelLightingNoSpec);
00550         <font class="keywordflow">if</font> (enabled)
00551         {
00552                 CRenderTrav             *renderTrav= scene-&gt;getRenderTrav();
00553                 renderTrav-&gt;changeVPLightSetupMaterial(mat, <font class="keyword">true</font> <font class="comment">/* exclude strongest*/</font>);               
00554 
00555                 <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> pplDiffuse, pplSpecular;          
00556                 renderTrav-&gt;getStrongestLightColors(pplDiffuse, pplSpecular);
00557                 drv-&gt;setPerPixelLightingLight(pplDiffuse, pplSpecular, mat.getShininess());
00558         }
00559         <font class="keywordtype">bool</font> change = (enabled != <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#o0">_Enabled</a>);
00560         <a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#c0">enable</a>(enabled, drv); <font class="comment">// enable disable the vertex program (for material that don't have the right shader)</font>
00561         <font class="keywordflow">return</font> change;
00562 }
00563 <font class="comment">//=================================================================================</font>
<a name="l00564"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#z609_4">00564</a> <font class="keywordtype">void</font>    CMeshVPPerPixelLight::setupForMaterial(<font class="keyword">const</font> CMaterial &amp;mat,
00565                                                                                            IDriver *drv,
00566                                                                                            CScene *scene,
00567                                                                                            CVertexBuffer *vb)
00568 {
00569         
00570         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#z609_4">setupForMaterial</a>(mat, drv, scene)) <font class="comment">// a switch from v.p enabled / disabled force to reactivate the vertex buffer.</font>
00571         {
00572                 drv-&gt;activeVertexBuffer(*vb);           
00573         }
00574 }
00575 
00576 <font class="comment">//=================================================================================</font>
<a name="l00577"></a><a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#z609_5">00577</a> <font class="keywordtype">void</font>    CMeshVPPerPixelLight::setupForMaterial(<font class="keyword">const</font> CMaterial &amp;mat,
00578                                                                                            IDriver *drv,
00579                                                                                            CScene *scene,
00580                                                                                            IVertexBufferHard *vb)
00581 {
00582         
00583         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CMeshVPPerPixelLight.html#z609_4">setupForMaterial</a>(mat, drv, scene)) <font class="comment">// a switch from v.p enabled / disabled force to reactivate the vertex buffer.</font>
00584         {
00585                 drv-&gt;activeVertexBufferHard(vb);                
00586         }
00587 }
00588 
00589 
00590 } <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=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>