1 : |
cchiw |
3281 |
|
2 : |
|
|
// set camera, image, and rendering parameters
|
3 : |
|
|
input vec3 camEye = [-1.5015, -3.6392, 5.27097];
|
4 : |
|
|
input vec3 camAt = [0, 0, 0]; // [-0.0455194, 0.0129536, -0.0035959];
|
5 : |
|
|
input vec3 camUp = [0.00940017, 0.298005, 0.954518];
|
6 : |
|
|
input real camNearAtRel = -1.9;
|
7 : |
|
|
input real camFarAtRel = 1.9;
|
8 : |
|
|
input real camFOV = 20;
|
9 : |
|
|
input int iresU = 600;
|
10 : |
|
|
input int iresV = 600;
|
11 : |
|
|
input real refStep = 0.1;
|
12 : |
|
|
input real rayStep = 0.06;
|
13 : |
|
|
input vec3 lightVsp = [-2, -3, -4];
|
14 : |
|
|
input real phongKa = 0.3;
|
15 : |
|
|
input real phongKd = 0.7;
|
16 : |
|
|
input real thickness = 0.1;
|
17 : |
|
|
|
18 : |
|
|
input real isoval = 1800;
|
19 : |
|
|
|
20 : |
|
|
field#4(3)[] V = bspln5 ⊛ image("canny.nrrd");
|
21 : |
|
|
|
22 : |
|
|
|
23 : |
|
|
field#3(3)[3] D = ∇V/|∇V|; // NOTISO (canny) NOTREF
|
24 : |
|
|
field#3(3)[] M = ∇V•∇V; // NOTISO (canny) NOTREF
|
25 : |
|
|
field#2(3)[] F = -∇M • D; // NOTISO (canny) NOTREF
|
26 : |
|
|
input real gmin = 1; // NOTISO (canny & ref)
|
27 : |
|
|
|
28 : |
|
|
|
29 : |
|
|
// field#1(3)[] S = ∇⊗∇M • D • D; // NOTISO
|
30 : |
|
|
// input real smax = -1;// NOTISO
|
31 : |
|
|
|
32 : |
|
|
function real alpha(real v, real g) = clamp(0, 1, 1.2*(1 - |v|/(g*thickness)));
|
33 : |
|
|
field#0(1)[3] cmap = tent ⊛ image("isobow.nrrd");
|
34 : |
|
|
function vec3 color(vec3 x) = cmap(clamp(-3,1,V(x)));
|
35 : |
|
|
|
36 : |
|
|
// (boilerplate) computation of camera and light info
|
37 : |
|
|
real camDist = |camAt - camEye|;
|
38 : |
|
|
real camNear = camNearAtRel + camDist;
|
39 : |
|
|
real camFar = camFarAtRel + camDist;
|
40 : |
|
|
vec3 camN = normalize(camAt - camEye); // away
|
41 : |
|
|
vec3 camU = normalize(camN × camUp); // right
|
42 : |
|
|
vec3 camV = camU × camN; // up
|
43 : |
|
|
real camVmax = tan(camFOV*π/360)*camDist;
|
44 : |
|
|
real camUmax = camVmax*iresU/iresV;
|
45 : |
|
|
vec3 light = transpose([camU,camV,camN])•normalize(lightVsp);
|
46 : |
|
|
|
47 : |
|
|
strand raycast(int ui, int vi) {
|
48 : |
|
|
real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5);
|
49 : |
|
|
real rayV = lerp(camVmax, -camVmax, -0.5, vi, iresV-0.5);
|
50 : |
|
|
real rayN = camNear;
|
51 : |
|
|
vec3 rayVec = camN + (rayU*camU + rayV*camV)/camDist;
|
52 : |
|
|
real transp = 1;
|
53 : |
|
|
vec3 rgb = [0,0,0];
|
54 : |
|
|
output vec4 rgba = [0,0,0,0];
|
55 : |
|
|
|
56 : |
|
|
update {
|
57 : |
|
|
vec3 x = camEye + rayN*rayVec;
|
58 : |
|
|
if (inside(x,V) && |∇V(x)| > gmin) { // NOTISO (canny & ref)
|
59 : |
|
|
|
60 : |
|
|
real val = F(x); // (iso & canny) NOTREF
|
61 : |
|
|
vec3 grad = -∇F(x); // (iso & canny) NOTREF
|
62 : |
|
|
|
63 : |
|
|
|
64 : |
|
|
real a = alpha(val, |grad|);
|
65 : |
|
|
if (a > 0) { // we have some opacity
|
66 : |
|
|
a = 1 - pow(1-a, rayStep*|rayVec|/refStep);
|
67 : |
|
|
real depth = lerp(1.3, 0.6, camNear, rayN, camFar);
|
68 : |
|
|
real shade = max(0, normalize(grad)•light);
|
69 : |
|
|
rgb += transp*depth*a*(phongKa + phongKd*shade)*color(x);
|
70 : |
|
|
transp *= 1 - a;
|
71 : |
|
|
}
|
72 : |
|
|
}
|
73 : |
|
|
if (transp < 0.01) { // early ray termination
|
74 : |
|
|
transp = 0;
|
75 : |
|
|
stabilize;
|
76 : |
|
|
}
|
77 : |
|
|
if (rayN > camFar) {
|
78 : |
|
|
stabilize;
|
79 : |
|
|
}
|
80 : |
|
|
rayN = rayN + rayStep;
|
81 : |
|
|
}
|
82 : |
|
|
stabilize {
|
83 : |
|
|
real a = 1-transp;
|
84 : |
|
|
if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a];
|
85 : |
|
|
}
|
86 : |
|
|
}
|
87 : |
|
|
initially [ raycast(ui, vi) | vi in 0..iresV-1, ui in 0..iresU-1 ];
|