Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/pure-cfg/test/vr-lite-cam.diderot
ViewVC logotype

Diff of /branches/pure-cfg/test/vr-lite-cam.diderot

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 827, Sat Apr 16 00:40:34 2011 UTC revision 915, Thu Apr 21 19:00:44 2011 UTC
# Line 3  Line 3 
3  // simple volume renderer, now with a single directional light,  // simple volume renderer, now with a single directional light,
4  // Phong shading, and the new camera.  // Phong shading, and the new camera.
5  //  //
6  // The main thing missing from this is a more general  // The main thing missing from this is a more general transfer function
7  // transfer function  //
8    // process output with:
9  //string dataFile = "../data/txs-pad3.nrrd";  // 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
 //vec3 camEye = [25.0, 15.0, 10.0];  
 //vec3 camAt = [3.0, 3.0, 3.0];  
 //vec3 camUp = [0.0, 0.0, 1.0];  
 //real camNear = -5.0;  
 //real camFar = 5.0;  
 //real camFOV = 18.0;  
 //int imgResU = 480;  
 //int imgResV = 345;  
 //real rayStep = 0.1;  
 //real valOpacMin = 0.20;          // highest value with opacity 0.0  
 //real valOpacMax = 0.25;          // lowest value with opacity 1.0  
10    
11  string dataFile = "../data/vfrhand-nohip.nhdr";  string dataFile = "../data/txs-pad3.nrrd";
12  vec3 camEye = [127.331, -1322.05, 272.53];  vec3 camEye = [25.0, 15.0, 10.0];
13  vec3 camAt = [63.0, 82.6536, 98.0];  vec3 camAt = [3.0, 3.0, 3.0];
14  vec3 camUp = [0.9987, 0.0459166, -0.0221267];  vec3 camUp = [0.0, 0.0, 1.0];
15  real camNear = -78.0;  real camNear = -5.0;
16  real camFar = 78.0;  real camFar = 5.0;
17  real camFOV = 5.0;  real camFOV = 16.0;
 //int imgResU = 640;  
 //int imgResV = 480;  
18  int imgResU = 480;  int imgResU = 480;
19  int imgResV = 345;  int imgResV = 345;
 //int imgResU = 320;  
 //int imgResV = 240;  
 // HEY (BUG?) do we intend to allow inconsistent redefinitions of things?  
20  real rayStep = 0.1;  real rayStep = 0.1;
21  real rayStep = 0.5;  real valOpacMin = 0.15;          // highest value with opacity 0.0
22  real valOpacMin = 400.0;        // 400.0 for skin, 1150.0 for bone  real valOpacMax = 0.20;          // lowest value with opacity 1.0
23  real valOpacMax = 700.0;        // 700.0 for skin, 1450.0 for bone  
24    //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  real camDist = |camAt - camEye|;  real camDist = |camAt - camEye|;
38  real camVspNear = camDist + camNear;  real camVspNear = camDist + camNear;
# Line 49  Line 45 
45    
46  vec3 lightVspDir = [0.9, -1.0, -2.5];  vec3 lightVspDir = [0.9, -1.0, -2.5];
47  vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);  vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
48    vec3 lightRGB = [1.0, 1.0, 1.0];
49    
50  real phongKa = 0.05;  real phongKa = 0.05;
51  real phongKd = 0.80;  real phongKd = 0.65;
52  real phongKs = 0.20;  real phongKs = 0.45;
53  real phongSp = 30.0;  real phongSp = 50.0;
54    
55  image(3)[] img = load (dataFile);  image(3)[] img = load (dataFile);
56  //field#4(3)[] F = img ⊛ bspln5;  //field#4(3)[] F = img ⊛ bspln5;
57  field#2(3)[] F = img ⊛ bspln3;  field#2(3)[] F = img ⊛ bspln3;
58  //field#1(3)[] F = img ⊛ ctmr;  //field#1(3)[] F = img ⊛ ctmr;
59  //field#0(3)[] F = img ⊛ tent;  //field#1(3)[] F = img ⊛ c1tent;
60    
61  strand RayCast (int ui, int vi)  strand RayCast (int ui, int vi)
62  {  {
63      real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);      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);      real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
65      vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;      vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
     vec3 rayDir = normalize(rayVec);  
66    
67      real rayN = camVspNear;      real rayN = camVspNear;
68      // ########## BEGIN per-ray initialization      // ########## BEGIN per-ray initialization
69      real transp = 1.0;      real rayTransp = 1.0;
70      real gray = 0.0;      vec3 rayRGB = [0.0, 0.0, 0.0];
71      output vec4 rgba = [0.0, 0.0, 0.0, 0.0];      output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0];
72      // ##########  END  per-ray initialization      // ##########  END  per-ray initialization
73    
74      update      update
# Line 80  Line 76 
76         vec3 rayPos = camEye + rayN*rayVec;         vec3 rayPos = camEye + rayN*rayVec;
77         if (inside (rayPos,F)) {         if (inside (rayPos,F)) {
78            // ########## BEGIN per-sample code            // ########## BEGIN per-sample code
79            real val = F@rayPos;            real val = F(rayPos);
80            vec3 grad = ∇F@rayPos; // (here as easy target for optimization)            vec3 grad = ∇F(rayPos); // (here as easy target for optimization)
81            vec3 norm = normalize(-∇F@rayPos);            vec3 norm = normalize(-∇F(rayPos));
82            if (val > valOpacMin) {  // we have some opacity            if (val > valOpacMin) {  // we have some opacity
83                real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));                real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
84                real ld = norm • lightDir;                real ld = max(0.0, norm • lightDir);
85                real hd = norm • normalize(lightDir + normalize(camEye - rayPos));                real hd = max(0.0, norm • normalize(lightDir + normalize(camEye - rayPos)));
86                real mat = (  phongKa                // contrived assignment of RGB from XYZ, only sensible
87                            + phongKd*(ld if ld > 0.0 else 0.0)                // for txs-pad3.nrrd, not for vfrhand-nohip.nhdr!!
88                            + phongKs*(hd^phongSp if hd > 0.0 else 0.0));                vec3 matRGB = [lerp(0.2, 1.0, 1.0, rayPos[0], 8.0),
89                gray = gray + transp*opac*mat;                               lerp(0.2, 1.0, 1.0, rayPos[1], 8.0),
90                transp = transp*(1.0 - opac);                               lerp(0.2, 1.0, 1.0, rayPos[2], 8.0)];
91                  vec3 pntRGB = (phongKa*matRGB
92                                 + phongKd*ld*modulate(matRGB, lightRGB)
93                                 + phongKs*hd^phongSp*lightRGB);
94                  rayRGB = rayRGB + rayTransp*alpha*pntRGB;
95                  rayTransp = rayTransp*(1.0 - alpha);
96            }            }
97            // ##########  END  per-sample code            // ##########  END  per-sample code
98         }         }
99         if (transp < 0.01) {  // early ray termination         if (rayTransp < 0.01) {  // early ray termination
100             transp = 0.0;             rayTransp = 0.0;
101             rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */             outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */
102             stabilize;             stabilize;
103         }         }
104         if (rayN > camVspFar) {         if (rayN > camVspFar) {
105             rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */             outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */
106             stabilize;             stabilize;
107         }         }
108         rayN = rayN + rayStep;         rayN = rayN + rayStep;
109      }      }
110    
111      stabilize {      stabilize {
112  //     rgba = [gray, gray, gray, 1.0-transp];  //     outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp];
113      }      }
114    
115  }  }

Legend:
Removed from v.827  
changed lines
  Added in v.915

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0