Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_material.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ef39ec4a77ced5ae3f441a5f1a5c158719cf0b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
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
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor(s): Blender Foundation (2008), Nathan Letwory
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/makesrna/intern/rna_material.c
 *  \ingroup RNA
 */

#include <float.h>
#include <stdlib.h>

#include "DNA_material_types.h"
#include "DNA_texture_types.h"

#include "RNA_define.h"
#include "RNA_enum_types.h"

#include "rna_internal.h"

#include "WM_api.h"
#include "WM_types.h"

static EnumPropertyItem prop_texture_coordinates_items[] = {
	{TEXCO_GLOB, "GLOBAL", 0, "Global", "Use global coordinates for the texture coordinates"},
	{TEXCO_OBJECT, "OBJECT", 0, "Object", "Use linked object's coordinates for texture coordinates"},
	{TEXCO_UV, "UV", 0, "UV", "Use UV coordinates for texture coordinates"},
	{TEXCO_ORCO, "ORCO", 0, "Generated", "Use the original undeformed coordinates of the object"},
	{TEXCO_STRAND, "STRAND", 0, "Strand / Particle",
	               "Use normalized strand texture coordinate (1D) or particle age (X) and trail position (Y)"},
	{TEXCO_WINDOW, "WINDOW", 0, "Window", "Use screen coordinates as texture coordinates"},
	{TEXCO_NORM, "NORMAL", 0, "Normal", "Use normal vector as texture coordinates"},
	{TEXCO_REFL, "REFLECTION", 0, "Reflection", "Use reflection vector as texture coordinates"},
	{TEXCO_STRESS, "STRESS", 0, "Stress",
	               "Use the difference of edge lengths compared to original coordinates of the mesh"},
	{TEXCO_TANGENT, "TANGENT", 0, "Tangent", "Use the optional tangent vector as texture coordinates"},
	{0, NULL, 0, NULL, NULL}
};

EnumPropertyItem ramp_blend_items[] = {
	{MA_RAMP_BLEND, "MIX", 0, "Mix", ""},
	{MA_RAMP_ADD, "ADD", 0, "Add", ""},
	{MA_RAMP_MULT, "MULTIPLY", 0, "Multiply", ""},
	{MA_RAMP_SUB, "SUBTRACT", 0, "Subtract", ""},
	{MA_RAMP_SCREEN, "SCREEN", 0, "Screen", ""},
	{MA_RAMP_DIV, "DIVIDE", 0, "Divide", ""},
	{MA_RAMP_DIFF, "DIFFERENCE", 0, "Difference", ""},
	{MA_RAMP_DARK, "DARKEN", 0, "Darken", ""},
	{MA_RAMP_LIGHT, "LIGHTEN", 0, "Lighten", ""},
	{MA_RAMP_OVERLAY, "OVERLAY", 0, "Overlay", ""},
	{MA_RAMP_DODGE, "DODGE", 0, "Dodge", ""},
	{MA_RAMP_BURN, "BURN", 0, "Burn", ""},
	{MA_RAMP_HUE, "HUE", 0, "Hue", ""},
	{MA_RAMP_SAT, "SATURATION", 0, "Saturation", ""},
	{MA_RAMP_VAL, "VALUE", 0, "Value", ""},
	{MA_RAMP_COLOR, "COLOR", 0, "Color", ""},
	{MA_RAMP_SOFT, "SOFT_LIGHT", 0, "Soft Light", ""},
	{MA_RAMP_LINEAR, "LINEAR_LIGHT", 0, "Linear Light", ""},
	{0, NULL, 0, NULL, NULL}
};

#ifdef RNA_RUNTIME

#include "MEM_guardedalloc.h"

#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"

#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_texture.h"
#include "BKE_node.h"
#include "BKE_paint.h"

#include "ED_node.h"
#include "ED_image.h"
#include "BKE_scene.h"

static void rna_Material_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	Material *ma = ptr->id.data;

	DAG_id_tag_update(&ma->id, 0);
	WM_main_add_notifier(NC_MATERIAL | ND_SHADING, ma);
}

static void rna_Material_update_previews(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	Material *ma = ptr->id.data;
	
	if (ma->nodetree)
		BKE_node_preview_clear_tree(ma->nodetree);
		
	WM_main_add_notifier(NC_MATERIAL | ND_SHADING_PREVIEW, ma);
}

static void rna_Material_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	Material *ma = ptr->id.data;

	DAG_id_tag_update(&ma->id, 0);
	WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
}

static PointerRNA rna_Material_mirror_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_MaterialRaytraceMirror, ptr->id.data);
}

static PointerRNA rna_Material_transp_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_MaterialRaytraceTransparency, ptr->id.data);
}

static PointerRNA rna_Material_halo_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_MaterialHalo, ptr->id.data);
}

static PointerRNA rna_Material_sss_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_MaterialSubsurfaceScattering, ptr->id.data);
}

static PointerRNA rna_Material_strand_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_MaterialStrand, ptr->id.data);
}

static PointerRNA rna_Material_physics_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_MaterialPhysics, ptr->id.data);
}

static void rna_Material_type_set(PointerRNA *ptr, int value)
{
	Material *ma = (Material *)ptr->data;

	if (ma->material_type == MA_TYPE_HALO && value != MA_TYPE_HALO)
		ma->mode &= ~(MA_STAR | MA_HALO_XALPHA | MA_ZINV | MA_ENV);

	ma->material_type = value;
}

static void rna_Material_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Material *ma = (Material *)ptr->data;
	rna_iterator_array_begin(iter, (void *)ma->mtex, sizeof(MTex *), MAX_MTEX, 0, NULL);
}

static void rna_Material_texpaint_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Material *ma = (Material *)ptr->data;
	rna_iterator_array_begin(iter, (void *)ma->texpaintslot, sizeof(TexPaintSlot), ma->tot_slots, 0, NULL);
}


static void rna_Material_active_paint_texture_index_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
	bScreen *sc;
	Material *ma = ptr->id.data;

	if (ma->use_nodes && ma->nodetree && BKE_scene_use_new_shading_nodes(scene)) {
		struct bNode *node;
		int index = 0;
		for (node = ma->nodetree->nodes.first; node; node = node->next) {
			if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
				if (index++ == ma->paint_active_slot) {
					break;
				}
			}
		}
		if (node)
			nodeSetActive(ma->nodetree, node);
	}

	if (ma->texpaintslot) {
		Image *image = ma->texpaintslot[ma->paint_active_slot].ima;
		for (sc = bmain->screen.first; sc; sc = sc->id.next) {
			ScrArea *sa;
			for (sa = sc->areabase.first; sa; sa = sa->next) {
				SpaceLink *sl;
				for (sl = sa->spacedata.first; sl; sl = sl->next) {
					if (sl->spacetype == SPACE_IMAGE) {
						SpaceImage *sima = (SpaceImage *)sl;
						ED_space_image_set(sima, scene, scene->obedit, image);
					}
				}
			}
		}
	}

	DAG_id_tag_update(&ma->id, 0);
	WM_main_add_notifier(NC_MATERIAL | ND_SHADING, ma);
}

static PointerRNA rna_Material_active_texture_get(PointerRNA *ptr)
{
	Material *ma = (Material *)ptr->data;
	Tex *tex;

	tex = give_current_material_texture(ma);
	return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
}

static void rna_Material_active_texture_set(PointerRNA *ptr, PointerRNA value)
{
	Material *ma = (Material *)ptr->data;

	set_current_material_texture(ma, value.data);
}

static int rna_Material_active_texture_editable(PointerRNA *ptr)
{
	Material *ma = (Material *)ptr->id.data;

	return has_current_material_texture(ma);
}

static PointerRNA rna_Material_active_node_material_get(PointerRNA *ptr)
{
	Material *ma = give_node_material((Material *)ptr->data);
	return rna_pointer_inherit_refine(ptr, &RNA_Material, ma);
}

static void rna_Material_active_node_material_set(PointerRNA *ptr, PointerRNA value)
{
	Material *ma = (Material *)ptr->data;
	Material *ma_act = value.data;

	nodeSetActiveID(ma->nodetree, ID_MA, &ma_act->id);
}

static void rna_MaterialStrand_start_size_range(PointerRNA *ptr, float *min, float *max,
                                                float *UNUSED(softmin), float *UNUSED(softmax))
{
	Material *ma = (Material *)ptr->id.data;

	if (ma->mode & MA_STR_B_UNITS) {
		*min = 0.0001f;
		*max = 2.0f;
	}
	else {
		*min = 0.25f;
		*max = 20.0f;
	}
}

static void rna_MaterialStrand_end_size_range(PointerRNA *ptr, float *min, float *max,
                                              float *UNUSED(softmin), float *UNUSED(softmax))
{
	Material *ma = (Material *)ptr->id.data;

	if (ma->mode & MA_STR_B_UNITS) {
		*min = 0.0001f;
		*max = 1.0f;
	}
	else {
		*min = 0.25f;
		*max = 10.0f;
	}
}

static int rna_MaterialTextureSlot_use_get(PointerRNA *ptr)
{
	Material *ma = (Material *)ptr->id.data;
	MTex *mtex = (MTex *)ptr->data;
	int a;

	for (a = 0; a < MAX_MTEX; a++)
		if (ma->mtex[a] == mtex)
			return (ma->septex & (1 << a)) == 0;
	
	return 0;
}

static void rna_MaterialTextureSlot_use_set(PointerRNA *ptr, int value)
{
	Material *ma = (Material *)ptr->id.data;
	MTex *mtex = (MTex *)ptr->data;
	int a;

	for (a = 0; a < MAX_MTEX; a++) {
		if (ma->mtex[a] == mtex) {
			if (value)
				ma->septex &= ~(1 << a);
			else
				ma->septex |= (1 << a);
		}
	}
}

