1 : |
cchiw |
3281 |
|
2 : |
|
|
// set camera, image, and rendering parameters
|
3 : |
|
|
input vec3 camEye = [-194.602, -4.82922, 910.873];
|
4 : |
|
|
input vec3 camAt = [-2.36389, 93.121, 661.166];
|
5 : |
|
|
input vec3 camUp = [0.0745335, -0.946525, -0.313904];
|
6 : |
|
|
input real camNearAtRel = -50;
|
7 : |
|
|
input real camFarAtRel = 20;
|
8 : |
|
|
input real camFOV = 15.5;
|
9 : |
|
|
input int iresU = 410;
|
10 : |
|
|
input int iresV = 450;
|
11 : |
|
|
input real refStep = 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.3;
|
17 : |
|
|
|
18 : |
|
|
field#4(3)[] V = bspln5 ⊛ image("moe-iso-b3i5-small.nrrd");
|
19 : |
|
|
field#0(3)[3] g= ∇V;
|
20 : |
|
|
field#0(3)[3,3] H = ∇⊗∇V;
|
21 : |
|
|
field#0(3)[3,3,3] T = ∇⊗∇⊗∇V;
|
22 : |
|
|
|
23 : |
|
|
//tmp
|
24 : |
|
|
field#0(3)[] M = |g|;
|
25 : |
|
|
field#0(3)[3] N = g/M;
|
26 : |
|
|
field#0(3)[3] t0 = g•H+ H•g;
|
27 : |
|
|
field#0(3)[3] t2 = (1/2)*t0/M;
|
28 : |
|
|
field#0(3)[3,3] t3 = H•H+ g•T+ T•g+H•H;
|
29 : |
|
|
field#0(3)[3,3] t5 =(1/2)*(t3*M-t0⊗t2)/(M*M);
|
30 : |
|
|
|
31 : |
|
|
|
32 : |
|
|
field#0(3)[3,3] t4 = (H*M- g⊗t2)/M*M; // ∇N
|
33 : |
|
|
field#0(3)[] S = N•t5•N; // ∇V/|∇V| • ∇⊗∇(|∇V|) • ∇V/|∇V|
|
34 : |
|
|
field#0(3)[] F = -t2•N; //-∇(|∇V|) • ∇V/|∇V|;
|
35 : |
|
|
field#0(3)[3] dF =(-1/2)*(((t0/M)•t4)+N•t3);
|
36 : |
|
|
|
37 : |
|
|
input real smax = -10;
|
38 : |
|
|
|
39 : |
|
|
function real alpha(real v, real g) = clamp(0, 1, 1.3*(1 - |v|/(g*thickness)));
|
40 : |
|
|
field#0(1)[3] cmap = tent ⊛ image("moe-isobow.nrrd");
|
41 : |
|
|
function vec3 color(vec3 x) = cmap(clamp(-1200,3300,V(x)));
|
42 : |
|
|
function real mask(vec3 x) = 1.0 if (S(x) < smax) else 0.0; // NOTISO
|
43 : |
|
|
|
44 : |
|
|
// (boilerplate) computation of camera and light info
|
45 : |
|
|
real camDist = |camAt - camEye|;
|
46 : |
|
|
real camNear = camNearAtRel + camDist;
|
47 : |
|
|
real camFar = camFarAtRel + camDist;
|
48 : |
|
|
vec3 camN = normalize(camAt - camEye); // away
|
49 : |
|
|
vec3 camU = normalize(camN × camUp); // right
|
50 : |
|
|
vec3 camV = camU × camN; // up
|
51 : |
|
|
real camVmax = tan(camFOV*π/360)*camDist;
|
52 : |
|
|
real camUmax = camVmax*iresU/iresV;
|
53 : |
|
|
vec3 light = transpose([camU,camV,camN])•normalize(lightVsp);
|
54 : |
|
|
|
55 : |
|
|
strand raycast(int ui, int vi) {
|
56 : |
|
|
real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5);
|
57 : |
|
|
real rayV = lerp(camVmax, -camVmax, -0.5, vi, iresV-0.5);
|
58 : |
|
|
real rayN = camNear;
|
59 : |
|
|
vec3 rayVec = camN + (rayU*camU + rayV*camV)/camDist;
|
60 : |
|
|
real transp = 1;
|
61 : |
|
|
vec3 rgb = [0,0,0];
|
62 : |
|
|
output vec4 rgba = [0,0,0,0];
|
63 : |
|
|
|
64 : |
|
|
update {
|
65 : |
|
|
vec3 x = camEye + rayN*rayVec;
|
66 : |
|
|
if (inside(x,V)) {
|
67 : |
|
|
real val = F(x);
|
68 : |
|
|
vec3 grad = -dF(x);
|
69 : |
|
|
real a = alpha(val, |grad|)*mask(x);
|
70 : |
|
|
if (a > 0) { // we have some opacity
|
71 : |
|
|
a = 1 - pow(1-a, rayStep*|rayVec|/refStep);
|
72 : |
|
|
real depth = lerp(1.1, 0.7, camNear, rayN, camFar);
|
73 : |
|
|
real shade = max(0, normalize(grad)•light);
|
74 : |
|
|
rgb += transp*a*depth*(phongKa + phongKd*shade)*color(x);
|
75 : |
|
|
transp *= 1 - a;
|
76 : |
|
|
}
|
77 : |
|
|
}
|
78 : |
|
|
if (transp < 0.01) { // early ray termination
|
79 : |
|
|
transp = 0;
|
80 : |
|
|
stabilize;
|
81 : |
|
|
}
|
82 : |
|
|
if (rayN > camFar) {
|
83 : |
|
|
stabilize;
|
84 : |
|
|
}
|
85 : |
|
|
rayN = rayN + rayStep;
|
86 : |
|
|
}
|
87 : |
|
|
stabilize {
|
88 : |
|
|
real a = 1-transp;
|
89 : |
|
|
if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a];
|
90 : |
|
|
}
|
91 : |
|
|
}
|
92 : |
|
|
initially [ raycast(ui, vi) | vi in 0..iresV-1, ui in 0..iresU-1 ];
|