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

SCM Repository

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

Annotation of /branches/pure-cfg/test/vr-lite-cam.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 694 - (view) (download)

1 : glk 693 // vr-lite-cam
2 :     //
3 :     // simple volume renderer, now with a single directional light,
4 :     // Phong shading, and the new camera.
5 :     //
6 :     // The main thing missing from this is a more general
7 :     // transfer function
8 :    
9 :     //string dataFile = "../data/txs-pad3.nrrd";
10 :     //vec3 camEye = [25.0, 15.0, 10.0];
11 :     //vec3 camAt = [3.0, 3.0, 3.0];
12 :     //vec3 camUp = [0.0, 0.0, 1.0];
13 :     //real camNear = -5.0;
14 :     //real camFar = 5.0;
15 :     //real camFOV = 18.0;
16 :     //int imgResU = 320;
17 :     //int imgResV = 240;
18 :     //real rayStep = 0.1;
19 :     //real valOpacMin = 0.20; // highest value with opacity 0.0
20 :     //real valOpacMax = 0.25; // lowest value with opacity 1.0
21 :    
22 :     string dataFile = "../data/vfrhand-nohip.nhdr";
23 :     vec3 camEye = [127.331, -1322.05, 272.53];
24 : glk 694 vec3 camAt = [63.0, 82.6536, 98.0];
25 : glk 693 vec3 camUp = [0.9987, 0.0459166, -0.0221267];
26 :     real camNear = -78.0;
27 :     real camFar = 78.0;
28 :     real camFOV = 5.0;
29 :     //int imgResU = 640;
30 :     //int imgResV = 480;
31 :     int imgResU = 480;
32 :     int imgResV = 345;
33 :     //int imgResU = 320;
34 :     //int imgResV = 240;
35 :     // HEY (BUG?) do we intend to allow inconsistent redefinitions of things?
36 :     real rayStep = 0.1;
37 :     real rayStep = 0.5;
38 :     real valOpacMin = 400.0; // 400.0 for skin, 1150.0 for bone
39 :     real valOpacMax = 700.0; // 700.0 for skin, 1450.0 for bone
40 :    
41 :     // HEY: update this camera code when possible, based on eventual
42 :     // improvements to mip-cam.diderot
43 :     real camDist = |camAt - camEye|;
44 :     real camVspNear = camDist + camNear;
45 :     real camVspFar = camDist + camFar;
46 :     vec3 camN = (camAt - camEye)/camDist;
47 :     vec3 tmp0 = cross(camN,camUp);
48 :     vec3 camU = tmp0/|tmp0|;
49 :     vec3 camV = cross(camN,camU);
50 :     real tmp1 = camFOV*3.1415926536/360.0;
51 :     real camVmax = sin(tmp1)/cos(tmp1)*camDist;
52 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
53 :    
54 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
55 :     // HEY (want) ability to access components of a vector (e.g. "vec[0]")
56 :     // would make this transform to world-space less awkward; would be
57 :     // lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN
58 :     // OR, we could create and apply a view-to-world matrix transform
59 :     vec3 tmp2 = ( dot(lightVspDir,[1.0,0.0,0.0])*camU
60 :     + dot(lightVspDir,[0.0,1.0,0.0])*camV
61 :     + dot(lightVspDir,[0.0,0.0,1.0])*camN);
62 :     vec3 lightDir = tmp2/|tmp2|;
63 :    
64 :     real phongKa = 0.05;
65 :     real phongKd = 0.80;
66 :     real phongKs = 0.20;
67 :     real phongSp = 30.0;
68 :    
69 :     image(3)[] img = load (dataFile);
70 :     //field#2(3)[] F = img ⊛ bspln3;
71 :     field#2(3)[] F = img ⊛ bspln3;
72 :     // HEY (BUG): ctmr Catmull-Rom is C1 but not C2 continuous
73 :     //field#2(3)[] F = img ⊛ ctmr;
74 :     //field#0(3)[] F = img ⊛ tent;
75 :    
76 :     strand RayCast (int ui, int vi)
77 :     {
78 :     real rayU = 2.0*camUmax*(real(ui) + 0.5)/real(imgResU) - camUmax;
79 :     real rayV = 2.0*camVmax*(real(vi) + 0.5)/real(imgResV) - camVmax;
80 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
81 :     vec3 rayDir = rayVec/|rayVec|;
82 :    
83 :     real rayN = camVspNear;
84 :     // ########## BEGIN per-ray initialization
85 :     real transp = 1.0;
86 :     real gray = 0.0;
87 :     output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
88 :     // ########## END per-ray initialization
89 :    
90 :     update
91 :     {
92 :     vec3 rayPos = camEye + rayN*rayVec;
93 :     if (inside (rayPos,F)) {
94 :     // ########## BEGIN per-sample code
95 :     real val = F@rayPos;
96 :     vec3 grad = ∇F@rayPos;
97 :     vec3 norm = -grad/|grad|;
98 :     // HEY (BUG) will get an "uncaught exception" if code is instead
99 :     // vec3 norm = -∇F@rayPos/|∇F@rayPos|;
100 :     if (val > valOpacMin) { // we have some opacity
101 :     real opac =
102 :     1.0 if (val > valOpacMax)
103 :     else (val - valOpacMin)/(valOpacMax - valOpacMin);
104 :     real ld = dot(lightDir,norm);
105 :     real mat = ( phongKa
106 :     + phongKd*(ld if ld > 0.0 else 0.0)
107 :     + phongKs*(pow(ld, phongSp) if ld > 0.0 else 0.0));
108 :     gray = gray + transp*opac*mat;
109 :     transp = transp*(1.0 - opac);
110 :     }
111 :     // ########## END per-sample code
112 :     }
113 :     if (transp < 0.01) { // early ray termination
114 :     rgba = [gray, gray, gray, 1.0];
115 :     stabilize;
116 :     }
117 :     if (rayN > camVspFar) {
118 :     rgba = [gray, gray, gray, 1.0-transp];
119 :     stabilize;
120 :     }
121 :     rayN = rayN + rayStep;
122 :     }
123 :    
124 :     /* render: output maxval */
125 :     }
126 :    
127 :     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