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 704 - (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 : glk 696 real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
51 : glk 693 real camUmax = camVmax*real(imgResU)/real(imgResV);
52 :    
53 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
54 :     // HEY (want) ability to access components of a vector (e.g. "vec[0]")
55 :     // would make this transform to world-space less awkward; would be
56 :     // lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN
57 :     // OR, we could create and apply a view-to-world matrix transform
58 : jhr 704 //vec3 tmp2 = lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN;
59 : glk 693 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 : jhr 704 //field#4(3)[] F = img ⊛ bspln5;
71 : glk 693 //field#2(3)[] F = img ⊛ bspln3;
72 : jhr 704 field#1(3)[] F = img ⊛ ctmr;
73 : glk 693 //field#0(3)[] F = img ⊛ tent;
74 :    
75 :     strand RayCast (int ui, int vi)
76 :     {
77 :     real rayU = 2.0*camUmax*(real(ui) + 0.5)/real(imgResU) - camUmax;
78 :     real rayV = 2.0*camVmax*(real(vi) + 0.5)/real(imgResV) - camVmax;
79 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
80 :     vec3 rayDir = rayVec/|rayVec|;
81 :    
82 :     real rayN = camVspNear;
83 :     // ########## BEGIN per-ray initialization
84 :     real transp = 1.0;
85 :     real gray = 0.0;
86 :     output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
87 :     // ########## END per-ray initialization
88 :    
89 :     update
90 :     {
91 :     vec3 rayPos = camEye + rayN*rayVec;
92 :     if (inside (rayPos,F)) {
93 :     // ########## BEGIN per-sample code
94 :     real val = F@rayPos;
95 :     vec3 grad = ∇F@rayPos;
96 : jhr 704 vec3 norm = -∇F@rayPos/|∇F@rayPos|;
97 : glk 693 if (val > valOpacMin) { // we have some opacity
98 :     real opac =
99 :     1.0 if (val > valOpacMax)
100 :     else (val - valOpacMin)/(valOpacMax - valOpacMin);
101 :     real ld = dot(lightDir,norm);
102 :     real mat = ( phongKa
103 :     + phongKd*(ld if ld > 0.0 else 0.0)
104 :     + phongKs*(pow(ld, phongSp) if ld > 0.0 else 0.0));
105 :     gray = gray + transp*opac*mat;
106 :     transp = transp*(1.0 - opac);
107 :     }
108 :     // ########## END per-sample code
109 :     }
110 :     if (transp < 0.01) { // early ray termination
111 :     rgba = [gray, gray, gray, 1.0];
112 :     stabilize;
113 :     }
114 :     if (rayN > camVspFar) {
115 :     rgba = [gray, gray, gray, 1.0-transp];
116 :     stabilize;
117 :     }
118 :     rayN = rayN + rayStep;
119 :     }
120 :    
121 :     /* render: output maxval */
122 :     }
123 :    
124 :     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