static void rna_Material_use_diffuse_ramp_set(PointerRNA *ptr, int value)
{
	Material *ma = (Material *)ptr->data;

	if (value) ma->mode |= MA_RAMP_COL;
	else ma->mode &= ~MA_RAMP_COL;

	if ((ma->mode & MA_RAMP_COL) && ma->ramp_col == NULL)
		ma->ramp_col = add_colorband(false);
}

static void rna_Material_use_specular_ramp_set(PointerRNA *ptr, int value)
{
	Material *ma = (Material *)ptr->data;

	if (value) ma->mode |= MA_RAMP_SPEC;
	else ma->mode &= ~MA_RAMP_SPEC;

	if ((ma->mode & MA_RAMP_SPEC) && ma->ramp_spec == NULL)
		ma->ramp_spec = add_colorband(false);
}

static void rna_Material_use_nodes_update(bContext *C, PointerRNA *ptr)
{
	Material *ma = (Material *)ptr->data;

	if (ma->use_nodes && ma->nodetree == NULL)
		ED_node_shader_default(C, &ma->id);
	
	rna_Material_draw_update(CTX_data_main(C), CTX_data_scene(C), ptr);
}

static EnumPropertyItem *rna_Material_texture_coordinates_itemf(bContext *UNUSED(C), PointerRNA *ptr,
                                                                PropertyRNA *UNUSED(prop), bool *r_free)
{
	Material *ma = (Material *)ptr->id.data;
	EnumPropertyItem *item = NULL;
	int totitem = 0;
	
	RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_GLOB);
	RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_OBJECT);
	RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_ORCO);
	
	if (ma->material_type == MA_TYPE_VOLUME) {
		
	}
	else if (ELEM(ma->material_type, MA_TYPE_SURFACE, MA_TYPE_HALO, MA_TYPE_WIRE)) {
		RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_UV);
		RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_STRAND);
		RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_WINDOW);
		RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_NORM);
		RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_REFL);
		RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_STRESS);
		RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_TANGENT);
	}
	
	RNA_enum_item_end(&item, &totitem);
	*r_free = true;
	
	return item;
}

MTex *rna_mtex_texture_slots_add(ID *self_id, struct bContext *C, ReportList *reports)
{
	MTex *mtex = add_mtex_id(self_id, -1);
	if (mtex == NULL) {
		BKE_reportf(reports, RPT_ERROR, "Maximum number of textures added %d", MAX_MTEX);
		return NULL;
	}

	/* for redraw only */
	WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));

	return mtex;
}

MTex *rna_mtex_texture_slots_create(ID *self_id, struct bContext *C, ReportList *reports, int index)
{
	MTex *mtex;

	if (index < 0 || index >= MAX_MTEX) {
		BKE_reportf(reports, RPT_ERROR, "Index %d is invalid", index);
		return NULL;
	}

	mtex = add_mtex_id(self_id, index);

	/* for redraw only */
	WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));

	return mtex;
}

void rna_mtex_texture_slots_clear(ID *self_id, struct bContext *C, ReportList *reports, int index)
{
	MTex **mtex_ar;
	short act;

	give_active_mtex(self_id, &mtex_ar, &act);

	if (mtex_ar == NULL) {
		BKE_report(reports, RPT_ERROR, "Mtex not found for this type");
		return;
	}
	
	if (index < 0 || index >= MAX_MTEX) {
		BKE_reportf(reports, RPT_ERROR, "Index %d is invalid", index);
		return;
	}

	if (mtex_ar[index]) {
		id_us_min((ID *)mtex_ar[index]->tex);
		MEM_freeN(mtex_ar[index]);
		mtex_ar[index] = NULL;
		DAG_id_tag_update(self_id, 0);
	}

	/* for redraw only */
	WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));
}

#else

