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 694, Fri Mar 25 06:33:14 2011 UTC revision 780, Thu Apr 7 22:38:42 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;
47  vec3 camV = cross(camN,camU);  real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;
 real tmp1 = camFOV*3.1415926536/360.0;  
 real camVmax = sin(tmp1)/cos(tmp1)*camDist;  
48  real camUmax = camVmax*real(imgResU)/real(imgResV);  real camUmax = camVmax*real(imgResU)/real(imgResV);
49    
50    // 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  vec3 lightVspDir = [0.9, -1.0, -2.5];  vec3 lightVspDir = [0.9, -1.0, -2.5];
60  // 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|;  
61    
62  real phongKa = 0.05;  real phongKa = 0.05;
63  real phongKd = 0.80;  real phongKd = 0.80;
# Line 67  Line 65 
65  real phongSp = 30.0;  real phongSp = 30.0;
66    
67  image(3)[] img = load (dataFile);  image(3)[] img = load (dataFile);
68  //field#2(3)[] F = img ⊛ bspln3;  //field#4(3)[] F = img ⊛ bspln5;
69  field#2(3)[] F = img ⊛ bspln3;  field#2(3)[] F = img ⊛ bspln3;
70  // HEY (BUG): ctmr Catmull-Rom is C1 but not C2 continuous  //field#1(3)[] F = img ⊛ ctmr;
 //field#2(3)[] F = img ⊛ ctmr;  
71  //field#0(3)[] F = img ⊛ tent;  //field#0(3)[] F = img ⊛ tent;
72    
73  strand RayCast (int ui, int vi)  strand RayCast (int ui, int vi)
74  {  {
75      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);
76      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);
77      vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;      vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
78      vec3 rayDir = rayVec/|rayVec|;      vec3 rayDir = normalize(rayVec);
79    
80      real rayN = camVspNear;      real rayN = camVspNear;
81      // ########## BEGIN per-ray initialization      // ########## BEGIN per-ray initialization
# Line 93  Line 90 
90         if (inside (rayPos,F)) {         if (inside (rayPos,F)) {
91            // ########## BEGIN per-sample code            // ########## BEGIN per-sample code
92            real val = F@rayPos;            real val = F@rayPos;
93            vec3 grad = ∇F@rayPos;            vec3 grad = ∇F@rayPos; // (here as easy target for optimization)
94            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|;  
95            if (val > valOpacMin) {  // we have some opacity            if (val > valOpacMin) {  // we have some opacity
96                real opac =                real opac = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
97                   1.0 if (val > valOpacMax)                real ld = norm • lightDir;
98                   else (val - valOpacMin)/(valOpacMax - valOpacMin);                real hd = norm • normalize(lightDir + normalize(camEye - rayPos));
               real ld = dot(lightDir,norm);  
99                real mat = (  phongKa                real mat = (  phongKa
100                            + phongKd*(ld if ld > 0.0 else 0.0)                            + phongKd*(ld if ld > 0.0 else 0.0)
101                            + phongKs*(pow(ld, phongSp) if ld > 0.0 else 0.0));                            + phongKs*(pow(hd, phongSp) if hd > 0.0 else 0.0));
102                gray = gray + transp*opac*mat;                gray = gray + transp*opac*mat;
103                transp = transp*(1.0 - opac);                transp = transp*(1.0 - opac);
104            }            }
105            // ##########  END  per-sample code            // ##########  END  per-sample code
106         }         }
107         if (transp < 0.01) {  // early ray termination         if (transp < 0.01) {  // early ray termination
108            rgba = [gray, gray, gray, 1.0];             transp = 0.0;
109               rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */
110            stabilize;            stabilize;
111         }         }
112         if (rayN > camVspFar) {         if (t > 40.0) {
113            rgba = [gray, gray, gray, 1.0-transp];             rgba = [gray, gray, gray, 1.0-transp]; /* FIXME */
114            stabilize;            stabilize;
115         }         }
116         rayN = rayN + rayStep;         t = t + stepSz;
117        }
118    
119        stabilize {
120    //     rgba = [gray, gray, gray, 1.0-transp];
121      }      }
122    
     /* render: output maxval */  
123  }  }
124    
125  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.694  
changed lines
  Added in v.780

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