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

SCM Repository

[diderot] Annotation of /branches/lamont/test/vr-kcomp.diderot
ViewVC logotype

Annotation of /branches/lamont/test/vr-kcomp.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1115 - (view) (download)
Original Path: trunk/test/vr-kcomp.diderot

1 : jhr 1115 // process output with:
2 :     // unu reshape -i mip.txt -s 4 200 200 | overrgb -i - -b 0.1 0.15 0.2 -o - | unu quantize -b 8 -min 0 -max 255 -o vr-kcomp.png
3 :    
4 :     vec3 camEye = [25.0, 10.0, 8.0];
5 :     vec3 camAt = [0.0, 0.0, 0.0];
6 :     vec3 camUp = [0.0, 0.0, 1.0];
7 :     real camNear = -1.0;
8 :     real camFar = 1.0;
9 :     real camFOV = 4.5;
10 :     int imgResU = 200;
11 :     int imgResV = 200;
12 :     real rayStep = 0.01;
13 :     real valOpacMin = 0.08; // highest value with opacity 0.0
14 :     real valOpacMax = 0.09; // lowest value with opacity 1.0
15 :    
16 :     real camDist = |camAt - camEye|;
17 :     real camVspNear = camNear + camDist;
18 :     real camVspFar = camFar + camDist;
19 :     vec3 camN = normalize(camAt - camEye);
20 :     vec3 camU = normalize(camN × camUp);
21 :     vec3 camV = camN × camU;
22 :     real camVmax = tan(camFOV*π/360.0)*camDist;
23 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
24 :    
25 :     vec3 lightVspDir = [-1.0, -1.0, -3.5];
26 :     vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
27 :    
28 :     real phongKa = 0.02;
29 :     real phongKd = 0.60;
30 :     real phongKs = 0.40;
31 :     real phongSp = 30.0;
32 :    
33 :     image(3)[] img = load ("../data/vox1-9.nrrd");
34 :     field#1(3)[] Fc1 = img ⊛ ctmr;
35 :     field#1(3)[] Fc0 = img ⊛ c1tent;
36 :    
37 :     strand RayCast (int ui, int vi)
38 :     {
39 :     real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
40 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
41 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
42 :    
43 :     real rayN = camVspNear;
44 :     // ########## BEGIN per-ray initialization
45 :     real transp = 1.0;
46 :     real gray = 0.0;
47 :     output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
48 :     // ########## END per-ray initialization
49 :    
50 :     update
51 :     {
52 :     vec3 rayPos = camEye + rayN*rayVec;
53 :     if (inside (rayPos,Fc1)) {
54 :     // ########## BEGIN per-sample code
55 :     real val = 0.0;
56 :     vec3 norm = [0.0,0.0,0.0];
57 :     // HEY (scoping BUG): the strand parameters (e.g. ui, vi) can't
58 :     // appear in conditional below "if (ui + vi < imgResU)"
59 :     if (ui + vi < imgResU) {
60 :     val = Fc0@rayPos;
61 :     norm = normalize(-∇Fc0@rayPos);
62 :     } else {
63 :     val = Fc1@rayPos;
64 :     norm = normalize(-∇Fc1@rayPos);
65 :     }
66 :     if (val > valOpacMin) { // we have some opacity
67 :     real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
68 :     real ld = lightDir • norm;
69 :     real hd = norm • normalize(lightDir + normalize(camEye - rayPos));
70 :     real mat = ( phongKa
71 :     + phongKd*(ld if ld > 0.0 else 0.0)
72 :     + phongKs*(hd^phongSp if hd > 0.0 else 0.0));
73 :     gray = gray + transp*opac*mat;
74 :     transp = transp*(1.0 - opac);
75 :     }
76 :     // ########## END per-sample code
77 :     }
78 :     if (transp < 0.01) { // early ray termination
79 :     transp = 0.0;
80 :     // HEY (BUG) stabilize function not working
81 :     // setting rgba should be done there
82 :     rgba = [gray, gray, gray, 1.0-transp];
83 :     stabilize;
84 :     }
85 :     if (rayN > camVspFar) {
86 :     // HEY (BUG) (same as above)
87 :     rgba = [gray, gray, gray, 1.0-transp];
88 :     stabilize;
89 :     }
90 :     rayN = rayN + rayStep;
91 :     }
92 :    
93 :     stabilize {
94 :     // rgba = [gray, gray, gray, 1.0-transp];
95 :     }
96 :    
97 :     /* render: output maxval */
98 :     }
99 :    
100 :     initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ];

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