static void rna_def_material_mtex(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem prop_mapping_items[] = {
		{MTEX_FLAT, "FLAT", 0, "Flat", "Map X and Y coordinates directly"},
		{MTEX_CUBE, "CUBE", 0, "Cube", "Map using the normal vector"},
		{MTEX_TUBE, "TUBE", 0, "Tube", "Map with Z as central axis"},
		{MTEX_SPHERE, "SPHERE", 0, "Sphere", "Map with Z as central axis"},
		{0, NULL, 0, NULL, NULL}
	};
		
	static EnumPropertyItem prop_x_mapping_items[] = {
		{0, "NONE", 0, "None", ""},
		{1, "X", 0, "X", ""},
		{2, "Y", 0, "Y", ""},
		{3, "Z", 0, "Z", ""},
		{0, NULL, 0, NULL, NULL}
	};
		
	static EnumPropertyItem prop_y_mapping_items[] = {
		{0, "NONE", 0, "None", ""},
		{1, "X", 0, "X", ""},
		{2, "Y", 0, "Y", ""},
		{3, "Z", 0, "Z", ""},
		{0, NULL, 0, NULL, NULL}
	};
		
	static EnumPropertyItem prop_z_mapping_items[] = {
		{0, "NONE", 0, "None", ""},
		{1, "X", 0, "X", ""},
		{2, "Y", 0, "Y", ""},
		{3, "Z", 0, "Z", ""},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem prop_normal_map_space_items[] = {
		{MTEX_NSPACE_CAMERA, "CAMERA", 0, "Camera", ""},
		{MTEX_NSPACE_WORLD, "WORLD", 0, "World", ""},
		{MTEX_NSPACE_OBJECT, "OBJECT", 0, "Object", ""},
		{MTEX_NSPACE_TANGENT, "TANGENT", 0, "Tangent", ""},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem prop_bump_method_items[] = {
		{0, "BUMP_ORIGINAL", 0, "Original", ""},
		{MTEX_COMPAT_BUMP, "BUMP_COMPATIBLE", 0, "Compatible", ""},
		{MTEX_3TAP_BUMP, "BUMP_LOW_QUALITY", 0, "Low Quality", "Use 3 tap filtering"},
		{MTEX_5TAP_BUMP, "BUMP_MEDIUM_QUALITY", 0, "Medium Quality", "Use 5 tap filtering"},
		{MTEX_BICUBIC_BUMP, "BUMP_BEST_QUALITY", 0,
		 "Best Quality", "Use bicubic filtering (requires OpenGL 3.0+, it will fall back on "
		 "medium setting for other systems)"},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem prop_bump_space_items[] = {
		{0, "BUMP_VIEWSPACE", 0, "ViewSpace", ""},
		{MTEX_BUMP_OBJECTSPACE, "BUMP_OBJECTSPACE", 0, "ObjectSpace", ""},
		{MTEX_BUMP_TEXTURESPACE, "BUMP_TEXTURESPACE", 0, "TextureSpace", ""},
		{0, NULL, 0, NULL, NULL}
	};
	
	srna = RNA_def_struct(brna, "MaterialTextureSlot", "TextureSlot");
	RNA_def_struct_sdna(srna, "MTex");
	RNA_def_struct_ui_text(srna, "Material Texture Slot", "Texture slot for textures in a Material datablock");

	prop = RNA_def_property(srna, "texture_coords", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "texco");
	RNA_def_property_enum_items(prop, prop_texture_coordinates_items);
	RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Material_texture_coordinates_itemf");
	RNA_def_property_ui_text(prop, "Texture Coordinates", "");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "object");
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Object", "Object to use for mapping with Object texture coordinates");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
	RNA_def_property_string_sdna(prop, NULL, "uvname");
	RNA_def_property_ui_text(prop, "UV Map", "UV map to use for mapping with UV texture coordinates");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_from_dupli", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_DUPLI_MAPTO);
	RNA_def_property_ui_text(prop, "From Dupli",
	                         "Dupli's instanced from verts, faces or particles, inherit texture coordinate "
	                         "from their parent");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_map_to_bounds", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_MAPTO_BOUNDS);
	RNA_def_property_ui_text(prop, "Map to Bounds",
	                         "Map coordinates in object bounds");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_from_original", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_OB_DUPLI_ORIG);
	RNA_def_property_ui_text(prop, "From Original",
	                         "Dupli's derive their object coordinates from the original object's transformation");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_map_color_diffuse", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COL);
	RNA_def_property_ui_text(prop, "Diffuse Color", "The texture affects basic color of the material");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_normal", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_NORM);
	RNA_def_property_ui_text(prop, "Normal", "The texture affects the rendered normal");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_color_spec", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COLSPEC);
	RNA_def_property_ui_text(prop, "Specular Color", "The texture affects the specularity color");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_mirror", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COLMIR);
	RNA_def_property_ui_text(prop, "Mirror", "The texture affects the mirror color");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_diffuse", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_REF);
	RNA_def_property_ui_text(prop, "Diffuse", "The texture affects the value of diffuse reflectivity");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_specular", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_SPEC);
	RNA_def_property_ui_text(prop, "Specular", "The texture affects the value of specular reflectivity");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_ambient", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_AMB);
	RNA_def_property_ui_text(prop, "Ambient", "The texture affects the value of ambient");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_hardness", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_HAR);
	RNA_def_property_ui_text(prop, "Hardness", "The texture affects the hardness value");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_raymir", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_RAYMIRR);
	RNA_def_property_ui_text(prop, "Ray-Mirror", "The texture affects the ray-mirror value");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_alpha", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_ALPHA);
	RNA_def_property_ui_text(prop, "Alpha", "The texture affects the alpha value");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_emit", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMIT);
	RNA_def_property_ui_text(prop, "Emit", "The texture affects the emit value");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_translucency", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_TRANSLU);
	RNA_def_property_ui_text(prop, "Translucency", "The texture affects the translucency value");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_displacement", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_DISPLACE);
	RNA_def_property_ui_text(prop, "Displacement", "Let the texture displace the surface");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_warp", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_WARP);
	RNA_def_property_ui_text(prop, "Warp", "Let the texture warp texture coordinates of next channels");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "mapping_x", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "projx");
	RNA_def_property_enum_items(prop, prop_x_mapping_items);
	RNA_def_property_ui_text(prop, "X Mapping", "");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "mapping_y", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "projy");
	RNA_def_property_enum_items(prop, prop_y_mapping_items);
	RNA_def_property_ui_text(prop, "Y Mapping", "");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "mapping_z", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "projz");
	RNA_def_property_enum_items(prop, prop_z_mapping_items);
	RNA_def_property_ui_text(prop, "Z Mapping", "");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_items(prop, prop_mapping_items);
	RNA_def_property_ui_text(prop, "Mapping", "");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "normal_map_space", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "normapspace");
	RNA_def_property_enum_items(prop, prop_normal_map_space_items);
	RNA_def_property_ui_text(prop, "Normal Map Space", "Set space of normal map image");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "normal_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "norfac");
	RNA_def_property_ui_range(prop, -5, 5, 10, 3);
	RNA_def_property_ui_text(prop, "Normal Factor", "Amount texture affects normal values");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "displacement_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "dispfac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Displacement Factor", "Amount texture displaces the surface");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "warp_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "warpfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Warp Factor", "Amount texture affects texture coordinates of next channels");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "specular_color_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "colspecfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Specular Color Factor", "Amount texture affects specular color");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_color_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "colfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Diffuse Color Factor", "Amount texture affects diffuse color");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "mirror_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "mirrfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Mirror Factor", "Amount texture affects mirror color");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "alpha_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "alphafac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Alpha Factor", "Amount texture affects alpha");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "difffac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Diffuse Factor", "Amount texture affects diffuse reflectivity");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "specular_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "specfac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Specular Factor", "Amount texture affects specular reflectivity");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "emit_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "emitfac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Emit Factor", "Amount texture affects emission");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "hardness_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "hardfac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Hardness Factor", "Amount texture affects hardness");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "raymir_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "raymirrfac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Ray Mirror Factor", "Amount texture affects ray mirror");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "translucency_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "translfac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Translucency Factor", "Amount texture affects translucency");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "ambient_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "ambfac");
	RNA_def_property_ui_range(prop, -1, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Ambient Factor", "Amount texture affects ambient");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	/* volume material */
	prop = RNA_def_property(srna, "use_map_color_emission", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMISSION_COL);
	RNA_def_property_ui_text(prop, "Emission Color", "The texture affects the color of emission");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_color_reflection", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_REFLECTION_COL);
	RNA_def_property_ui_text(prop, "Reflection Color", "The texture affects the color of scattered light");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_color_transmission", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_TRANSMISSION_COL);
	RNA_def_property_ui_text(prop, "Transmission Color",
	                         "The texture affects the result color after other light has been scattered/absorbed");
	RNA_def_property_update(prop, NC_TEXTURE, NULL);
	
	prop = RNA_def_property(srna, "use_map_density", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_DENSITY);
	RNA_def_property_ui_text(prop, "Density", "The texture affects the volume's density");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_emission", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMISSION);
	RNA_def_property_ui_text(prop, "Emission", "The texture affects the volume's emission");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_scatter", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_SCATTERING);
	RNA_def_property_ui_text(prop, "Scattering", "The texture affects the volume's scattering");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_map_reflect", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_REFLECTION);
	RNA_def_property_ui_text(prop, "Reflection", "The texture affects the reflected light's brightness");
	RNA_def_property_update(prop, NC_TEXTURE, NULL);
	
	prop = RNA_def_property(srna, "emission_color_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "colemitfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Emission Color Factor", "Amount texture affects emission color");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "reflection_color_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "colreflfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Reflection Color Factor", "Amount texture affects color of out-scattered light");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "transmission_color_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "coltransfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Transmission Color Factor",
	                         "Amount texture affects result color after light has been scattered/absorbed");
	RNA_def_property_update(prop, NC_TEXTURE, NULL);
	
	prop = RNA_def_property(srna, "density_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "densfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Density Factor", "Amount texture affects density");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "emission_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "emitfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Emission Factor", "Amount texture affects emission");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "scattering_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "scatterfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Scattering Factor", "Amount texture affects scattering");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "reflection_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "reflfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Reflection Factor", "Amount texture affects brightness of out-scattered light");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	/* end volume material */
	
	prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_funcs(prop, "rna_MaterialTextureSlot_use_get", "rna_MaterialTextureSlot_use_set");
	RNA_def_property_ui_text(prop, "Enabled", "Enable this material texture slot");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "bump_method", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_bitflag_sdna(prop, NULL, "texflag");
	RNA_def_property_enum_items(prop, prop_bump_method_items);
	RNA_def_property_ui_text(prop, "Bump Method", "Method to use for bump mapping");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "bump_objectspace", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_bitflag_sdna(prop, NULL, "texflag");
	RNA_def_property_enum_items(prop, prop_bump_space_items);
	RNA_def_property_ui_text(prop, "Bump Space", "Space to apply bump mapping in");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_gamesettings(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem prop_alpha_blend_items[] = {
		{GEMAT_SOLID, "OPAQUE", 0, "Opaque", "Render color of textured face as color"},
		{GEMAT_ADD, "ADD", 0, "Add", "Render face transparent and add color of face"},
		{GEMAT_CLIP, "CLIP", 0, "Alpha Clip", "Use the image alpha values clipped with no blending (binary alpha)"},
		{GEMAT_ALPHA, "ALPHA", 0, "Alpha Blend",
		              "Render polygon transparent, depending on alpha channel of the texture"},
		{GEMAT_ALPHA_SORT, "ALPHA_SORT", 0, "Alpha Sort",
		                   "Sort faces for correct alpha drawing (slow, use Alpha Clip instead when possible)"},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem prop_face_orientation_items[] = {
		{GEMAT_NORMAL, "NORMAL", 0, "Normal", "No transformation"},
		{GEMAT_HALO, "HALO", 0, "Halo", "Screen aligned billboard"},
		{GEMAT_BILLBOARD, "BILLBOARD", 0, "Billboard", "Billboard with Z-axis constraint"},
		{GEMAT_SHADOW, "SHADOW", 0, "Shadow", "Faces are used for shadow"},
		{0, NULL, 0, NULL, NULL}
	};
	
	srna = RNA_def_struct(brna, "MaterialGameSettings", NULL);
	RNA_def_struct_sdna(srna, "GameSettings");
	RNA_def_struct_nested(brna, srna, "Material");
	RNA_def_struct_ui_text(srna, "Material Game Settings", "Game Engine settings for a Material datablock");
	
	prop = RNA_def_property(srna, "use_backface_culling", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", GEMAT_BACKCULL); /* use bitflags */
	RNA_def_property_ui_text(prop, "Backface Culling", "Hide Back of the face in Game Engine ");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "text", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", GEMAT_TEXT); /* use bitflags */
	RNA_def_property_ui_text(prop, "Text", "Use material as text in Game Engine ");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "invisible", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", GEMAT_INVISIBLE); /* use bitflags */
	RNA_def_property_ui_text(prop, "Invisible", "Make face invisible");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "alpha_blend", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "alpha_blend");
	RNA_def_property_enum_items(prop, prop_alpha_blend_items);
	RNA_def_property_ui_text(prop, "Blend Mode", "Blend Mode for Transparent Faces");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "face_orientation", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_items(prop, prop_face_orientation_items);
	RNA_def_property_ui_text(prop, "Face Orientations", "Especial face orientation options");

	prop = RNA_def_property(srna, "physics", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GEMAT_NOPHYSICS); /* use bitflags */
	RNA_def_property_ui_text(prop, "Physics", "Use physics properties of materials ");
}

static void rna_def_material_colors(StructRNA *srna)
{
	PropertyRNA *prop;

	static EnumPropertyItem prop_ramp_input_items[] = {
		{MA_RAMP_IN_SHADER, "SHADER", 0, "Shader", ""},
		{MA_RAMP_IN_ENERGY, "ENERGY", 0, "Energy", ""},
		{MA_RAMP_IN_NOR, "NORMAL", 0, "Normal", ""},
		{MA_RAMP_IN_RESULT, "RESULT", 0, "Result", ""},
		{0, NULL, 0, NULL, NULL}
	};

	prop = RNA_def_property(srna, "diffuse_color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_float_sdna(prop, NULL, "r");
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Diffuse Color", "Diffuse color of the material");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");
	
	prop = RNA_def_property(srna, "specular_color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_float_sdna(prop, NULL, "specr");
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Specular Color", "Specular color of the material");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");
	
	prop = RNA_def_property(srna, "mirror_color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_float_sdna(prop, NULL, "mirr");
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Mirror Color", "Mirror color of the material");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Alpha", "Alpha transparency of the material");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "specular_alpha", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "spectra");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Specular Alpha", "Alpha transparency for specular areas");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	/* Color bands */
	prop = RNA_def_property(srna, "use_diffuse_ramp", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_RAMP_COL);
	RNA_def_property_boolean_funcs(prop, NULL, "rna_Material_use_diffuse_ramp_set");
	RNA_def_property_ui_text(prop, "Use Diffuse Ramp", "Toggle diffuse ramp operations");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_ramp", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "ramp_col");
	RNA_def_property_struct_type(prop, "ColorRamp");
	RNA_def_property_ui_text(prop, "Diffuse Ramp", "Color ramp used to affect diffuse shading");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_specular_ramp", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_RAMP_SPEC);
	RNA_def_property_boolean_funcs(prop, NULL, "rna_Material_use_specular_ramp_set");
	RNA_def_property_ui_text(prop, "Use Specular Ramp", "Toggle specular ramp operations");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "specular_ramp", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "ramp_spec");
	RNA_def_property_struct_type(prop, "ColorRamp");
	RNA_def_property_ui_text(prop, "Specular Ramp", "Color ramp used to affect specular shading");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "diffuse_ramp_blend", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "rampblend_col");
	RNA_def_property_enum_items(prop, ramp_blend_items);
	RNA_def_property_ui_text(prop, "Diffuse Ramp Blend", "Blending method of the ramp and the diffuse color");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "specular_ramp_blend", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "rampblend_spec");
	RNA_def_property_enum_items(prop, ramp_blend_items);
	RNA_def_property_ui_text(prop, "Specular Ramp Blend", "Blending method of the ramp and the specular color");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_ramp_input", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "rampin_col");
	RNA_def_property_enum_items(prop, prop_ramp_input_items);
	RNA_def_property_ui_text(prop, "Diffuse Ramp Input", "How the ramp maps on the surface");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "specular_ramp_input", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "rampin_spec");
	RNA_def_property_enum_items(prop, prop_ramp_input_items);
	RNA_def_property_ui_text(prop, "Specular Ramp Input", "How the ramp maps on the surface");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_ramp_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "rampfac_col");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Diffuse Ramp Factor", "Blending factor (also uses alpha in Colorband)");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "specular_ramp_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "rampfac_spec");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Specular Ramp Factor", "Blending factor (also uses alpha in Colorband)");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	/* Freestyle line color */
	prop = RNA_def_property(srna, "line_color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_float_sdna(prop, NULL, "line_col");
	RNA_def_property_array(prop, 4);
	RNA_def_property_ui_text(prop, "Line Color", "Line color used for Freestyle line rendering");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "line_priority", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "line_priority");
	RNA_def_property_range(prop, 0, 32767);
	RNA_def_property_ui_text(prop, "Line Priority",
	                         "The line color of a higher priority is used at material boundaries");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_diffuse(StructRNA *srna)
{
	PropertyRNA *prop;

	static EnumPropertyItem prop_diff_shader_items[] = {
		{MA_DIFF_LAMBERT, "LAMBERT", 0, "Lambert", "Use a Lambertian shader"},
		{MA_DIFF_ORENNAYAR, "OREN_NAYAR", 0, "Oren-Nayar", "Use an Oren-Nayar shader"},
		{MA_DIFF_TOON, "TOON", 0, "Toon", "Use a toon shader"},
		{MA_DIFF_MINNAERT, "MINNAERT", 0, "Minnaert", "Use a Minnaert shader"},
		{MA_DIFF_FRESNEL, "FRESNEL", 0, "Fresnel", "Use a Fresnel shader"},
		{0, NULL, 0, NULL, NULL}
	};
	
	prop = RNA_def_property(srna, "diffuse_shader", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "diff_shader");
	RNA_def_property_enum_items(prop, prop_diff_shader_items);
	RNA_def_property_ui_text(prop, "Diffuse Shader Model", "");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "diffuse_intensity", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "ref");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Diffuse Intensity", "Amount of diffuse reflection");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");
	
	prop = RNA_def_property(srna, "roughness", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, 3.14f);
	RNA_def_property_ui_text(prop, "Roughness", "Oren-Nayar Roughness");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_toon_size", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "param[0]");
	RNA_def_property_range(prop, 0.0f, 3.14f);
	RNA_def_property_ui_text(prop, "Diffuse Toon Size", "Size of diffuse toon area");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_toon_smooth", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "param[1]");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Diffuse Toon Smooth", "Smoothness of diffuse toon area");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_fresnel", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "param[1]");
	RNA_def_property_range(prop, 0.0f, 5.0f);
	RNA_def_property_ui_text(prop, "Diffuse Fresnel", "Power of Fresnel");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "diffuse_fresnel_factor", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "param[0]");
	RNA_def_property_range(prop, 0.0f, 5.0f);
	RNA_def_property_ui_text(prop, "Diffuse Fresnel Factor", "Blending factor of Fresnel");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "darkness", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, 2.0f);
	RNA_def_property_ui_text(prop, "Darkness", "Minnaert darkness");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_raymirror(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem prop_fadeto_mir_items[] = {
		{MA_RAYMIR_FADETOSKY, "FADE_TO_SKY", 0, "Sky", ""},
		{MA_RAYMIR_FADETOMAT, "FADE_TO_MATERIAL", 0, "Material", ""},
		{0, NULL, 0, NULL, NULL}
	};

	srna = RNA_def_struct(brna, "MaterialRaytraceMirror", NULL);
	RNA_def_struct_sdna(srna, "Material");
	RNA_def_struct_nested(brna, srna, "Material");
	RNA_def_struct_ui_text(srna, "Material Raytrace Mirror", "Raytraced reflection settings for a Material datablock");

	prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_RAYMIRROR); /* use bitflags */
	RNA_def_property_ui_text(prop, "Enabled", "Enable raytraced reflections");
	RNA_def_property_update(prop, 0, "rna_Material_update");
		
	prop = RNA_def_property(srna, "reflect_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "ray_mirror");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Reflectivity", "Amount of mirror reflection for raytrace");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "fresnel", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "fresnel_mir");
	RNA_def_property_range(prop, 0.0f, 5.0f);
	RNA_def_property_ui_text(prop, "Fresnel", "Power of Fresnel for mirror reflection");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "fresnel_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "fresnel_mir_i");
	RNA_def_property_range(prop, 0.0f, 5.0f);
	RNA_def_property_ui_text(prop, "Fresnel Factor", "Blending factor for Fresnel");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "gloss_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "gloss_mir");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Gloss Amount",
	                         "The shininess of the reflection (values < 1.0 give diffuse, blurry reflections)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "gloss_anisotropic", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "aniso_gloss_mir");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Gloss Anisotropy",
	                         "The shape of the reflection, from 0.0 (circular) to 1.0 "
	                         "(fully stretched along the tangent");
	RNA_def_property_update(prop, 0, "rna_Material_update");
		
	prop = RNA_def_property(srna, "gloss_samples", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "samp_gloss_mir");
	RNA_def_property_range(prop, 0, 1024);
	RNA_def_property_ui_text(prop, "Gloss Samples", "Number of cone samples averaged for blurry reflections");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "gloss_threshold", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "adapt_thresh_mir");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Gloss Threshold",
	                         "Threshold for adaptive sampling (if a sample contributes less than "
	                         "this amount [as a percentage], sampling is stopped)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_sdna(prop, NULL, "ray_depth");
	RNA_def_property_ui_range(prop, 0, 100, 1, 3);
	RNA_def_property_ui_text(prop, "Depth", "Maximum allowed number of light inter-reflections");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
	RNA_def_property_float_sdna(prop, NULL, "dist_mir");
	RNA_def_property_range(prop, 0.0f, 10000.0f);
	RNA_def_property_ui_text(prop, "Maximum Distance",
	                         "Maximum distance of reflected rays (reflections further than this "
	                         "range fade to sky color or material color)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "fade_to", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "fadeto_mir");
	RNA_def_property_enum_items(prop, prop_fadeto_mir_items);
	RNA_def_property_ui_text(prop, "Fade-out Color",
	                         "The color that rays with no intersection within the Max Distance take "
	                         "(material color can be best for indoor scenes, sky color for outdoor)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_raytra(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MaterialRaytraceTransparency", NULL);
	RNA_def_struct_sdna(srna, "Material");
	RNA_def_struct_nested(brna, srna, "Material");
	RNA_def_struct_ui_text(srna, "Material Raytrace Transparency",
	                       "Raytraced refraction settings for a Material datablock");

	prop = RNA_def_property(srna, "ior", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "ang");
	RNA_def_property_range(prop, 0.25f, 4.0f);
	RNA_def_property_ui_text(prop, "IOR", "Angular index of refraction for raytraced refraction");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "fresnel", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "fresnel_tra");
	RNA_def_property_range(prop, 0.0f, 5.0f);
	RNA_def_property_ui_text(prop, "Fresnel", "Power of Fresnel for transparency (Ray or ZTransp)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "fresnel_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "fresnel_tra_i");
	RNA_def_property_range(prop, 1.0f, 5.0f);
	RNA_def_property_ui_text(prop, "Fresnel Factor", "Blending factor for Fresnel");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "gloss_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "gloss_tra");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Gloss Amount",
	                         "The clarity of the refraction. Values < 1.0 give diffuse, blurry refractions");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "gloss_samples", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "samp_gloss_tra");
	RNA_def_property_range(prop, 0, 1024);
	RNA_def_property_ui_text(prop, "Gloss Samples", "Number of cone samples averaged for blurry refractions");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "gloss_threshold", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "adapt_thresh_tra");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Gloss Threshold",
	                         "Threshold for adaptive sampling. If a sample contributes less than "
	                         "this amount (as a percentage), sampling is stopped");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_sdna(prop, NULL, "ray_depth_tra");
	RNA_def_property_ui_range(prop, 0, 100, 1, 3);
	RNA_def_property_ui_text(prop, "Depth", "Maximum allowed number of light inter-refractions");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "filter", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "filter");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Filter",
	                         "Amount to blend in the material's diffuse color in raytraced "
	                         "transparency (simulating absorption)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "depth_max", PROP_FLOAT, PROP_DISTANCE);
	RNA_def_property_float_sdna(prop, NULL, "tx_limit");
	RNA_def_property_range(prop, 0.0f, 100.0f);
	RNA_def_property_ui_text(prop, "Limit",
	                         "Maximum depth for light to travel through the transparent material "
	                         "before becoming fully filtered (0.0 is disabled)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "tx_falloff");
	RNA_def_property_range(prop, 0.1f, 10.0f);
	RNA_def_property_ui_text(prop, "Falloff", "Falloff power for transmissivity filter effect (1.0 is linear)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_volume(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem prop_lighting_items[] = {
		{MA_VOL_SHADE_SHADELESS, "SHADELESS", 0, "Shadeless", "Do not calculate lighting and shadows"},
		{MA_VOL_SHADE_SHADOWED, "SHADOWED", 0, "Shadowed", ""},
		{MA_VOL_SHADE_SHADED, "SHADED", 0, "Shaded", ""},
		{MA_VOL_SHADE_MULTIPLE, "MULTIPLE_SCATTERING", 0, "Multiple Scattering", ""},
		{MA_VOL_SHADE_SHADEDPLUSMULTIPLE, "SHADED_PLUS_MULTIPLE_SCATTERING", 0, "Shaded + Multiple Scattering", ""},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem prop_stepsize_items[] = {
		{MA_VOL_STEP_RANDOMIZED, "RANDOMIZED", 0, "Randomized", ""},
		{MA_VOL_STEP_CONSTANT, "CONSTANT", 0, "Constant", ""},
		/*{MA_VOL_STEP_ADAPTIVE, "ADAPTIVE", 0, "Adaptive", ""}, */
		{0, NULL, 0, NULL, NULL}
	};
		
	srna = RNA_def_struct(brna, "MaterialVolume", NULL);
	RNA_def_struct_sdna(srna, "VolumeSettings");
	RNA_def_struct_nested(brna, srna, "Material");
	RNA_def_struct_ui_text(srna, "Material Volume", "Volume rendering settings for a Material datablock");
	
	prop = RNA_def_property(srna, "step_method", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "stepsize_type");
	RNA_def_property_enum_items(prop, prop_stepsize_items);
	RNA_def_property_ui_text(prop, "Step Calculation", "Method of calculating the steps through the volume");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "step_size", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "stepsize");
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.001f, 1.0f, 1, 3);
	RNA_def_property_ui_text(prop, "Step Size", "Distance between subsequent volume depth samples");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "light_method", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "shade_type");
	RNA_def_property_enum_items(prop, prop_lighting_items);
	RNA_def_property_ui_text(prop, "Lighting Mode",
	                         "Method of shading, attenuating, and scattering light through the volume");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_external_shadows", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "shadeflag", MA_VOL_RECV_EXT_SHADOW); /* use bitflags */
	RNA_def_property_ui_text(prop, "External Shadows", "Receive shadows from sources outside the volume (temporary)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_light_cache", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "shadeflag", MA_VOL_PRECACHESHADING); /* use bitflags */
	RNA_def_property_ui_text(prop, "Light Cache",
	                         "Pre-calculate the shading information into a voxel grid, "
	                         "speeds up shading at slightly less accuracy");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "cache_resolution", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "precache_resolution");
	RNA_def_property_range(prop, 1, 1024);
	RNA_def_property_ui_text(prop, "Resolution",
	                         "Resolution of the voxel grid, low resolutions are faster, "
	                         "high resolutions use more memory");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "ms_diffusion", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "ms_diff");
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_text(prop, "Diffusion", "Diffusion factor, the strength of the blurring effect");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "ms_spread", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "ms_spread");
	RNA_def_property_range(prop, 0, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 1, 3);
	RNA_def_property_ui_text(prop, "Spread", "Proportional distance over which the light is diffused");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "ms_intensity", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "ms_intensity");
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_text(prop, "Intensity", "Multiplier for multiple scattered light energy");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "depth_threshold", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "depth_cutoff");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Depth Cutoff",
	                         "Stop ray marching early if transmission drops below this luminance - "
	                         "higher values give speedups in dense volumes at the expense of accuracy");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "density", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "density");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Density", "The base density of the volume");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "density_scale", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "density_scale");
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
	RNA_def_property_ui_text(prop, "Density Scale", "Multiplier for the material's density");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "scattering", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "scattering");
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
	RNA_def_property_ui_text(prop, "Scattering",
	                         "Amount of light that gets scattered out by the volume - "
	                         "the more out-scattering, the shallower the light will penetrate");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "transmission_color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_float_sdna(prop, NULL, "transmission_col");
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Transmission Color",
	                         "Result color of the volume, after other light has been scattered/absorbed");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");
	
	prop = RNA_def_property(srna, "reflection_color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_float_sdna(prop, NULL, "reflection_col");
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Reflection Color",
	                         "Color of light scattered out of the volume (does not affect transmission)");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");
	
	prop = RNA_def_property(srna, "reflection", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "reflection");
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
	RNA_def_property_ui_text(prop, "Reflection",
	                         "Multiplier to make out-scattered light brighter or darker (non-physically correct)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "emission_color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_float_sdna(prop, NULL, "emission_col");
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Emission Color", "Color of emitted light");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");
	
	prop = RNA_def_property(srna, "emission", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "emission");
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
	RNA_def_property_ui_text(prop, "Emission", "Amount of light that gets emitted by the volume");
	RNA_def_property_update(prop, 0, "rna_Material_update");
		
	prop = RNA_def_property(srna, "asymmetry", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "asymmetry");
	RNA_def_property_range(prop, -1.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Asymmetry",
	                         "Back scattering (-1.0) to Forward scattering (1.0) and the range in between");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}


