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

SCM Repository

[diderot] Annotation of /branches/vis12/bugs/resolved/bug042.diderot
ViewVC logotype

Annotation of /branches/vis12/bugs/resolved/bug042.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3322 - (view) (download)

1 : glk 3294 /*
2 :     compiling with: ../../bin/diderotc --exec bug042.diderot
3 :     produces error:
4 :    
5 :     uncaught exception Fail [Fail: lookup(_, l__t_217)]
6 :     raised at common/phase-timer.sml:78.50-78.52
7 :     raised at common/phase-timer.sml:78.50-78.52
8 :     raised at c-util/tree-to-c.sml:69.29-69.70
9 :    
10 :     */
11 :     // set camera, image, and rendering parameters
12 :     input vec3 camEye = [0.09, 0, 10];
13 :     input vec3 camAt = [0.09, 0, 0];
14 :     input vec3 camUp = [-1, 0, 0];
15 :     input real camNearAtRel = -0.45;
16 :     input real camFarAtRel = 0.45;
17 :     input real camFOV = 4.85;
18 :     input int iresU = 450;
19 :     input int iresV = 200;
20 :     input real refStep = 0.005;
21 :     input real rayStep = 0.005;
22 :     input vec3 lightVsp = [-2, -3, -4];
23 :     input real phongKa = 0.3;
24 :     input real phongKd = 0.7;
25 :     input real thickness = 0.017;
26 :    
27 :     input real isoval = -0.1;
28 :    
29 :     field#2(3)[] F = c4hexic ⊛ image("../data/wee-torus.nrrd");
30 :    
31 :     function real alpha(real v, real g) = max(0, 1 - |v/g|/thickness);
32 :    
33 :     // (boilerplate) computation of camera and light info
34 :     real camDist = |camAt - camEye|;
35 :     real camNear = camNearAtRel + camDist;
36 :     real camFar = camFarAtRel + camDist;
37 :     vec3 camN = normalize(camAt - camEye); // away
38 :     vec3 camU = normalize(camN × camUp); // right
39 :     vec3 camV = camU × camN; // up
40 :     real camVmax = tan(camFOV*π/360)*camDist;
41 :     real camUmax = camVmax*iresU/iresV;
42 :     vec3 light = transpose([camU,camV,camN])•normalize(lightVsp);
43 :    
44 :     strand raycast(int ui, int vi) {
45 :     real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5);
46 :     real rayV = lerp(camVmax, -camVmax, -0.5, vi, iresV-0.5);
47 :     real rayN = camNear;
48 :     vec3 rayVec = camN + (rayU*camU + rayV*camV)/camDist;
49 :     real transp = 1;
50 :     vec3 rgb = [0,0,0];
51 :     output vec4 rgba = [0,0,0,0];
52 :    
53 :     update {
54 :     vec3 x = camEye + rayN*rayVec;
55 :     if (inside(x,F)) {
56 :     vec3 grad = -∇F(x);
57 :     real a = 0;
58 :     real val = F(x) - isoval;
59 :     a = alpha(val, |grad|);
60 :     if (a > 0) { // we have some opacity
61 :     a = 1 - pow(1-a, rayStep*|rayVec|/refStep);
62 :     real depth = lerp(1.3, 0.6, camNear, rayN, camFar);
63 :     real shade = max(0, normalize(grad)•light);
64 :     rgb += transp*depth*a*(phongKa + phongKd*shade)*[1,1,1];
65 :     transp *= 1 - a;
66 :     }
67 :     }
68 :     if (transp < 0.01) { // early ray termination
69 :     transp = 0;
70 :     stabilize;
71 :     }
72 :     if (rayN > camFar) {
73 :     stabilize;
74 :     }
75 :     rayN = rayN + rayStep;
76 :     }
77 :     stabilize {
78 :     real a = 1-transp;
79 :     if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a];
80 :     }
81 :     }
82 :     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