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 1016 - (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 : glk 892 // The main thing missing from this is a more general transfer function
7 :     //
8 :     // process output with:
9 : glk 915 // unu reshape -i mip.txt -s 4 480 345 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255 -o vr-lite-cam.png
10 : glk 693
11 : glk 978 string dataFile = "../data/txs-pad3.nrrd";
12 :     vec3 camEye = [25.0, 15.0, 10.0];
13 :     vec3 camAt = [3.0, 3.0, 3.0];
14 :     vec3 camUp = [0.0, 0.0, 1.0];
15 :     real camNear = -5.0;
16 :     real camFar = 5.0;
17 :     real camFOV = 16.0;
18 : glk 915 int imgResU = 480;
19 :     int imgResV = 345;
20 : glk 978 real rayStep = 0.1;
21 :     real valOpacMin = 0.15; // highest value with opacity 0.0
22 :     real valOpacMax = 0.20; // lowest value with opacity 1.0
23 : glk 892
24 : glk 978 //string dataFile = "../data/vfrhand-nohip.nhdr";
25 :     //vec3 camEye = [127.331, -1322.05, 272.53];
26 :     //vec3 camAt = [63.0, 82.6536, 98.0];
27 :     //vec3 camUp = [0.9987, 0.0459166, -0.0221267];
28 :     //real camNear = -78.0;
29 :     //real camFar = 78.0;
30 :     //real camFOV = 5.0;
31 :     //int imgResU = 480;
32 :     //int imgResV = 345;
33 :     //real rayStep = 0.1;
34 :     //real valOpacMin = 400.0; // 400.0 for skin, 1150.0 for bone
35 :     //real valOpacMax = 700.0; // 700.0 for skin, 1450.0 for bone
36 :    
37 : glk 693 real camDist = |camAt - camEye|;
38 :     real camVspNear = camDist + camNear;
39 :     real camVspFar = camDist + camFar;
40 : glk 775 vec3 camN = normalize(camAt - camEye);
41 : glk 773 vec3 camU = normalize(camN × camUp);
42 :     vec3 camV = camN × camU;
43 : glk 696 real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
44 : glk 693 real camUmax = camVmax*real(imgResU)/real(imgResV);
45 :    
46 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
47 : glk 773 vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
48 : glk 892 vec3 lightRGB = [1.0, 1.0, 1.0];
49 : glk 693
50 :     real phongKa = 0.05;
51 : glk 892 real phongKd = 0.65;
52 :     real phongKs = 0.45;
53 :     real phongSp = 50.0;
54 : glk 693
55 :     image(3)[] img = load (dataFile);
56 : jhr 704 //field#4(3)[] F = img ⊛ bspln5;
57 : glk 773 field#2(3)[] F = img ⊛ bspln3;
58 :     //field#1(3)[] F = img ⊛ ctmr;
59 : glk 907 //field#1(3)[] F = img ⊛ c1tent;
60 : glk 693
61 :     strand RayCast (int ui, int vi)
62 :     {
63 : glk 770 real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
64 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
65 : glk 693 vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
66 : glk 1008 vec3 toEye = normalize(-rayVec);
67 : glk 693
68 :     real rayN = camVspNear;
69 :     // ########## BEGIN per-ray initialization
70 : glk 892 real rayTransp = 1.0;
71 :     vec3 rayRGB = [0.0, 0.0, 0.0];
72 : glk 915 output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0];
73 : glk 693 // ########## END per-ray initialization
74 :    
75 :     update
76 :     {
77 :     vec3 rayPos = camEye + rayN*rayVec;
78 :     if (inside (rayPos,F)) {
79 :     // ########## BEGIN per-sample code
80 : jhr 903 real val = F(rayPos);
81 : glk 693 if (val > valOpacMin) { // we have some opacity
82 : glk 1016 vec3 grad = ∇F(rayPos); // (here as easy target for optimization)
83 :     vec3 norm = normalize(-∇F(rayPos));
84 : glk 892 real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
85 :     real ld = max(0.0, norm • lightDir);
86 : glk 1008 real hd = max(0.0, norm • normalize(lightDir + toEye));
87 : glk 978 // contrived assignment of RGB from XYZ, only sensible
88 :     // for txs-pad3.nrrd, not for vfrhand-nohip.nhdr!!
89 :     vec3 matRGB = [lerp(0.2, 1.0, 1.0, rayPos[0], 8.0),
90 :     lerp(0.2, 1.0, 1.0, rayPos[1], 8.0),
91 :     lerp(0.2, 1.0, 1.0, rayPos[2], 8.0)];
92 : glk 892 vec3 pntRGB = (phongKa*matRGB
93 :     + phongKd*ld*modulate(matRGB, lightRGB)
94 :     + phongKs*hd^phongSp*lightRGB);
95 :     rayRGB = rayRGB + rayTransp*alpha*pntRGB;
96 :     rayTransp = rayTransp*(1.0 - alpha);
97 : glk 693 }
98 :     // ########## END per-sample code
99 :     }
100 : glk 892 if (rayTransp < 0.01) { // early ray termination
101 :     rayTransp = 0.0;
102 : glk 915 outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */
103 : glk 780 stabilize;
104 : glk 693 }
105 : jhr 787 if (rayN > camVspFar) {
106 : glk 915 outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */
107 : glk 780 stabilize;
108 : glk 693 }
109 : jhr 787 rayN = rayN + rayStep;
110 : glk 693 }
111 :    
112 : glk 780 stabilize {
113 : glk 915 // outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp];
114 : glk 780 }
115 :    
116 : glk 693 }
117 :    
118 :     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