static void rna_def_material_halo(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MaterialHalo", NULL);
	RNA_def_struct_sdna(srna, "Material");
	RNA_def_struct_nested(brna, srna, "Material");
	RNA_def_struct_ui_text(srna, "Material Halo", "Halo particle effect settings for a Material datablock");

	prop = RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "hasize");
	RNA_def_property_range(prop, 0.0f, 100.0f);
	RNA_def_property_ui_text(prop, "Size", "Dimension of the halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "hardness", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "har");
	RNA_def_property_range(prop, 0, 127);
	RNA_def_property_ui_text(prop, "Hardness", "Hardness of the halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "add", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "add");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Add", "Strength of the add effect");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "ring_count", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "ringc");
	RNA_def_property_range(prop, 0, 24);
	RNA_def_property_ui_text(prop, "Rings", "Number of rings rendered over the halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "line_count", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "linec");
	RNA_def_property_range(prop, 0, 250);
	RNA_def_property_ui_text(prop, "Line Number", "Number of star shaped lines rendered over the halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "star_tip_count", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "starc");
	RNA_def_property_range(prop, 3, 50);
	RNA_def_property_ui_text(prop, "Star Tips", "Number of points on the star shaped halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "seed", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "seed1");
	RNA_def_property_range(prop, 0, 255);
	RNA_def_property_ui_text(prop, "Seed", "Randomize ring dimension and line location");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_flare_mode", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_FLARE); /* use bitflags */
	RNA_def_property_ui_text(prop, "Flare", "Render halo as a lens flare");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "flare_size", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "flaresize");
	RNA_def_property_range(prop, 0.1f, 25.0f);
	RNA_def_property_ui_text(prop, "Flare Size", "Factor by which the flare is larger than the halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "flare_subflare_size", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "subsize");
	RNA_def_property_range(prop, 0.1f, 25.0f);
	RNA_def_property_ui_text(prop, "Flare Subsize", "Dimension of the sub-flares, dots and circles");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "flare_boost", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "flareboost");
	RNA_def_property_range(prop, 0.1f, 10.0f);
	RNA_def_property_ui_text(prop, "Flare Boost", "Give the flare extra strength");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "flare_seed", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "seed2");
	RNA_def_property_range(prop, 0, 255);
	RNA_def_property_ui_text(prop, "Flare Seed", "Offset in the flare seed table");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "flare_subflare_count", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "flarec");
	RNA_def_property_range(prop, 1, 32);
	RNA_def_property_ui_text(prop, "Flares Sub", "Number of sub-flares");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_ring", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_RINGS);
	RNA_def_property_ui_text(prop, "Rings", "Render rings over halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_lines", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_LINES);
	RNA_def_property_ui_text(prop, "Lines", "Render star shaped lines over halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_star", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_STAR);
	RNA_def_property_ui_text(prop, "Star", "Render halo as a star");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_texture", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALOTEX);
	RNA_def_property_ui_text(prop, "Texture", "Give halo a texture");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_vertex_normal", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALOPUNO);
	RNA_def_property_ui_text(prop, "Vertex Normal", "Use the vertex normal to specify the dimension of the halo");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_extreme_alpha", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_XALPHA);
	RNA_def_property_ui_text(prop, "Extreme Alpha", "Use extreme alpha");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_shaded", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_SHADE);
	RNA_def_property_ui_text(prop, "Shaded", "Let halo receive light and shadows from external objects");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_soft", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_SOFT);
	RNA_def_property_ui_text(prop, "Soft", "Soften the edges of halos at intersections with other geometry");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_sss(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MaterialSubsurfaceScattering", NULL);
	RNA_def_struct_sdna(srna, "Material");
	RNA_def_struct_nested(brna, srna, "Material");
	RNA_def_struct_ui_text(srna, "Material Subsurface Scattering",
	                       "Diffuse subsurface scattering settings for a Material datablock");

	prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_COLOR | PROP_UNIT_LENGTH);
	RNA_def_property_float_sdna(prop, NULL, "sss_radius");
	RNA_def_property_range(prop, 0.001, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.001, 10000, 1, 3);
	RNA_def_property_ui_text(prop, "Radius", "Mean red/green/blue scattering path length");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_float_sdna(prop, NULL, "sss_col");
	RNA_def_property_ui_text(prop, "Color", "Scattering color");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "error_threshold", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "sss_error");
	RNA_def_property_ui_range(prop, 0.0001, 10, 1, 3);
	RNA_def_property_ui_text(prop, "Error Tolerance", "Error tolerance (low values are slower and higher quality)");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "sss_scale");
	RNA_def_property_ui_range(prop, 0.001, 1000, 1, 3);
	RNA_def_property_ui_text(prop, "Scale", "Object scale factor");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "ior", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "sss_ior");
	RNA_def_property_ui_range(prop, 0.1, 2, 1, 3);
	RNA_def_property_ui_text(prop, "IOR", "Index of refraction (higher values are denser)");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "color_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "sss_colfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Color Factor", "Blend factor for SSS colors");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "texture_factor", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "sss_texfac");
	RNA_def_property_ui_range(prop, 0, 1, 10, 3);
	RNA_def_property_ui_text(prop, "Texture Factor", "Texture scattering blend factor");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "front", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "sss_front");
	RNA_def_property_range(prop, 0, 2);
	RNA_def_property_ui_text(prop, "Front", "Front scattering weight");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "back", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "sss_back");
	RNA_def_property_range(prop, 0, 10);
	RNA_def_property_ui_text(prop, "Back", "Back scattering weight");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "sss_flag", MA_DIFF_SSS);
	RNA_def_property_ui_text(prop, "Enabled", "Enable diffuse subsurface scattering effects in a material");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_specularity(StructRNA *srna)
{
	PropertyRNA *prop;
	
	static EnumPropertyItem prop_specular_shader_items[] = {
		{MA_SPEC_COOKTORR, "COOKTORR", 0, "CookTorr", "Use a Cook-Torrance shader"},
		{MA_SPEC_PHONG, "PHONG", 0, "Phong", "Use a Phong shader"},
		{MA_SPEC_BLINN, "BLINN", 0, "Blinn", "Use a Blinn shader"},
		{MA_SPEC_TOON, "TOON", 0, "Toon", "Use a toon shader"},
		{MA_SPEC_WARDISO, "WARDISO", 0, "WardIso", "Use a Ward anisotropic shader"},
		{0, NULL, 0, NULL, NULL}
	};
	
	prop = RNA_def_property(srna, "specular_shader", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "spec_shader");
	RNA_def_property_enum_items(prop, prop_specular_shader_items);
	RNA_def_property_ui_text(prop, "Specular Shader Model", "");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "specular_intensity", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "spec");
	RNA_def_property_range(prop, 0, 1);
	RNA_def_property_ui_text(prop, "Specular Intensity", "How intense (bright) the specular reflection is");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	/* NOTE: "har", "param", etc are used for multiple purposes depending on
	 * settings. This should be fixed in DNA once, for RNA we just expose them
	 * multiple times, which may give somewhat strange changes in the outliner,
	 * but in the UI they are never visible at the same time. */

	prop = RNA_def_property(srna, "specular_hardness", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "har");
	RNA_def_property_range(prop, 1, 511);
	RNA_def_property_ui_text(prop, "Specular Hardness", "How hard (sharp) the specular reflection is");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "specular_ior", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "refrac");
	RNA_def_property_range(prop, 1, 10);
	RNA_def_property_ui_text(prop, "Specular IOR", "Specular index of refraction");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "specular_toon_size", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "param[2]");
	RNA_def_property_range(prop, 0.0f, 1.53f);
	RNA_def_property_ui_text(prop, "Specular Toon Size", "Size of specular toon area");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "specular_toon_smooth", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "param[3]");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Specular Toon Smooth", "Smoothness of specular toon area");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "specular_slope", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "rms");
	RNA_def_property_range(prop, 0, 0.4);
	RNA_def_property_ui_text(prop, "Specular Slope", "The standard deviation of surface slope");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_strand(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MaterialStrand", NULL);
	RNA_def_struct_sdna(srna, "Material");
	RNA_def_struct_nested(brna, srna, "Material");
	RNA_def_struct_ui_text(srna, "Material Strand", "Strand settings for a Material datablock");

	prop = RNA_def_property(srna, "use_tangent_shading", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_TANGENT_STR);
	RNA_def_property_ui_text(prop, "Tangent Shading", "Use direction of strands as normal for tangent-shading");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	/* this flag is only set when rendering, not to be edited manually */
	prop = RNA_def_property(srna, "use_surface_diffuse", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_STR_SURFDIFF);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Surface Diffuse", "Make diffuse shading more similar to shading the surface");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "blend_distance", PROP_FLOAT, PROP_DISTANCE);
	RNA_def_property_float_sdna(prop, NULL, "strand_surfnor");
	RNA_def_property_range(prop, 0, 10);
	RNA_def_property_ui_text(prop, "Blend Distance", "Worldspace distance over which to blend in the surface normal");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_blender_units", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_STR_B_UNITS);
	RNA_def_property_ui_text(prop, "Blender Units", "Use Blender units for widths instead of pixels");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "root_size", PROP_FLOAT, PROP_UNSIGNED);
	RNA_def_property_float_sdna(prop, NULL, "strand_sta");
	RNA_def_property_float_funcs(prop, NULL, NULL, "rna_MaterialStrand_start_size_range");
	RNA_def_property_ui_range(prop, 0, 10.0f, 10, 5);
	RNA_def_property_ui_text(prop, "Root Size", "Start size of strands in pixels or Blender units");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "tip_size", PROP_FLOAT, PROP_UNSIGNED);
	RNA_def_property_float_sdna(prop, NULL, "strand_end");
	RNA_def_property_ui_range(prop, 0, 10.0f, 10, 5);
	RNA_def_property_float_funcs(prop, NULL, NULL, "rna_MaterialStrand_end_size_range");
	RNA_def_property_ui_text(prop, "Tip Size", "End size of strands in pixels or Blender units");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "size_min", PROP_FLOAT, PROP_UNSIGNED);
	RNA_def_property_float_sdna(prop, NULL, "strand_min");
	RNA_def_property_range(prop, 0.001, 10);
	RNA_def_property_ui_text(prop, "Minimum Size", "Minimum size of strands in pixels");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "shape", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "strand_ease");
	RNA_def_property_range(prop, -0.9, 0.9);
	RNA_def_property_ui_text(prop, "Shape", "Positive values make strands rounder, negative ones make strands spiky");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "width_fade", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "strand_widthfade");
	RNA_def_property_range(prop, 0, 2);
	RNA_def_property_ui_text(prop, "Width Fade", "Transparency along the width of the strand");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
	RNA_def_property_string_sdna(prop, NULL, "strand_uvname");
	RNA_def_property_ui_text(prop, "UV Map", "Name of UV map to override");
	RNA_def_property_update(prop, 0, "rna_Material_update");
}

