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 770 - (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 :     // HEY: update this camera code when possible, based on eventual
14 :     // improvements to mip-cam.diderot
15 :     real camDist = |camAt - camEye|;
16 :     real camVspNear = camDist + camNear;
17 :     real camVspFar = camDist + camFar;
18 :     vec3 camN = (camAt - camEye)/camDist;
19 :     vec3 tmp0 = cross(camN,camUp);
20 :     vec3 camU = tmp0/|tmp0|;
21 :     vec3 camV = cross(camN,camU);
22 :     real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
23 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
24 :    
25 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
26 :     vec3 tmp2 = lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN;
27 :     vec3 lightDir = tmp2/|tmp2|;
28 :    
29 :     real phongKa = 0.05;
30 :     real phongKd = 0.80;
31 :     real phongKs = 0.20;
32 :     real phongSp = 30.0;
33 :    
34 :     image(3)[] img = load ("../data/vox1-9.nrrd");
35 :     field#1(3)[] Fc1 = img ⊛ ctmr;
36 :     field#1(3)[] Fc0 = img ⊛ c1tent;
37 :    
38 :     strand RayCast (int ui, int vi)
39 :     {
40 : glk 770 real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
41 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
42 : glk 746 vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
43 :     vec3 rayDir = rayVec/|rayVec|;
44 :    
45 :     real rayN = camVspNear;
46 :     // ########## BEGIN per-ray initialization
47 :     real transp = 1.0;
48 :     real gray = 0.0;
49 : glk 770 int myui = ui;
50 :     int myvi = vi;
51 : glk 746 output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
52 :     // ########## END per-ray initialization
53 :    
54 :     update
55 :     {
56 :     vec3 rayPos = camEye + rayN*rayVec;
57 :     if (inside (rayPos,Fc1)) {
58 :     // ########## BEGIN per-sample code
59 :     real val = 0.0;
60 :     vec3 grad = [0.0,0.0,0.0];
61 : glk 770 // HEY (scoping BUG): the strand parameters (e.g. ui, vi) can't
62 : glk 746 // appear in conditionals
63 : glk 770 if (myui + myvi < imgResU) {
64 : glk 746 val = Fc0@rayPos;
65 :     grad = ∇Fc0@rayPos;
66 :     } else {
67 :     val = Fc1@rayPos;
68 :     grad = ∇Fc1@rayPos;
69 :     }
70 :     vec3 norm = -grad/|grad|;
71 :     if (val > valOpacMin) { // we have some opacity
72 : glk 770 real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
73 : glk 746 real ld = dot(lightDir,norm);
74 :     real mat = ( phongKa
75 :     + phongKd*(ld if ld > 0.0 else 0.0)
76 :     + phongKs*(pow(ld, phongSp) if ld > 0.0 else 0.0));
77 :     gray = gray + transp*opac*mat;
78 :     transp = transp*(1.0 - opac);
79 :     }
80 :     // ########## END per-sample code
81 :     }
82 :     if (transp < 0.01) { // early ray termination
83 :     rgba = [gray, gray, gray, 1.0];
84 :     stabilize;
85 :     }
86 :     if (rayN > camVspFar) {
87 :     rgba = [gray, gray, gray, 1.0-transp];
88 :     stabilize;
89 :     }
90 :     rayN = rayN + rayStep;
91 :     }
92 :    
93 :     /* render: output maxval */
94 :     }
95 :    
96 :     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