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 827 - (view) (download)

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