static void rna_def_material_physics(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "MaterialPhysics", NULL);
	RNA_def_struct_sdna(srna, "Material");
	RNA_def_struct_nested(brna, srna, "Material");
	RNA_def_struct_ui_text(srna, "Material Physics", "Physics settings for a Material datablock");
	
	prop = RNA_def_property(srna, "friction", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "friction");
	RNA_def_property_range(prop, 0, 100);
	RNA_def_property_ui_text(prop, "Friction", "Coulomb friction coefficient, when inside the physics distance area");

	prop = RNA_def_property(srna, "elasticity", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "reflect");
	RNA_def_property_range(prop, 0, 1);
	RNA_def_property_ui_text(prop, "Elasticity", "Elasticity of collisions");

	/* FH/Force Field Settings */
	prop = RNA_def_property(srna, "use_fh_normal", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "dynamode", MA_FH_NOR);
	RNA_def_property_ui_text(prop, "Align to Normal",
	                         "Align dynamic game objects along the surface normal, "
	                         "when inside the physics distance area");

	prop = RNA_def_property(srna, "fh_force", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "fh");
	RNA_def_property_range(prop, 0, 1);
	RNA_def_property_ui_range(prop, 0.0, 1.0, 10, 2);
	RNA_def_property_ui_text(prop, "Force", "Upward spring force, when inside the physics distance area");
	
	prop = RNA_def_property(srna, "fh_distance", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "fhdist");
	RNA_def_property_range(prop, 0, 20);
	RNA_def_property_ui_text(prop, "Distance", "Distance of the physics area");
	
	prop = RNA_def_property(srna, "fh_damping", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "xyfrict");
	RNA_def_property_range(prop, 0, 1);
	RNA_def_property_ui_text(prop, "Damping", "Damping of the spring force, when inside the physics distance area");
}

