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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
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="/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> <A CLASS=uplinks HREF='/'><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF='/'><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="/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>
<!-- 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> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </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 <algorithm></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<<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 <<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<<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>->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>->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<<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->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->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]->VegetableManager= <font class="keyword">this</font>;
00173 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]->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]->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 &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=> 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=> R0.y= [0,1] <=> [-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=> R0.y= [0,1] <=> [-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 => 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>->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->_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 &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->_Owner= clipBlock;
00710 ret->_Center= center;
00711 ret->_Radius= radius;
00712
00713 <font class="comment">// append to list.</font>
00714 clipBlock->_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->_InstanceGroupList.size() == 0);
00727
00728 <font class="comment">// unlink from clipBlock</font>
00729 sortBlock->_Owner->_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->_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->_SortOwner= sortBlock;
00747 ret->_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->_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->_NumIgs++;
00760
00761 <font class="comment">// link ig to sortBlock.</font>
00762 sortBlock->_InstanceGroupList.append(ret);
00763
00764 <font class="comment">// Special Init: The ZSort rdrPass must start with the same HardMode than SortBlock.</font>
00765 ret->_RdrPass[<a class="code" href="vegetable__def_8h.html#a5">NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT</a>].HardMode= sortBlock->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->_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->_ULNumVertices;
00792 <font class="comment">// unlink the ig for lighting update.</font>
00793 ig->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 < <a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; rdrPass++)
00799 {
00800 <font class="comment">// rdrPass</font>
00801 CVegetableInstanceGroup::CVegetableRdrPass &vegetRdrPass= ig->_RdrPass[rdrPass];
00802 <font class="comment">// which allocator?</font>
00803 CVegetableVBAllocator &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<numVertices;i++)
00811 {
00812 vbAllocator.deleteVertex(vegetRdrPass.Vertices[i]);
00813 }
00814 vegetRdrPass.Vertices.clear();
00815 }
00816
00817 CVegetableClipBlock *clipBlock= ig->_ClipOwner;
00818 CVegetableSortBlock *sortBlock= ig->_SortOwner;
00819
00820 <font class="comment">// If I have got some faces in ZSort rdrPass</font>
00821 <font class="keywordflow">if</font>(ig->_HasZSortPassInstances)
00822 <font class="comment">// after my deletion, the sortBlock must be updated.</font>
00823 sortBlock->_Dirty= <font class="keyword">true</font>;
00824
00825
00826 <font class="comment">// unlink from sortBlock, and delete.</font>
00827 sortBlock->_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->_NumIgs--;
00833 <font class="comment">// if the clipBlock is now empty, change list</font>
00834 <font class="keywordflow">if</font>(clipBlock->_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 &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> &it->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= &it->second;
00858
00859 <font class="comment">// fill.</font>
00860 <font class="keywordflow">try</font>
00861 {
00862 ret->loadShape(shape);
00863 }
00864 <font class="keywordflow">catch</font> (Exception &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> &instanceLighted, <font class="keywordtype">bool</font> &instanceDoubleSided, <font class="keywordtype">bool</font> &instanceZSort,
00884 <font class="keywordtype">bool</font> &destLighted, <font class="keywordtype">bool</font> &precomputeLighting)
00885 {
00886 instanceLighted= shape->Lighted;
00887 instanceDoubleSided= shape->DoubleSided;
00888 <font class="comment">// Disable ZSorting when we intersect water.</font>
00889 instanceZSort= shape->AlphaBlend && vegetWaterState!=<a class="code" href="classNL3D_1_1CVegetableManager.html#s4s2">IntersectWater</a>;
00890 destLighted= instanceLighted && !shape->PreComputeLighting;
00891 precomputeLighting= instanceLighted && shape->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 &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 &vegetRdrPass= vegetIgReserve._RdrPass[rdrPass];
00936
00937 <font class="comment">// Reserve space in the rdrPass.</font>
00938 vegetRdrPass.NVertices+= numInstances * shape->VB.getNumVertices();
00939 vegetRdrPass.NTriangles+= numInstances * shape->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 &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<<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; rdrPass++)
00956 {
00957 CVegetableInstanceGroup::CVegetableRdrPass &vegetRdrPass= ig->_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->_TriangleQuadrantOrderArray.size()==0);
00965 <a class="code" href="debug_8h.html#a6">nlassert</a>(ig->_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<<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>; rdrPass++)
00972 {
00973 CVegetableInstanceGroup::CVegetableRdrPass &vegetRdrPass= ig->_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->_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>0)
00992 {
00993 <font class="keywordtype">float</font> *start= ig->_TriangleQuadrantOrderArray.getPtr();
00994 <font class="comment">// init ptr to each qaudrant</font>
00995 <font class="keywordflow">for</font>(uint i=0; i<<a class="code" href="vegetable__def_8h.html#a10">NL3D_VEGETABLE_NUM_QUADRANT</a>; i++)
00996 {
00997 ig->_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 &rotNormal, <font class="keywordtype">bool</font> instanceDoubleSided,
01005 <font class="keyword">const</font> CVector &sunDir, CRGBA primaryRGBA, CRGBA secondaryRGBA,
01006 CVegetableLightEx &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>=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>=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>=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>=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 &rotNormal, <font class="keywordtype">bool</font> instanceDoubleSided,
01087 <font class="keyword">const</font> CVector &sunDir, CRGBA primaryRGBA, CRGBA secondaryRGBA,
01088 CVegetableLightEx &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>=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>=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> &mat,
01150 <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CRGBAF.html">NLMISC::CRGBAF</a> &ambientColor, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CRGBAF.html">NLMISC::CRGBAF</a> &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 && shape->BestSidedPreComputeLighting;
01171
01172
01173 <font class="comment">// veget rdrPass</font>
01174 CVegetableInstanceGroup::CVegetableRdrPass &vegetRdrPass= ig->_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 => 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 &vegetLex= ig->VegetableLightEx;
01211 <font class="comment">// Color of pointLights modulated by diffuse.</font>
01212 CRGBA diffusePL[2];
01213 <font class="keywordflow">if</font>(vegetLex.NumLights>=1)
01214 {
01215 diffusePL[0].modulateFromColorRGBOnly(diffuseRGBA, vegetLex.Color[0]);
01216 <font class="keywordflow">if</font>(vegetLex.NumLights>=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= &<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= &<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->exceedMaxVertexInBufferHard(shape->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->_SortOwner->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->_SortOwner->_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->Next;
01258 }
01259
01260 <font class="comment">// Then all The sortBlock is in SoftMode.</font>
01261 ig->_SortOwner->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= &<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 &dstVBInfo= allocator->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->_ClipOwner->extendSphere(instancePos);
01294
01295
01296 <font class="comment">// Vertex/triangle Info.</font>
01297 uint numNewVertices= shape->VB.getNumVertices();
01298 uint numNewTris= shape->TriangleIndices.size()/3;
01299 uint numNewIndices= shape->TriangleIndices.size();
01300
01301 <font class="comment">// src info.</font>
01302 uint srcNormalOff= (instanceLighted? shape->VB.getNormalOff() : 0);
01303 uint srcTex0Off= shape->VB.getTexCoordOff(0);
01304 uint srcTex1Off= shape->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<CVector> 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<(sint)numNewVertices;i++)
01332 {
01333 <font class="comment">// allocate a Vertex</font>
01334 uint vid= allocator->allocateVertex();
01335 <font class="comment">// store in tmp shape.</font>
01336 shape->InstanceVertices[i]= vid;
01337
01338 <font class="comment">// Fill this vertex.</font>
01339 uint8 *srcPtr= (uint8*)shape->VB.getVertexCoordPointer(i);
01340 uint8 *dstPtr= (uint8*)allocator->getVertexPointer(vid);
01341
01342 <font class="comment">// Get bendWeight for this vertex.</font>
01343 <font class="keywordtype">float</font> vertexBendWeight= ((CUV*)(srcPtr + srcTex1Off))->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->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->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->_ClipOwner->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->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->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->x= deltaPosNorm;
01446 <font class="comment">// setup bendFreqFactor</font>
01447 dstBendPtr->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->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->flushVertex(vid);
01462 }
01463
01464
01465 <font class="comment">// must recompute the sphere according to the bbox.</font>
01466 ig->_ClipOwner->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->_SortOwner->_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->_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->_SortOwner->_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->_SortOwner->_UnderWater= <font class="keyword">true</font>;
01483
01484 <font class="comment">// static to avoid reallocation</font>
01485 <font class="keyword">static</font> vector<CVector> triangleCenters;
01486 triangleCenters.resize(numNewTris);
01487
01488 <font class="comment">// compute triangle centers</font>
01489 <font class="keywordflow">for</font>(uint i=0; i<numNewTris; i++)
01490 {
01491 <font class="comment">// get index in shape.</font>
01492 uint v0= shape->TriangleIndices[i*3+0];
01493 uint v1= shape->TriangleIndices[i*3+1];
01494 uint v2= shape->TriangleIndices[i*3+2];
01495
01496 <font class="comment">// get world coord.</font>
01497 <font class="keyword">const</font> CVector &vert0= worldVertices[v0];
01498 <font class="keyword">const</font> CVector &vert1= worldVertices[v1];
01499 <font class="keyword">const</font> CVector &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->_SortOwner->_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->_TriangleQuadrantOrderNumTriangles;
01510 ig->_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->_TriangleQuadrantOrderNumTriangles * NL3D_VEGETABLE_NUM_QUADRANT <= ig->_TriangleQuadrantOrderArray.size());
01513
01514
01515 <font class="comment">// compute distance for each quadrant.</font>
01516 <font class="keywordflow">for</font>(uint quadId=0; quadId<<a class="code" href="vegetable__def_8h.html#a10">NL3D_VEGETABLE_NUM_QUADRANT</a>; quadId++)
01517 {
01518 <font class="keyword">const</font> CVector &quadDir= CVegetableQuadrant::Dirs[quadId];
01519
01520 <font class="comment">// For all tris.</font>
01521 <font class="keywordflow">for</font>(uint i=0; i<numNewTris; i++)
01522 {
01523 <font class="comment">// compute the distance with orientation of the quadrant. (DotProduct)</font>
01524 ig->_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 <= vegetRdrPass.Vertices.size());
01543 <a class="code" href="debug_8h.html#a6">nlassert</a>(offTriIdx + numNewIndices <= vegetRdrPass.TriangleIndices.size());
01544 <a class="code" href="debug_8h.html#a6">nlassert</a>(offTriIdx + numNewIndices <= 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, &shape->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<(sint)numNewIndices; i++)
01553 {
01554 <font class="comment">// get the index of the vertex in the shape</font>
01555 uint vid= shape->TriangleIndices[i];
01556 <font class="comment">// re-direction, using InstanceVertices;</font>
01557 vegetRdrPass.TriangleIndices[offTriIdx + i]= shape->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->_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->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 < vegetRdrPass.LightedInstances.size());
01583
01584 <font class="comment">// Fill instance info</font>
01585 CVegetableInstanceGroup::CVegetableLightedInstance &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 &vegetRdrPass= ig->_RdrPass[rdrPass];
01608
01609 <font class="comment">// the allocator where vertices come from</font>
01610 CVegetableVBAllocator &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 &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 < vegetRdrPass.Vertices.size() !!!</font>
01623 <font class="keywordflow">for</font>(i=0;i<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<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<<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 <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 <<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 &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->setFilterMode(ITexture::Linear, ITexture::LinearMipMapLinear);
01708 tex->setWrapS(ITexture::Clamp);
01709 tex->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 &ambient, <font class="keyword">const</font> CRGBA &diffuse, <font class="keyword">const</font> CVector &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 <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 <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<</a>(<font class="keyword">const</font> <a class="code" href="classNL3D_1_1CSortVSB.html#a0">CSortVSB</a> &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>->_SortKey>o.Sb->_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->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity);
01779 <font class="comment">// c[4..7] take the ModelView Matrix. After setupModelMatrix();</font>
01780 driver->setConstantMatrix(4, IDriver::ModelView, IDriver::Identity);
01781 <font class="comment">// c[8] take usefull constants.</font>
01782 driver->setConstant(8, 0, 1, 0.5f, 2);
01783 <font class="comment">// c[9] take normalized directional light</font>
01784 driver->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->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->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->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->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->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->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->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->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->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->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<<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->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 &viewCenter, <font class="keyword">const</font> CVector &frontVector, <font class="keyword">const</font> std::vector<CPlane> &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->clip(pyramid))
01846 {
01847 <font class="comment">// insert into visible list.</font>
01848 ptrClipBlock->_RenderNext= rootToRender;
01849 rootToRender= ptrClipBlock;
01850 }
01851
01852 <font class="comment">// next</font>
01853 ptrClipBlock= (CVegetableClipBlock*)ptrClipBlock->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->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->fogEnabled();
01874 driver->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->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<<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<<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>=0; vbHardMode--)
01988 {
01989 <font class="comment">// For all renderPass.</font>
01990 <font class="keywordflow">for</font>(sint rdrPass=0; rdrPass < <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 &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()>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->enableVertexProgramDoubleSidedColor(doubleSided);
02008
02009
02010 <font class="comment">// Activate the unique material.</font>
02011 driver->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]->getProgram().c_str());</font>
02015 <a class="code" href="debug_8h.html#a9">nlverify</a>(driver->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->_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->_InstanceGroupList.begin();
02030 <font class="keywordflow">while</font>(ptrIg)
02031 {
02032 <font class="comment">// rdrPass</font>
02033 CVegetableInstanceGroup::CVegetableRdrPass &vegetRdrPass= ptrIg->_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 && vbHardMode==1) || (!vegetRdrPass.HardMode && vbHardMode==0) )
02037 {
02038 <font class="comment">// Ok, Render the faces.</font>
02039 <font class="keywordflow">if</font>(vegetRdrPass.NTriangles)
02040 {
02041 driver->renderSimpleTriangles(&vegetRdrPass.TriangleIndices[0],
02042 vegetRdrPass.NTriangles);
02043 }
02044 }
02045
02046 <font class="comment">// next ig.</font>
02047 ptrIg= (CVegetableInstanceGroup*)ptrIg->Next;
02048 }
02049
02050 <font class="comment">// next sortBlock</font>
02051 ptrSortBlock= (CVegetableSortBlock *)(ptrSortBlock->Next);
02052 }
02053
02054 <font class="comment">// next clipBlock to render </font>
02055 ptrClipBlock= ptrClipBlock->_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<CVector> p0DebugLines;</font>
02068 <font class="comment"> static vector<CVector> 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<<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]->setWorldPos(pos);
02090 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_6">_ZSortModelLayersUW</a>[i]->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()>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()>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<CSortVSB> 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->_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->_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->_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<0)
02124 {
02125 ptrSortBlock->_SortKey= - distToViewer;
02126 }
02127 <font class="keywordflow">else</font>
02128 {
02129 ptrSortBlock->_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->_SortKey to get correct negative values.</font>
02137 <font class="keywordflow">if</font>(ptrSortBlock->_SortKey < ptrSortBlock->_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<<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>bestDirVal)
02148 {
02149 bestDirVal= dirVal;
02150 bestDirIdx= dirIdx;
02151 }
02152 }
02153
02154 <font class="comment">// set the result.</font>
02155 ptrSortBlock->_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->_Center);</font>
02162 <font class="comment"> p1DebugLines.push_back(ptrSortBlock->_Center + CVegetableQuadrant::Dirs[bestDirIdx]);*/</font>
02163 }
02164
02165 <font class="comment">// next sortBlock</font>
02166 ptrSortBlock= (CVegetableSortBlock *)(ptrSortBlock->Next);
02167 }
02168
02169 <font class="comment">// next clipBlock to render </font>
02170 ptrClipBlock= ptrClipBlock->_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<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->_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">// => 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) >> 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->_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]->SortBlocks.push_back(ptrSortBlock);
02212 <font class="keywordflow">else</font>
02213 <a class="code" href="classNL3D_1_1CVegetableManager.html#z890_5">_ZSortModelLayers</a>[layer]->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->activeVertexProgram(NULL);
02224
02225 <font class="comment">// reset state to default.</font>
02226 driver->enableVertexProgramDoubleSidedColor(<font class="keyword">false</font>);
02227
02228
02229 <font class="comment">// restore Fog.</font>
02230 driver->enableFog(bkupFog);
02231
02232
02233 <font class="comment">// Debug Quadrants</font>
02234 <font class="comment">/*for(uint l=0; l<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->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->fogEnabled();
02254 driver->enableFog(<font class="keyword">false</font>);
02255
02256 <font class="comment">// set model matrix to the manager matrix.</font>
02257 driver->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->enableVertexProgramDoubleSidedColor(doubleSided);
02270
02271 <font class="comment">// Activate the unique material (correclty setuped for AlphaBlend in render()).</font>
02272 driver->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]->getProgram().c_str());</font>
02276 <a class="code" href="debug_8h.html#a9">nlverify</a>(driver->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->activeVertexProgram(NULL);
02300
02301 <font class="comment">// reset state to default.</font>
02302 driver->enableVertexProgramDoubleSidedColor(<font class="keyword">false</font>);
02303
02304 <font class="comment">// restore Fog.</font>
02305 driver->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 &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> > 0 && <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>->_ULNext;
02391 }
02392 }
02393
02394 <font class="comment">// Now, _ULNVerticesToUpdate should be <=0. (most of the time < 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>->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>>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>>= <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 &vegetRdrPass= <a class="code" href="classNL3D_1_1CVegetableManager.html#z891_9">_ULRootIg</a>->_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>>= 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>>= 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>>= <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<<a class="code" href="vegetable__def_8h.html#a0">NL3D_VEGETABLE_NRDRPASS</a>);
02478 CVegetableInstanceGroup::CVegetableRdrPass &vegetRdrPass= ig->_RdrPass[rdrPassId];
02479 <font class="comment">// get the lighted instance.</font>
02480 <a class="code" href="debug_8h.html#a6">nlassert</a>(instanceId<vegetRdrPass.LightedInstances.size());
02481 CVegetableInstanceGroup::CVegetableLightedInstance &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->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 &vegetLex= ig->VegetableLightEx;
02492 <font class="comment">// Color of pointLights modulated by diffuse.</font>
02493 CRGBA diffusePL[2];
02494 <font class="keywordflow">if</font>(vegetLex.NumLights>=1)
02495 {
02496 diffusePL[0].modulateFromColorRGBOnly(vegetLI.MatDiffuse, vegetLex.Color[0]);
02497 <font class="keywordflow">if</font>(vegetLex.NumLights>=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->DoubleSided;
02510 <font class="comment">// Precompute lighting or not??</font>
02511 <font class="keywordtype">bool</font> precomputeLighting= instanceLighted && shape->PreComputeLighting;
02512 <font class="comment">// bestSided Precompute lighting or not??</font>
02513 <font class="keywordtype">bool</font> bestSidedPrecomputeLighting= precomputeLighting && shape->BestSidedPreComputeLighting;
02514 <font class="comment">// destLighted?</font>
02515 <font class="keywordtype">bool</font> destLighted= instanceLighted && !shape->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 &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->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= &<a class="code" href="classNL3D_1_1CVegetableManager.html#c1">getVBAllocatorForRdrPassAndVBHardMode</a>(rdrPassId, vegetRdrPass.HardMode);
02534 <font class="keyword">const</font> CVertexBuffer &dstVBInfo= allocator->getSoftwareVertexBuffer();
02535
02536 uint srcNormalOff= (instanceLighted? shape->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<(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->InstanceVertices[i]= vid;
02553
02554 <font class="comment">// Fill this vertex.</font>
02555 uint8 *srcPtr= (uint8*)shape->VB.getVertexCoordPointer(i);
02556 uint8 *dstPtr= (uint8*)allocator->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->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> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|