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 696, Fri Mar 25 18:29:12 2011 UTC revision 827, Sat Apr 16 00:40:34 2011 UTC
# Line 13  Line 13 
13  //real camNear = -5.0;  //real camNear = -5.0;
14  //real camFar = 5.0;  //real camFar = 5.0;
15  //real camFOV = 18.0;  //real camFOV = 18.0;
16  //int imgResU = 320;  //int imgResU = 480;
17  //int imgResV = 240;  //int imgResV = 345;
18  //real rayStep = 0.1;  //real rayStep = 0.1;
19  //real valOpacMin = 0.20;          // highest value with opacity 0.0  //real valOpacMin = 0.20;          // highest value with opacity 0.0
20  //real valOpacMax = 0.25;          // lowest value with opacity 1.0  //real valOpacMax = 0.25;          // lowest value with opacity 1.0
# Line 38  Line 38 
38  real valOpacMin = 400.0;        // 400.0 for skin, 1150.0 for bone  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  real valOpacMax = 700.0;        // 700.0 for skin, 1450.0 for bone
40    
  // HEY: update this camera code when possible, based on eventual  
 // improvements to mip-cam.diderot  
41  real camDist = |camAt - camEye|;  real camDist = |camAt - camEye|;
42  real camVspNear = camDist + camNear;  real camVspNear = camDist + camNear;
43  real camVspFar = camDist + camFar;  real camVspFar = camDist + camFar;
44  vec3 camN = (camAt - camEye)/camDist;  vec3 camN = normalize(camAt - camEye);
45  vec3 tmp0 = cross(camN,camUp);  vec3 camU = normalize(camN × camUp);
46  vec3 camU = tmp0/|tmp0|;  vec3 camV = camN × camU;
 vec3 camV = cross(camN,camU);  
47  real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;  real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
48  real camUmax = camVmax*real(imgResU)/real(imgResV);  real camUmax = camVmax*real(imgResU)/real(imgResV);
49    
50  vec3 lightVspDir = [0.9, -1.0, -2.5];  vec3 lightVspDir = [0.9, -1.0, -2.5];
51  // HEY (want) ability to access components of a vector (e.g. "vec[0]")  vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
 // would make this transform to world-space less awkward; would be  
 // lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN  
 // OR, we could create and apply a view-to-world matrix transform  
 vec3 tmp2 = (  dot(lightVspDir,[1.0,0.0,0.0])*camU  
              + dot(lightVspDir,[0.0,1.0,0.0])*camV  
              + dot(lightVspDir,[0.0,0.0,1.0])*camN);  
 vec3 lightDir = tmp2/|tmp2|;  
52    
53  real phongKa = 0.05;  real phongKa = 0.05;
54  real phongKd = 0.80;  real phongKd = 0.80;
# Line 66  Line 56 
56  real phongSp = 30.0;  real phongSp = 30.0;
57    
58  image(3)[] img = load (dataFile);  image(3)[] img = load (dataFile);
59  //field#2(3)[] F = img ⊛ bspln3;  //field#4(3)[] F = img ⊛ bspln5;
60  field#2(3)[] F = img ⊛ bspln3;  field#2(3)[] F = img ⊛ bspln3;
61  // HEY (BUG): ctmr Catmull-Rom is C1 but not C2 continuous  //field#1(3)[] F = img ⊛ ctmr;
 //field#2(3)[] F = img ⊛ ctmr;  
62  //field#0(3)[] F = img ⊛ tent;  //field#0(3)[] F = img ⊛ tent;
63    
64  strand RayCast (int ui, int vi)  strand RayCast (int ui, int vi)
65  {  {
66      real rayU = 2.0*camUmax*(real(ui) + 0.5)/real(imgResU) - camUmax;      real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
67      real rayV = 2.0*camVmax*(real(vi) + 0.5)/real(imgResV) - camVmax;      real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
68      vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;      vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
69      vec3 rayDir = rayVec/|rayVec|;      vec3 rayDir = normalize(rayVec);
70    
71      real rayN = camVspNear;      real rayN = camVspNear;
72      // ########## BEGIN per-ray initialization      // ########## BEGIN per-ray initialization
# Line 92  Line 81 
81         if (inside (rayPos,F)) {         if (inside (rayPos,F)) {
82            // ########## BEGIN per-sample code            // ########## BEGIN per-sample code
83            real val = F@rayPos;            real val = F@rayPos;
84            vec3 grad = ∇F@rayPos;            vec3 grad = ∇F@rayPos; // (here as easy target for optimization)
85            vec3 norm = -grad/|grad|;            vec3 norm = normalize(-∇F@rayPos);
           // HEY (BUG) will get an "uncaught exception" if code is instead  
           // vec3 norm = -∇F@rayPos/|∇F@rayPos|;  
86            if (val > valOpacMin) {  // we have some opacity            if (val > valOpacMin) {  // we have some opacity
87                real opac =                real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
88                   1.0 if (val > valOpacMax)                real ld = norm • lightDir;
89                   else (val - valOpacMin)/(valOpacMax - valOpacMin);                real hd = norm • normalize(lightDir + normalize(camEye - rayPos));
               real ld = dot(lightDir,norm);  
90                real mat = (  phongKa                real mat = (  phongKa
91                            + phongKd*(ld if ld > 0.0 else 0.0)                            + phongKd*(ld if ld > 0.0 else 0.0)
92                            + phongKs*(pow(ld, phongSp) if ld > 0.0 else 0.0));                            + phongKs*(hd^phongSp if hd > 0.0 else 0.0));
93                gray = gray + transp*opac*mat;                gray = gray + transp*opac*mat;
94                transp = transp*(1.0 - opac);                transp = transp*(1.0 - opac);
95            }            }
96            // ##########  END  per-sample code            // ##########  END  per-sample code
97         }         }
98         if (transp < 0.01) {  // early ray termination         if (transp < 0.01) {  // early ray termination
99            rgba = [gray, gray, gray, 1.0];             transp = 0.0;
100               rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */
101            stabilize;            stabilize;
102         }         }
103         if (rayN > camVspFar) {         if (rayN > camVspFar) {
104            rgba = [gray, gray, gray, 1.0-transp];             rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */
105            stabilize;            stabilize;
106         }         }
107         rayN = rayN + rayStep;         rayN = rayN + rayStep;
108      }      }
109    
110      /* render: output maxval */      stabilize {
111    //     rgba = [gray, gray, gray, 1.0-transp];
112        }
113    
114  }  }
115    
116  initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ];  initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ];

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

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