void RNA_def_material(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem prop_type_items[] = {
		{MA_TYPE_SURFACE, "SURFACE", 0, "Surface", "Render object as a surface"},
		{MA_TYPE_WIRE, "WIRE", 0, "Wire", "Render the edges of faces as wires (not supported in raytracing)"},
		{MA_TYPE_VOLUME, "VOLUME", 0, "Volume", "Render object as a volume"},
		{MA_TYPE_HALO, "HALO", 0, "Halo", "Render object as halo particles"},
		{0, NULL, 0, NULL, NULL}
	};
	static EnumPropertyItem transparency_items[] = {
		{0, "MASK", 0, "Mask", "Mask the background"},
		{MA_ZTRANSP, "Z_TRANSPARENCY", 0, "Z Transparency", "Use alpha buffer for transparent faces"},
		{MA_RAYTRANSP, "RAYTRACE", 0, "Raytrace", "Use raytracing for transparent refraction rendering"},
		{0, NULL, 0, NULL, NULL}
	};
	
	/* Render Preview Types */
	static EnumPropertyItem preview_type_items[] = {
		{MA_FLAT, "FLAT", ICON_MATPLANE, "Flat", "Flat XY plane"},
		{MA_SPHERE, "SPHERE", ICON_MATSPHERE, "Sphere", "Sphere"},
		{MA_CUBE, "CUBE", ICON_MATCUBE, "Cube", "Cube"},
		{MA_MONKEY, "MONKEY", ICON_MONKEY, "Monkey", "Monkey"},
		{MA_HAIR, "HAIR", ICON_HAIR, "Hair", "Hair strands"},
		{MA_SPHERE_A, "SPHERE_A", ICON_MAT_SPHERE_SKY, "World Sphere", "Large sphere with sky"},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem prop_shadows_only_items[] = {
		{MA_SO_OLD, "SHADOW_ONLY_OLD", 0, "Shadow and Distance", "Old shadow only method"},
		{MA_SO_SHADOW, "SHADOW_ONLY", 0, "Shadow Only", "Improved shadow only method"},
		{MA_SO_SHADED, "SHADOW_ONLY_SHADED", 0, "Shadow and Shading",
		 "Improved shadow only method which also renders lightless areas as shadows"},
		{0, NULL, 0, NULL, NULL}
	};

	srna = RNA_def_struct(brna, "Material", "ID");
	RNA_def_struct_ui_text(srna, "Material",
	                       "Material datablock to define the appearance of geometric objects for rendering");
	RNA_def_struct_ui_icon(srna, ICON_MATERIAL_DATA);
	
	prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "material_type");
	RNA_def_property_enum_items(prop, prop_type_items);
	RNA_def_property_ui_text(prop, "Type", "Material type defining how the object is rendered");
	RNA_def_property_enum_funcs(prop, NULL, "rna_Material_type_set", NULL);
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "use_transparency", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_TRANSP);
	RNA_def_property_ui_text(prop, "Transparency", "Render material as transparent");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "transparency_method", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
	RNA_def_property_enum_items(prop, transparency_items);
	RNA_def_property_ui_text(prop, "Transparency Method", "Method to use for rendering transparency");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	/* For Preview Render */
	prop = RNA_def_property(srna, "preview_render_type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "pr_type");
	RNA_def_property_enum_items(prop, preview_type_items);
	RNA_def_property_ui_text(prop, "Preview render type", "Type of preview render");
	RNA_def_property_update(prop, 0, "rna_Material_update_previews");
	
	prop = RNA_def_property(srna, "ambient", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "amb");
	RNA_def_property_range(prop, 0, 1);
	RNA_def_property_ui_text(prop, "Ambient", "Amount of global ambient color the material receives");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "emit", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0, FLT_MAX);
	RNA_def_property_ui_range(prop, 0, 2.0f, 1, 2);
	RNA_def_property_ui_text(prop, "Emit", "Amount of light to emit");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "translucency", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_range(prop, 0, 1);
	RNA_def_property_ui_text(prop, "Translucency", "Amount of diffuse shading on the back side");
	RNA_def_property_update(prop, 0, "rna_Material_update");
		
	prop = RNA_def_property(srna, "use_cubic", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_CUBIC);
	RNA_def_property_ui_text(prop, "Cubic Interpolation",
	                         "Use cubic interpolation for diffuse values, for smoother transitions");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_object_color", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_OBCOLOR);
	RNA_def_property_ui_text(prop, "Object Color", "Modulate the result with a per-object color");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");

	prop = RNA_def_property(srna, "shadow_ray_bias", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "sbias");
	RNA_def_property_range(prop, 0, 0.25);
	RNA_def_property_ui_text(prop, "Shadow Ray Bias",
	                         "Shadow raytracing bias to prevent terminator problems on shadow boundary");

	prop = RNA_def_property(srna, "shadow_buffer_bias", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "lbias");
	RNA_def_property_range(prop, 0, 10);
	RNA_def_property_ui_text(prop, "Shadow Buffer Bias", "Factor to multiply shadow buffer bias with (0 is ignore)");

	prop = RNA_def_property(srna, "shadow_cast_alpha", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "shad_alpha");
	RNA_def_property_range(prop, 0.001, 1);
	RNA_def_property_ui_text(prop, "Shadow Casting Alpha",
	                         "Shadow casting alpha, in use for Irregular and Deep shadow buffer");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "light_group", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "group");
	RNA_def_property_struct_type(prop, "Group");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Light Group", "Limit lighting to lamps in this Group");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_sdna(prop, NULL, "index");
	RNA_def_property_ui_text(prop, "Pass Index", "Index number for the IndexMA render pass");
	RNA_def_property_update(prop, NC_OBJECT, "rna_Material_update");

	/* flags */
	
	prop = RNA_def_property(srna, "use_light_group_exclusive", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_GROUP_NOLAY);
	RNA_def_property_ui_text(prop, "Light Group Exclusive",
	                         "Material uses the light group exclusively - these lamps are excluded "
	                         "from other scene lighting");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_light_group_local", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_GROUP_LOCAL);
	RNA_def_property_ui_text(prop, "Light Group Local", "When linked in, material uses local light group with the same name");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_raytrace", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_TRACEBLE);
	RNA_def_property_ui_text(prop, "Traceable",
	                         "Include this material and geometry that uses it in raytracing calculations");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_shadows", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_SHADOW);
	RNA_def_property_ui_text(prop, "Shadows", "Allow this material to receive shadows");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_shadeless", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_SHLESS);
	RNA_def_property_ui_text(prop, "Shadeless", "Make this material insensitive to light or shadow");
	RNA_def_property_update(prop, 0, "rna_Material_draw_update");
	
	prop = RNA_def_property(srna, "use_vertex_color_light", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_VERTEXCOL);
	RNA_def_property_ui_text(prop, "Vertex Color Light", "Add vertex colors as additional lighting");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_vertex_color_paint", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_VERTEXCOLP);
	RNA_def_property_ui_text(prop, "Vertex Color Paint",
	                         "Replace object base color with vertex colors (multiply with "
	                         "'texture face' face assigned textures)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "invert_z", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_ZINV);
	RNA_def_property_ui_text(prop, "Invert Z Depth",
	                         "Render material's faces with an inverted Z buffer (scanline only)");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "offset_z", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "zoffs");
	RNA_def_property_ui_text(prop, "Z Offset", "Give faces an artificial offset in the Z buffer for Z transparency");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_sky", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_ENV);
	RNA_def_property_ui_text(prop, "Sky",
	                         "Render this material with zero alpha, with sky background in place (scanline only)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_only_shadow", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_ONLYSHADOW);
	RNA_def_property_ui_text(prop, "Only Shadow",
	                         "Render shadows as the material's alpha value, making the material "
	                         "transparent except for shadowed areas");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "shadow_only_type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_bitflag_sdna(prop, NULL, "shadowonly_flag");
	RNA_def_property_enum_items(prop, prop_shadows_only_items);
	RNA_def_property_ui_text(prop, "Shadow Type", "How to draw shadows");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_face_texture", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_FACETEXTURE);
	RNA_def_property_ui_text(prop, "Face Textures",
	                         "Replace the object's base color with color from UV map image textures");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_face_texture_alpha", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_FACETEXTURE_ALPHA);
	RNA_def_property_ui_text(prop, "Face Textures Alpha",
	                         "Replace the object's base alpha value with alpha from UV map image textures");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_cast_shadows", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode2", MA_CASTSHADOW);
	RNA_def_property_ui_text(prop, "Cast Shadows",
	                         "Allow this material to cast shadows");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_cast_shadows_only", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_ONLYCAST);
	RNA_def_property_ui_text(prop, "Cast Shadows Only",
	                         "Make objects with this material appear invisible (not rendered), only casting shadows");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_mist", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "mode", MA_NOMIST);
	RNA_def_property_ui_text(prop, "Use Mist", "Use mist with this material (in world settings)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_transparent_shadows", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_SHADOW_TRA);
	RNA_def_property_ui_text(prop, "Receive Transparent Shadows",
	                         "Allow this object to receive transparent shadows cast through other objects");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_ray_shadow_bias", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_RAYBIAS);
	RNA_def_property_ui_text(prop, "Ray Shadow Bias",
	                         "Prevent raytraced shadow errors on surfaces with smooth shaded normals "
	                         "(terminator problem)");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_full_oversampling", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_FULL_OSA);
	RNA_def_property_ui_text(prop, "Full Oversampling",
	                         "Force this material to render full shading/textures for all anti-aliasing samples");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_cast_buffer_shadows", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_SHADBUF);
	RNA_def_property_ui_text(prop, "Cast Buffer Shadows",
	                         "Allow this material to cast shadows from shadow buffer lamps");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	prop = RNA_def_property(srna, "use_cast_approximate", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_APPROX_OCCLUSION);
	RNA_def_property_ui_text(prop, "Cast Approximate",
	                         "Allow this material to cast shadows when using approximate ambient occlusion");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_tangent_shading", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_TANGENT_V);
	RNA_def_property_ui_text(prop, "Tangent Shading",
	                         "Use the material's tangent vector instead of the normal for shading "
	                         "- for anisotropic shading effects");
	RNA_def_property_update(prop, 0, "rna_Material_update");
	
	prop = RNA_def_property(srna, "use_uv_project", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mapflag", MA_MAPFLAG_UVPROJECT);
	RNA_def_property_ui_text(prop, "UV Project",
	                         "Use to ensure UV interpolation is correct for camera projections (use with UV project modifier)");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	/* nested structs */
	prop = RNA_def_property(srna, "raytrace_mirror", PROP_POINTER, PROP_NONE);
	RNA_def_property_flag(prop, PROP_NEVER_NULL);
	RNA_def_property_struct_type(prop, "MaterialRaytraceMirror");
	RNA_def_property_pointer_funcs(prop, "rna_Material_mirror_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Raytrace Mirror", "Raytraced reflection settings for the material");

	prop = RNA_def_property(srna, "raytrace_transparency", PROP_POINTER, PROP_NONE);
	RNA_def_property_flag(prop, PROP_NEVER_NULL);
	RNA_def_property_struct_type(prop, "MaterialRaytraceTransparency");
	RNA_def_property_pointer_funcs(prop, "rna_Material_transp_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Raytrace Transparency", "Raytraced transparency settings for the material");

	prop = RNA_def_property(srna, "volume", PROP_POINTER, PROP_NONE);
	RNA_def_property_flag(prop, PROP_NEVER_NULL);
	RNA_def_property_pointer_sdna(prop, NULL, "vol");
	RNA_def_property_struct_type(prop, "MaterialVolume");
	RNA_def_property_ui_text(prop, "Volume", "Volume settings for the material");

	prop = RNA_def_property(srna, "halo", PROP_POINTER, PROP_NONE);
	RNA_def_property_flag(prop, PROP_NEVER_NULL);
	RNA_def_property_struct_type(prop, "MaterialHalo");
	RNA_def_property_pointer_funcs(prop, "rna_Material_halo_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Halo", "Halo settings for the material");

	prop = RNA_def_property(srna, "subsurface_scattering", PROP_POINTER, PROP_NONE);
	RNA_def_property_flag(prop, PROP_NEVER_NULL);
	RNA_def_property_struct_type(prop, "MaterialSubsurfaceScattering");
	RNA_def_property_pointer_funcs(prop, "rna_Material_sss_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Subsurface Scattering", "Subsurface scattering settings for the material");

	prop = RNA_def_property(srna, "strand", PROP_POINTER, PROP_NONE);
	RNA_def_property_flag(prop, PROP_NEVER_NULL);
	RNA_def_property_struct_type(prop, "MaterialStrand");
	RNA_def_property_pointer_funcs(prop, "rna_Material_strand_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Strand", "Strand settings for the material");
	
	prop = RNA_def_property(srna, "physics", PROP_POINTER, PROP_NONE);
	RNA_def_property_flag(prop, PROP_NEVER_NULL);
	RNA_def_property_struct_type(prop, "MaterialPhysics");
	RNA_def_property_pointer_funcs(prop, "rna_Material_physics_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Physics", "Game physics settings");

	/* game settings */
	prop = RNA_def_property(srna, "game_settings", PROP_POINTER, PROP_NONE);
	RNA_def_property_flag(prop, PROP_NEVER_NULL);
	RNA_def_property_pointer_sdna(prop, NULL, "game");
	RNA_def_property_struct_type(prop, "MaterialGameSettings");
	RNA_def_property_ui_text(prop, "Game Settings", "Game material settings");

	/* nodetree */
	prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
	RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based materials");

	prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "use_nodes", 1);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
	RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the material");
	RNA_def_property_update(prop, 0, "rna_Material_use_nodes_update");

	prop = RNA_def_property(srna, "active_node_material", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "Material");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_pointer_funcs(prop, "rna_Material_active_node_material_get",
	                               "rna_Material_active_node_material_set", NULL, NULL);
	RNA_def_property_ui_text(prop, "Material", "Active node material");
	RNA_def_property_update(prop, NC_MATERIAL, NULL);

	/* common */
	rna_def_animdata_common(srna);
	rna_def_mtex_common(brna, srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get",
	                    "rna_Material_active_texture_set", "rna_Material_active_texture_editable",
	                    "MaterialTextureSlot", "MaterialTextureSlots", "rna_Material_update", "rna_Material_update");

	rna_def_texpaint_slots(brna, srna);

	/* only material has this one */
	prop = RNA_def_property(srna, "use_textures", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "septex", 1);
	RNA_def_property_array(prop, 18);
	RNA_def_property_ui_text(prop, "Use Textures", "Enable/Disable each texture");
	RNA_def_property_update(prop, 0, "rna_Material_update");

	rna_def_material_colors(srna);
	rna_def_material_diffuse(srna);
	rna_def_material_specularity(srna);

	/* nested structs */
	rna_def_material_raymirror(brna);
	rna_def_material_raytra(brna);
	rna_def_material_volume(brna);
	rna_def_material_halo(brna);
	rna_def_material_sss(brna);
	rna_def_material_mtex(brna);
	rna_def_material_strand(brna);
	rna_def_material_physics(brna);
	rna_def_material_gamesettings(brna);

	RNA_api_material(srna);
}


