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 776 - (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 770 real camFOV = 5.0;
7 : glk 746 int imgResU = 200;
8 :     int imgResV = 200;
9 :     real rayStep = 0.01;
10 : glk 770 real valOpacMin = 0.05; // highest value with opacity 0.0
11 :     real valOpacMax = 0.06; // 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 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
23 : glk 776 vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
24 : glk 746
25 :     real phongKa = 0.05;
26 :     real phongKd = 0.80;
27 :     real phongKs = 0.20;
28 :     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 : glk 746 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 grad = [0.0,0.0,0.0];
57 : glk 770 // HEY (scoping BUG): the strand parameters (e.g. ui, vi) can't
58 : glk 746 // appear in conditionals
59 : glk 770 if (myui + myvi < imgResU) {
60 : glk 746 val = Fc0@rayPos;
61 :     grad = ∇Fc0@rayPos;
62 :     } else {
63 :     val = Fc1@rayPos;
64 :     grad = ∇Fc1@rayPos;
65 :     }
66 : glk 776 vec3 norm = normalize(-grad);
67 : glk 746 if (val > valOpacMin) { // we have some opacity
68 : glk 770 real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
69 : glk 776 real ld = lightDir • norm;
70 : glk 746 real mat = ( phongKa
71 :     + phongKd*(ld if ld > 0.0 else 0.0)
72 :     + phongKs*(pow(ld, phongSp) if ld > 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 :     rgba = [gray, gray, gray, 1.0];
80 :     stabilize;
81 :     }
82 :     if (rayN > camVspFar) {
83 :     rgba = [gray, gray, gray, 1.0-transp];
84 :     stabilize;
85 :     }
86 :     rayN = rayN + rayStep;
87 :     }
88 :    
89 :     /* render: output maxval */
90 :     }
91 :    
92 :     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