-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoMaterial_RedShift
186 lines (174 loc) · 9.48 KB
/
AutoMaterial_RedShift
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
/////////////////////// AutoMaterial_Redshift Node Generator ///////////////////////
/////////////////////// By: Fabio Basile ///////////////////////
////////////////////////////////////////////////////////////////////////////////////
///|----------------------------------------------------------------------------|///
///| This MEL script is currently under early development. |///
///| !! USE AT OWN RISK !! |///
///|----------------------------------------------------------------------------|///
////////////////////////////////////////////////////////////////////////////////////
// specify your PBR shader suffixes here and ensure that the same naming convention is followed by your painting program export settings
// If you don't need a particular PBR network to be generated, leave the specific variable blank like so: "" DO NOT LEAVE SPACES.
string $PBR_C = "Color"; //Color
string $PBR_D = "Diffuse"; //Diffuse
string $PBR_M = "Metalness"; //Metalness / Reflectivity / Shine
string $PBR_R = "Roughness"; //Roughness / Microdetails
string $PBR_E = "EmissionColor"; //Emission / Luminosity
string $PBR_O = "Opacity"; //Opacity / Transparency
string $PBR_IOR = "Ior"; //Index Of Refraction
string $PBR_N = "Normal"; //Bump map
string $PBR_H = "DisplaceHeightField"; //Displacement / Heightfield
string $filePrefix = "[PREFIX]"; // Type a prefix for your painting program to use when saving your maps
string $strDir = "[PATH TO TEXTURES FOLDER]"+$filePrefix+"_"; //edit what's between the quotes only, to specify the location of your textures on your hard drive. REMEMBER TO CHANGE ALL YOUR FORWARD ( \ ) SLASHES INTO BACKSLASHES ( / )
string $ext = "exr"; //texture file extension
string $selectedObjs[] = `ls -sl`; // ITERATE ALL OBJECTS SELECTED
//////////////////////////////////////////////////////////////////////////
////////////// !!! DO NOT MODIFY BELOW THIS LINE !!! /////////////////
////////////// !!! UNLESS YOU KNOW WHAT YOU'RE DOING !!! /////////////////
//////////////////////////////////////////////////////////////////////////
if(`namespace -exists $filePrefix`){
namespace -f -mv $filePrefix ":";
namespace -rm $filePrefix;
}
for ($obj in $selectedObjs){
string $newMat = `shadingNode -asShader "RedshiftMaterial"`;
string $rnMat = `rename $newMat ($obj + "_RS")`;
string $newSG = `sets -renderable true -noSurfaceShader true -empty -name ($rnMat + "SG")`;
//////// IF VARIABLE EXISTS, CREATE THE FOLLOWING NODES:
// GENERATE PBR COLOR NODES AND SETTINGS
if($PBR_C != ""){
string $fileNodeC = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_C)`;
connectAttr -f ( $obj + "_RS_" + $PBR_C + ".outColor" ) ($obj + "_RS.diffuse_color" );
string $inputC = $fileNodeC + ".fileTextureName";
string $pathC = $strDir + $obj + "_RS_" + $PBR_C + "." + $ext ;
string $csC = $fileNodeC + ".colorSpace";
string $csrulesC = $fileNodeC + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputC $pathC;
if($ext == "exr"){
setAttr $csrulesC 1;
setAttr -type "string" $csC "Raw";
}
}
// GENERATE PBR DIFFUSE NODES AND SETTINGS
if($PBR_D != ""){
string $fileNodeD = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_D)`;
connectAttr -f ( $obj + "_RS_" + $PBR_D + ".outAlpha" ) ($obj + "_RS.diffuse_weight" );
string $inputD = $fileNodeD + ".fileTextureName";
string $pathD = $strDir + $obj + "_RS_" + $PBR_D + "." + $ext ;
string $csD = $fileNodeD + ".colorSpace";
string $csrulesD = $fileNodeD + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputD $pathD;
if($ext == "exr"){
setAttr $csrulesD 1;
setAttr -type "string" $csD "Raw";
}
}
// GENERATE PBR METALLICITY NODES AND SETTINGS
if($PBR_M != ""){
string $fileNodeM = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_M)`;
connectAttr -f ( $obj + "_RS_" + $PBR_M + ".outAlpha" ) ($obj + "_RS.refl_weight" );
string $inputM = $fileNodeM + ".fileTextureName";
string $pathM = $strDir + $obj + "_RS_" + $PBR_M + "." + $ext ;
string $csM = $fileNodeM + ".colorSpace";
string $csrulesM = $fileNodeM + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputM $pathM;
if($ext == "exr"){
setAttr $csrulesM 1;
setAttr -type "string" $csM "Raw";
}
}
// GENERATE PBR ROUGHNESS NODES AND SETTINGS
if($PBR_R != ""){
string $fileNodeR = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_R)`;
connectAttr -f ( $obj + "_RS_" + $PBR_R + ".outAlpha" ) ($obj + "_RS.refl_roughness" );
string $inputR = $fileNodeR + ".fileTextureName";
string $pathR = $strDir + $obj + "_RS_" + $PBR_R + "." + $ext ;
string $csR = $fileNodeR + ".colorSpace";
string $csrulesR = $fileNodeR + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputR $pathR;
if($ext == "exr"){
setAttr $csrulesR 1;
setAttr -type "string" $csR "Raw";
}
}
// GENERATE PBR EMISSION NODES AND SETTINGS
if($PBR_E != ""){
string $fileNodeE = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_E)`;
connectAttr -f ( $obj + "_RS_" + $PBR_E + ".outColor" ) ($obj + "_RS.emission_color" );
string $inputE = $fileNodeE + ".fileTextureName";
string $pathE = $strDir + $obj + "_RS_" + $PBR_E + "." + $ext ;
string $csE = $fileNodeE + ".colorSpace";
string $csrulesE = $fileNodeE + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputE $pathE;
if($ext == "exr"){
setAttr $csrulesE 1;
setAttr -type "string" $csE "Raw";
}
}
// GENERATE PBR OPACITY NODES AND SETTINGS
if($PBR_O != ""){
string $fileNodeO = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_O)`;
connectAttr -f ( $obj + "_RS_" + $PBR_O + ".outColor" ) ( $obj + "_RS.opacity_color" );
string $pathO = $strDir + $obj + "_RS_" + $PBR_O + "." + $ext ;
string $inputO = $fileNodeO + ".fileTextureName";
string $csO = $fileNodeO + ".colorSpace";
string $csrulesO = $fileNodeO + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputO $pathO;
if($ext == "exr"){
setAttr $csrulesO 1;
setAttr -type "string" $csO "Raw";
}
}
// GENERATE PBR REFRACTION NODES AND SETTINGS
if($PBR_IOR != ""){
string $fileNodeIOR = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_IOR)`;
connectAttr -f ( $obj + "_RS_" + $PBR_IOR + ".outAlpha" ) ( $obj + "_RS.refr_weight" );
string $pathIOR = $strDir + $obj + "_RS_" + $PBR_IOR + "." + $ext ;
string $inputIOR = $fileNodeIOR + ".fileTextureName";
string $csIOR = $fileNodeIOR + ".colorSpace";
string $csrulesIOR = $fileNodeIOR + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputIOR $pathIOR;
if($ext == "exr"){
setAttr $csrulesIOR 1;
setAttr -type "string" $csIOR "Raw";
}
}
// GENERATE PBR NORMAL NODES AND SETTINGS
if($PBR_N != ""){
string $fileNodeN = `shadingNode -asUtility RedshiftBumpMap -name ($obj + "_RS_" + $PBR_N)`;
string $fileNodeNM = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_N + "M")`;
connectAttr -f ( $obj + "_RS_" + $PBR_N + ".input" ) ($obj + "_RSSG.rsBumpmapShader" );
connectAttr -f ( $obj + "_RS_" + $PBR_N + "M.outColor" ) ($obj + "_RS_Normal.input" );
string $inputNM = $fileNodeNM + ".fileTextureName";
string $pathNM = $strDir + $obj + "_RS_" + $PBR_N + "M" + "." + $ext ;
string $inputN = $fileNodeN + ".input";
string $pathN = $strDir + $obj + "_RS_" + $PBR_N + "." + $ext ;
string $csN = $fileNodeNM + ".colorSpace";
string $csrulesN = $fileNodeNM + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputNM $pathN;
if($ext == "exr"){
setAttr $csrulesN 1;
setAttr -type "string" $csN "Raw";
}
}
// GENERATE PBR DISPLACEMENT NODES AND SETTINGS
if($PBR_H != ""){
string $fileNodeH = `shadingNode -asUtility RedshiftDisplacement -name ($obj + "_RS_" + $PBR_H)`;
string $fileNodeHM = `shadingNode -asTexture file -name ($obj + "_RS_" + $PBR_H + "M")`;
connectAttr -f ( $obj + "_RS_" + $PBR_H + ".texMap" ) ($obj + "_RSSG.rsDisplacementShader" );
connectAttr -f ( $obj + "_RS_" + $PBR_H + "M.outColor" ) ($obj + "_RS_DisplaceHeightField.texMap" );
string $inputHM = $fileNodeHM + ".fileTextureName";
string $pathHM = $strDir + $obj + "_RS_" + $PBR_H + "M" + "." + $ext ;
string $inputH = $fileNodeH + ".texMap";
string $pathH = $strDir + $obj + "_RS_" + $PBR_H + "." + $ext ;
string $csH = $fileNodeHM + ".colorSpace";
string $csrulesH = $fileNodeHM + ".ignoreColorSpaceFileRules";
setAttr -type "string" $inputHM $pathH;
if($ext == "exr"){
setAttr $csrulesH 1;
setAttr -type "string" $csH "Raw";
}
}
// connect each material to each shader, rinse and repeat
connectAttr -f ($rnMat + ".outColor") ($newSG + ".surfaceShader");
sets -e -forceElement $newSG $obj;
}