static void rna_def_texture_slots(BlenderRNA *brna, PropertyRNA *cprop, const char *structname,
                                  const char *structname_slots)
{
	StructRNA *srna;

	FunctionRNA *func;
	PropertyRNA *parm;

	RNA_def_property_srna(cprop, structname_slots);
	srna = RNA_def_struct(brna, structname_slots, NULL);
	RNA_def_struct_sdna(srna, "ID");
	RNA_def_struct_ui_text(srna, "Texture Slots", "Collection of texture slots");

	/* functions */
	func = RNA_def_function(srna, "add", "rna_mtex_texture_slots_add");
	RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_NO_SELF | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
	parm = RNA_def_pointer(func, "mtex", structname, "", "The newly initialized mtex");
	RNA_def_function_return(func, parm);
	
	func = RNA_def_function(srna, "create", "rna_mtex_texture_slots_create");
	RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_NO_SELF | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
	parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Slot index to initialize", 0, INT_MAX);
	RNA_def_property_flag(parm, PROP_REQUIRED);
	parm = RNA_def_pointer(func, "mtex", structname, "", "The newly initialized mtex");
	RNA_def_function_return(func, parm);
	
	func = RNA_def_function(srna, "clear", "rna_mtex_texture_slots_clear");
	RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_NO_SELF | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
	parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Slot index to clear", 0, INT_MAX);
	RNA_def_property_flag(parm, PROP_REQUIRED);
}

