-
Notifications
You must be signed in to change notification settings - Fork 32
/
jiTraceAOVs.osl
52 lines (46 loc) · 1.66 KB
/
jiTraceAOVs.osl
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
//Traces secondary outputs for use in comp in a single render layer
//currently only works reliably with later versions of Arnold
//Julius Ihle 2021
shader jiTraceAOVs(
string trace_component = "P"
[[ string help = "The name of the component to reflect. OSL globals such as P, N, u, v as well as arbitrary userdata such as Pref are supported." ]],
color trace_color = 1
[[ string help = "The color to be used if trace_component is not found." ]],
string traceset = ""
[[ string help = "The name of the traceset (optional). Can be used to exclude all geo of an environment if it contains multiple shapes." ]],
int inclusive = 1
[[ string widget = "checkBox",
string help = "ON is inclusive. OFF is exclusive." ]],
output color out = 0
)
{
color out_component;
string traceset_name;
//prep traceset
if (inclusive < 1)
traceset_name = format("-%s", traceset);
else
traceset_name = traceset;
//trace reflection
int hit = trace(P, reflect(I,N), "traceset", traceset_name);
if (hit)
{
//calc trace distance
if (trace_component == "distance" || trace_component == "dist")
{
point trace_P;
getmessage("trace", "P", trace_P);
out = length( (trace_P - P) * abs(N)) / 100;
}
else
{
//get reflected component
int trace_msg = getmessage("trace", trace_component, out_component);
//set to "trace_color" if component doesn't exist
if (trace_msg == 1)
out = out_component;
else
out = trace_color;
}
}
}