-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.sl
More file actions
122 lines (103 loc) · 2.68 KB
/
bench.sl
File metadata and controls
122 lines (103 loc) · 2.68 KB
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
/* see readme.txt for copyright info */
/* attempt to stress the shader interpreter
this is a modified version of the Mandelbrot fractal
algorithm, with noise() called for each iteration
as an option. */
color shader_bench(float u; float v; float call_noise )
{
float i;
float x = 0, y = 0;
float MAXIT = 256; /* max # of iterations */
for(i = 0; i < MAXIT; i += 1) {
float oldx = x, oldy = y;
/* Z = Z^2 + C */
x = oldx*oldx - oldy*oldy + u;
y = 2*oldx*oldy + v;
/* throw in some noise just for fun */
if( call_noise == 1 )
{
point noiz = point noise(point(10*x, 10*y, 0));
x += 0.07*xcomp(noiz);
y += 0.07*ycomp(noiz);
}
/* check for escape */
float rsquared = x*x + y*y;
if(rsquared > 10) {
break;
}
}
/* output of Mandelbrot iteration */
float c = i/MAXIT;
return color spline(pow(1-c, 2),
color(0),
color(0),
color(1, 0, 0),
color(0, 0, 1),
color(1),
color(1));
}
surface bench(
string mode = "simple";
float samples = 16; /* only used in raytrace modes */
float ray_bias = 0.001;
float call_noise = 1;
float modulate_opacity = 0;)
{
normal NN = normalize(N);
Oi = Os;
if(mode == "raydiff") {
/* diffuse raytracing (ambient occlusion) test */
float occ = occlusion(P, NN,
samples,
"adaptive", 1,
"maxerror", 0,
"bias", ray_bias,
"maxdist", 5000);
Ci = Oi * (1-occ);
} else if(mode == "rayspec") {
/* specular raytracing (raytraced reflections) test */
/* get ray depth */
float depth;
rayinfo("depth", depth);
if(depth > 1) {
/* don't recurse more than once */
Ci = color(0);
} else {
float maxsamples, minsamples, coneangle;
if(depth == 0) {
/* initial ray bundle, use normal # of samples */
maxsamples = samples;
minsamples = samples/4;
coneangle = radians(2.5);
} else {
/* secondary ray shots, use only 1 sample */
maxsamples = 1;
minsamples = 1;
coneangle = 0;
}
vector II = normalize(I);
/* shoot the rays */
color hitcolor = 0, total = 0;
gather("illuminance", P, reflect(II, NN), coneangle, maxsamples,
"distribution", "uniform", "bias", ray_bias,
"surface:Ci", hitcolor) {
/* hit */
total += hitcolor;
} else {
/* miss */
total += color(1);
}
total /= maxsamples;
Ci = Oi * total;
}
} else if(mode == "shader") {
/* shader interpreter stress test */
point oP = transform("object", P);
Ci = Oi * shader_bench(xcomp(oP), ycomp(oP), call_noise);
} else if(mode == "simple") {
/* quick shader for hider test */
Ci = Oi * (diffuse(NN) + ambient());
}
if( modulate_opacity != 0 )
Oi *= noise(u,v)*0.1;
}