void rna_def_mtex_common(BlenderRNA *brna, StructRNA *srna, const char *begin,
                         const char *activeget, const char *activeset, const char *activeeditable,
                         const char *structname, const char *structname_slots, const char *update, const char *update_index)
{
	PropertyRNA *prop;

	/* mtex */
	prop = RNA_def_property(srna, "texture_slots", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, structname);
	RNA_def_property_collection_funcs(prop, begin, "rna_iterator_array_next", "rna_iterator_array_end",
	                                  "rna_iterator_array_dereference_get", NULL, NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Textures", "Texture slots defining the mapping and influence of textures");
	rna_def_texture_slots(brna, prop, structname, structname_slots);

	prop = RNA_def_property(srna, "active_texture", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "Texture");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	if (activeeditable)
		RNA_def_property_editable_func(prop, activeeditable);
	RNA_def_property_pointer_funcs(prop, activeget, activeset, NULL, NULL);
	RNA_def_property_ui_text(prop, "Active Texture", "Active texture slot being displayed");
	RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, update);

	prop = RNA_def_property(srna, "active_texture_index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_sdna(prop, NULL, "texact");
	RNA_def_property_range(prop, 0, MAX_MTEX - 1);
	RNA_def_property_ui_text(prop, "Active Texture Index", "Index of active texture slot");
	RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, update_index);
}

static void rna_def_tex_slot(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "TexPaintSlot", NULL);
	RNA_def_struct_ui_text(srna, "Texture Paint Slot",
	                       "Slot that contains information about texture painting");

	prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
	RNA_def_property_string_maxlength(prop, 64); /* else it uses the pointer size! */
	RNA_def_property_string_sdna(prop, NULL, "uvname");
	RNA_def_property_ui_text(prop, "UV Map", "Name of UV map");
	RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Material_update");
	
	prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Index", "Index of MTex slot in the material");
}


void rna_def_texpaint_slots(BlenderRNA *brna, StructRNA *srna)
{
	PropertyRNA *prop;

	rna_def_tex_slot(brna);

	/* mtex */
	prop = RNA_def_property(srna, "texture_paint_images", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "texpaintslot", NULL);
	RNA_def_property_collection_funcs(prop, "rna_Material_texpaint_begin", "rna_iterator_array_next", "rna_iterator_array_end",
	                                  "rna_iterator_array_dereference_get", NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "Image");
	RNA_def_property_ui_text(prop, "Texture Slot Images", "Texture images used for texture painting");

	prop = RNA_def_property(srna, "texture_paint_slots", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_Material_texpaint_begin", "rna_iterator_array_next", "rna_iterator_array_end",
	                                  "rna_iterator_array_get", NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "TexPaintSlot");
	RNA_def_property_ui_text(prop, "Texture Slots", "Texture slots defining the mapping and influence of textures");

	prop = RNA_def_property(srna, "paint_active_slot", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_range(prop, 0, SHRT_MAX);
	RNA_def_property_ui_text(prop, "Active Paint Texture Index", "Index of active texture paint slot");
	RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, "rna_Material_active_paint_texture_index_update");

	prop = RNA_def_property(srna, "paint_clone_slot", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_range(prop, 0, SHRT_MAX);
	RNA_def_property_ui_text(prop, "Clone Paint Texture Index", "Index of clone texture paint slot");
	RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, NULL);
}

#endif