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

SCM Repository

[diderot] Annotation of /tests/glk-tests/orig/moe-vr-can2.diderot
ViewVC logotype

Annotation of /tests/glk-tests/orig/moe-vr-can2.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4640 - (view) (download)

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