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 775 - (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 : glk 775 //int imgResU = 480;
17 :     //int imgResV = 345;
18 : glk 693 //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 :     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 : glk 775 // HEY (BUG): these:
51 :     // vec3 lightVspDir = [1.0, -0.0, 0.0];
52 :     // vec3 lightVspDir = [1.0, 0.0, -0.0];
53 :     // work okay but this:
54 :     // vec3 lightVspDir = [1.0, 0.0, 0.0];
55 :     // does not:
56 :     // uncaught exception Fail [Fail: E_Slice]
57 :     // raised at simplify/eval.sml:266.57
58 :     // raised at simplify/eval.sml:183.33-183.47
59 : glk 693 vec3 lightVspDir = [0.9, -1.0, -2.5];
60 : glk 773 vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
61 : glk 693
62 :     real phongKa = 0.05;
63 :     real phongKd = 0.80;
64 :     real phongKs = 0.20;
65 :     real phongSp = 30.0;
66 :    
67 :     image(3)[] img = load (dataFile);
68 : jhr 704 //field#4(3)[] F = img ⊛ bspln5;
69 : glk 773 field#2(3)[] F = img ⊛ bspln3;
70 :     //field#1(3)[] F = img ⊛ ctmr;
71 : glk 693 //field#0(3)[] F = img ⊛ tent;
72 :    
73 :     strand RayCast (int ui, int vi)
74 :     {
75 : glk 770 real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
76 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
77 : glk 693 vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
78 : glk 773 vec3 rayDir = normalize(rayVec);
79 : glk 693
80 :     real rayN = camVspNear;
81 :     // ########## BEGIN per-ray initialization
82 :     real transp = 1.0;
83 :     real gray = 0.0;
84 :     output vec4 rgba = [0.0, 0.0, 0.0, 0.0];
85 :     // ########## END per-ray initialization
86 :    
87 :     update
88 :     {
89 :     vec3 rayPos = camEye + rayN*rayVec;
90 :     if (inside (rayPos,F)) {
91 :     // ########## BEGIN per-sample code
92 :     real val = F@rayPos;
93 : glk 773 vec3 grad = ∇F@rayPos; // (here as easy target for optimization)
94 : jhr 765 vec3 norm = normalize(-∇F@rayPos);
95 : glk 693 if (val > valOpacMin) { // we have some opacity
96 : glk 770 real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
97 : glk 775 real ld = norm • lightDir;
98 :     real hd = norm • normalize(lightDir + normalize(camEye - rayPos));
99 : glk 693 real mat = ( phongKa
100 :     + phongKd*(ld if ld > 0.0 else 0.0)
101 : glk 775 + phongKs*(pow(hd, phongSp) if hd > 0.0 else 0.0));
102 : glk 693 gray = gray + transp*opac*mat;
103 :     transp = transp*(1.0 - opac);
104 :     }
105 :     // ########## END per-sample code
106 :     }
107 :     if (transp < 0.01) { // early ray termination
108 :     rgba = [gray, gray, gray, 1.0];
109 :     stabilize;
110 :     }
111 :     if (rayN > camVspFar) {
112 :     rgba = [gray, gray, gray, 1.0-transp];
113 :     stabilize;
114 :     }
115 :     rayN = rayN + rayStep;
116 :     }
117 :    
118 :     /* render: output maxval */
119 :     }
120 :    
121 :     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