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

SCM Repository

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

Annotation of /branches/pure-cfg/test/vr-kcomp.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1021 - (view) (download)

1 : glk 887 // 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 : glk 746 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 : glk 778 real camFOV = 4.5;
10 : glk 746 int imgResU = 200;
11 :     int imgResV = 200;
12 :     real rayStep = 0.01;
13 : glk 778 real valOpacMin = 0.08; // highest value with opacity 0.0
14 :     real valOpacMax = 0.09; // lowest value with opacity 1.0
15 : glk 746
16 :     real camDist = |camAt - camEye|;
17 : glk 776 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 : glk 746 real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
23 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
24 :    
25 : glk 778 vec3 lightVspDir = [-1.0, -1.0, -3.5];
26 : glk 776 vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
27 : glk 746
28 : glk 778 real phongKa = 0.02;
29 :     real phongKd = 0.60;
30 :     real phongKs = 0.40;
31 : glk 746 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 : glk 770 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 : glk 746 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 : glk 791 vec3 norm = [0.0,0.0,0.0];
57 : glk 770 // HEY (scoping BUG): the strand parameters (e.g. ui, vi) can't
58 : glk 887 // appear in conditional below "if (ui + vi < imgResU)"
59 : glk 1021 if (ui + vi < imgResU) {
60 : glk 887 val = Fc0@rayPos;
61 :     norm = normalize(-∇Fc0@rayPos);
62 : glk 746 } else {
63 : glk 887 val = Fc1@rayPos;
64 :     norm = normalize(-∇Fc1@rayPos);
65 : glk 746 }
66 :     if (val > valOpacMin) { // we have some opacity
67 : glk 770 real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
68 : glk 776 real ld = lightDir • norm;
69 : glk 778 real hd = norm • normalize(lightDir + normalize(camEye - rayPos));
70 : glk 746 real mat = ( phongKa
71 :     + phongKd*(ld if ld > 0.0 else 0.0)
72 : glk 827 + phongKs*(hd^phongSp if hd > 0.0 else 0.0));
73 : glk 746 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 : glk 779 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 : glk 746 stabilize;
84 :     }
85 :     if (rayN > camVspFar) {
86 : glk 779 // HEY (BUG) (same as above)
87 : glk 746 rgba = [gray, gray, gray, 1.0-transp];
88 :     stabilize;
89 :     }
90 :     rayN = rayN + rayStep;
91 :     }
92 :    
93 : glk 779 stabilize {
94 :     // rgba = [gray, gray, gray, 1.0-transp];
95 :     }
96 :    
97 : glk 746 /* 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