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 789 - (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 789 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 775 //int imgResU = 480;
32 :     //int imgResV = 345;
33 : glk 789 ////int imgResU = 320;
34 :     ////int imgResV = 240;
35 :     //// HEY (BUG?) do we intend to allow inconsistent redefinitions of things?
36 : glk 693 //real rayStep = 0.1;
37 : glk 789 //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 693
41 :     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 : glk 773 vec3 rayDir = normalize(rayVec);
70 : glk 693
71 :     real rayN = camVspNear;
72 :     // ########## BEGIN per-ray initialization
73 :     real transp = 1.0;
74 :     real gray = 0.0;
75 :     output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
76 :     // ########## END per-ray initialization
77 :    
78 :     update
79 :     {
80 :     vec3 rayPos = camEye + rayN*rayVec;
81 :     if (inside (rayPos,F)) {
82 :     // ########## BEGIN per-sample code
83 :     real val = F@rayPos;
84 : glk 773 vec3 grad = ∇F@rayPos; // (here as easy target for optimization)
85 : jhr 765 vec3 norm = normalize(-∇F@rayPos);
86 : glk 693 if (val > valOpacMin) { // we have some opacity
87 : glk 770 real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
88 : glk 775 real ld = norm • lightDir;
89 :     real hd = norm • normalize(lightDir + normalize(camEye - rayPos));
90 : glk 693 real mat = ( phongKa
91 :     + phongKd*(ld if ld > 0.0 else 0.0)
92 : glk 775 + phongKs*(pow(hd, phongSp) if hd > 0.0 else 0.0));
93 : glk 693 gray = gray + transp*opac*mat;
94 :     transp = transp*(1.0 - opac);
95 :     }
96 :     // ########## END per-sample code
97 :     }
98 :     if (transp < 0.01) { // early ray termination
99 : glk 780 transp = 0.0;
100 :     rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */
101 :     stabilize;
102 : glk 693 }
103 : jhr 787 if (rayN > camVspFar) {
104 : glk 780 rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */
105 :     stabilize;
106 : glk 693 }
107 : jhr 787 rayN = rayN + rayStep;
108 : glk 693 }
109 :    
110 : glk 780 stabilize {
111 :     // rgba = [gray, gray, gray, 1.0-transp];
112 :     }
113 :    
114 : glk 693 }
115 :    
116 :     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