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
|
struct ClosureDiffuse {
vec3 color;
vec3 N;
vec3 sss_radius;
uint sss_id;
};
struct ClosureReflection {
vec3 color;
vec3 N;
float roughness;
};
struct ClosureRefraction {
vec3 color;
vec3 N;
float roughness;
float ior;
};
struct ClosureVolume {
vec3 emission;
vec3 scattering;
vec3 transmittance;
float anisotropy;
};
struct ClosureEmission {
vec3 emission;
};
struct ClosureTransparency {
vec3 transmittance;
float holdout;
};
/* We use the weight tree pre-evaluation to weight the closures.
* There is no need for the Closure type. */
struct Closure {
float dummy;
};
#define CLOSURE_DEFAULT Closure(0.0)
#define closure_add(a, b) CLOSURE_DEFAULT
#define closure_mix(a, b, c) CLOSURE_DEFAULT
/* Store weight in red channel. Store negative to differentiate with evaluated closure. */
void closure_weight_add(inout ClosureDiffuse closure, float weight)
{
closure.color.r -= weight;
}
void closure_weight_add(inout ClosureReflection closure, float weight)
{
closure.color.r -= weight;
}
void closure_weight_add(inout ClosureRefraction closure, float weight)
{
closure.color.r -= weight;
}
/* Create a random threshold inside the weight range. */
void closure_weight_randomize(inout ClosureDiffuse closure, float randu)
{
closure.color.g = closure.color.r * randu;
}
void closure_weight_randomize(inout ClosureReflection closure, float randu)
{
closure.color.g = closure.color.r * randu;
}
void closure_weight_randomize(inout ClosureRefraction closure, float randu)
{
closure.color.g = closure.color.r * randu;
}
bool closure_weight_threshold(inout ClosureDiffuse closure, inout float weight)
{
/* Decrement weight from random threshold. */
closure.color.g += weight;
/* Evaluate this closure if threshold reaches 0. */
if (closure.color.g >= 0.0) {
/* Returns the sum of all weights. */
weight = abs(closure.color.r);
return true;
}
return false;
}
bool closure_weight_threshold(inout ClosureReflection closure, inout float weight)
{
closure.color.g += weight;
if (closure.color.g >= 0.0) {
weight = abs(closure.color.r);
return true;
}
return false;
}
bool closure_weight_threshold(inout ClosureRefraction closure, inout float weight)
{
closure.color.g += weight;
if (closure.color.g >= 0.0) {
weight = abs(closure.color.r);
return true;
}
return false;
}
|