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 872 - (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 : glk 790 //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 = 480;
17 :     //int imgResV = 345;
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 :     vec3 camAt = [63.0, 82.6536, 98.0];
25 :     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 : glk 789 int imgResU = 480;
32 :     int imgResV = 345;
33 : glk 790 //int imgResU = 320;
34 :     //int imgResV = 240;
35 :     // HEY (BUG?) do we intend to allow inconsistent redefinitions of things?
36 : glk 789 real rayStep = 0.1;
37 : glk 790 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 : glk 789
41 : glk 693 real camDist = |camAt - camEye|;
42 :     real camVspNear = camDist + camNear;
43 :     real camVspFar = camDist + camFar;
44 : glk 775 vec3 camN = normalize(camAt - camEye);
45 : glk 773 vec3 camU = normalize(camN × camUp);
46 :     vec3 camV = camN × camU;
47 : glk 696 real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
48 : glk 693 real camUmax = camVmax*real(imgResU)/real(imgResV);
49 :    
50 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
51 : glk 773 vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
52 : glk 693
53 :     real phongKa = 0.05;
54 :     real phongKd = 0.80;
55 :     real phongKs = 0.20;
56 :     real phongSp = 30.0;
57 :    
58 :     image(3)[] img = load (dataFile);
59 : jhr 704 //field#4(3)[] F = img ⊛ bspln5;
60 : glk 773 field#2(3)[] F = img ⊛ bspln3;
61 :     //field#1(3)[] F = img ⊛ ctmr;
62 : glk 693 //field#0(3)[] F = img ⊛ tent;
63 :    
64 :     strand RayCast (int ui, int vi)
65 :     {
66 : glk 770 real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
67 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
68 : glk 693 vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
69 :    
70 :     real rayN = camVspNear;
71 :     // ########## BEGIN per-ray initialization
72 :     real transp = 1.0;
73 :     real gray = 0.0;
74 :     output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
75 :     // ########## END per-ray initialization
76 :    
77 :     update
78 :     {
79 :     vec3 rayPos = camEye + rayN*rayVec;
80 :     if (inside (rayPos,F)) {
81 :     // ########## BEGIN per-sample code
82 :     real val = F@rayPos;
83 : glk 773 vec3 grad = ∇F@rayPos; // (here as easy target for optimization)
84 : jhr 765 vec3 norm = normalize(-∇F@rayPos);
85 : glk 693 if (val > valOpacMin) { // we have some opacity
86 : glk 770 real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
87 : glk 775 real ld = norm • lightDir;
88 :     real hd = norm • normalize(lightDir + normalize(camEye - rayPos));
89 : glk 693 real mat = ( phongKa
90 :     + phongKd*(ld if ld > 0.0 else 0.0)
91 : glk 827 + phongKs*(hd^phongSp if hd > 0.0 else 0.0));
92 : glk 693 gray = gray + transp*opac*mat;
93 :     transp = transp*(1.0 - opac);
94 :     }
95 :     // ########## END per-sample code
96 :     }
97 :     if (transp < 0.01) { // early ray termination
98 : glk 780 transp = 0.0;
99 :     rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */
100 :     stabilize;
101 : glk 693 }
102 : jhr 787 if (rayN > camVspFar) {
103 : glk 780 rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */
104 :     stabilize;
105 : glk 693 }
106 : jhr 787 rayN = rayN + rayStep;
107 : glk 693 }
108 :    
109 : glk 780 stabilize {
110 :     // rgba = [gray, gray, gray, 1.0-transp];
111 :     }
112 :    
113 : glk 693 }
114 :    
115 :     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