forked from p1nga/RV4-Calibration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReal Virtuality 4.jsx
118 lines (95 loc) · 3.67 KB
/
Real Virtuality 4.jsx
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
#include ../common/functions.jsx
// Exports maps for Real Virtuality 4
// Renames maps to expected RV4 standard
// Combines Specular and Glossiness Into SMDI
// Applies GradientMap To AmbientOcclusion
// Does Not Support Metalness
// Bumps Normal
function Calibrate()
{
SetSaveAlpha(false);
SetAOExport(false);
SetIgnoreSuffixType(true);
var mapType = GetMapType();
switch(mapType)
{
case "Normal":
SetMapType("nohq");
var normal = GetBumpedNormal(mapType);
FlipY();
BlendMap(normal, "Normal", BlendMode.OVERLAY,50);
return normal;
case "Albedo":
SetMapType("co");
var map = GetMergedMap();
BlendMap(map, "AO", BlendMode.MULTIPLY, 50);
return map;
case "AO":
SetMapType("as");
var ambientshadow = GetMergedMap();
ambientshadow.changeMode(ChangeMode.RGB);
var channels = ambientshadow.channels;
var whiteChannel = fillWhite();
StoreMapInChannel(ambientshadow, whiteChannel, channels, 0);
StoreMapInChannel(ambientshadow, "AO", channels, 1);
StoreMapInChannel(ambientshadow, whiteChannel, channels, 2);
return ambientshadow;
case "Specular":
SetMapType("smdi");
var smdimap = GetMergedMap();
var channels = smdimap.channels;
var whiteChannel = fillWhite();
StoreMapInChannel(smdimap, whiteChannel, channels, 0);
StoreMapInChannel(smdimap, "Specular",channels, 1);
StoreMapInChannelInverted(smdimap, "Gloss", channels, 2);
BlendMap(smdimap, "AO", BlendMode.MULTIPLY, 100);
if(true)
{
app.activeDocument.activeChannels = [channels[1]];
activeDocument.activeLayer.adjustLevels(15, 140, 0.4, 0, 250);
app.activeDocument.activeChannels = [channels[2]];
activeDocument.activeLayer.adjustLevels(0, 90, 0.4, 20, 255);
}
return smdimap;
default:
return null;
}
}
function Finish()
{
}
// --- THE FUNCTIONS BELOW ARE SHARED AND ULTIMATLEY SHOULD BELONG IN THE COMMON.JSX
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
function fillWhite()
{
fillBlack();
Invert();
}
function BlendMap(_map, _blendMapType, _blendMode, _opacity)
{
var blendMap = GetMap(_blendMapType);
if(blendMap != null)
{
app.open(new File(blendMap[0]));
DuplicateMerged(blendMap[1]);
DuplicateToDocument(_map.name);
Close("no", _map);
_map.activeLayer.blendMode = _blendMode;
_map.activeLayer.opacity = _opacity;
_map.flatten();
}
}
function StoreMapInChannelInverted(_map, _mapType, _channels, _channel)
{
//This function takes a source texture and inverts it, then stores it in the output texture and channel.
var map = GetMap(_mapType); // Find map
if(map != null) // If map exists, do:
{
var mapDoc = app.open(new File(map[0])); // Open map
activeDocument = _map; // Select main document
_map.activeChannels = [_channels[_channel]]; // Select channel
ApplyMergedFromName(mapDoc.name); // Apply map to channel
Invert(); // Inverts the Channel
}
}