Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/charisee_dev/examples/moe/moe-byhand.diderot
ViewVC logotype

Annotation of /branches/charisee_dev/examples/moe/moe-byhand.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3313 - (view) (download)

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

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0