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

SCM Repository

[diderot] Diff of /branches/vis12/test/vr-phong.diderot
ViewVC logotype

Diff of /branches/vis12/test/vr-phong.diderot

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

trunk/test/vr-phong.diderot revision 46, Tue Apr 6 17:02:18 2010 UTC branches/vis12/test/vr-phong.diderot revision 1927, Sat Jun 23 18:09:16 2012 UTC
# Line 1  Line 1 
1  // vr.diderot  // vr-phong.diderot
2  //  //
3  // volume rendering example in Diderot  // volume rendering example in Diderot
4  //  //
5    
 input string dataFile;          // name of dataset  
6  input real stepSz;              // size of steps  input real stepSz;              // size of steps
7  input vec<3> lightDir;  input vec3 lightDir;
8  input vec<3> lightCol;  input vec3 lightRGB;
9  input vec<3> eye;               // location of eye point  input vec3 eye;               // location of eye point
10  input vec<3> orig;              // location of pixel (0,0)  input vec3 orig;              // location of pixel (0,0)
11  input vec<3> cVec;              // vector between pixels horizontally  input vec3 cVec;              // vector between pixels horizontally
12  input vec<3> rVec;              // vector between pixels vertically  input vec3 rVec;              // vector between pixels vertically
13  input real pka;  input real ka;
14  input real pkd;  input real kd;
15  input real pks;  input real ks;
16  input real psh;  input real sh;
17    
18  image[3] img = load (dataFile);  field#2(3)[] F = bspln3 (*) image("../data/txs.nrrd");
19    field#0(1)[4] txf = tent ⊛ image("../data/dummy-txf-rgba.nrrd");
20    
21  field#1[3] F = convolve (bspln3, img);  strand RayCast (int row, int col)
   
 actor RayCast (int row, int col)  
22  {  {
23      vec<3>      pos = orig + row*rVec + col*cVec;      vec3        pos = orig + real(row)*rVec + real(col)*cVec;
24      vec<3>      dir = pos - eye/|pos - eye|;      vec3        dir = normalize(pos - eye);
25      real        t = 0.0;      real        t = 0.0;
26      vec<3>      rayRGB = (0.0, 0.0, 0.0);      output vec3 rayRGB = [0.0, 0.0, 0.0];
27      real        rayTransp = 1.0;      real        rayTransp = 1.0;
28    
29      update      update
30      {      {
31          if (inside (pos,F)) {          if (inside (pos,F)) {
32             real val = F@pos;             real val = F@pos;
33             vec<3> grad = (D F)@pos;             vec3 norm = normalize(-∇F@pos);
34             vec<3> norm = grad/|grad|;             vec3 halfDir = normalize(lightDir - dir);
35             vec<3> half = lightDir - dir/|lightDir - dir|;             vec4 matRGBA = txf@val;
36             vec<4> matRGBA = txf(val);             vec3 matRGB = [matRGBA[0],matRGBA[1],matRGBA[2]];
37             vec<3> matRGB = (matRGBA[0],matRGBA[1],matRGBA[2]);             real ldotn = lightDir • norm;
38             real ldotn = dot(lightDir,norm);             real hdotn = halfDir • norm;
39             real hdotn = dot(halfDir,norm);             vec3 pntRGB = (ka + kd*ldotn)*modulate(matRGB,lightRGB) + ks*hdotn^sh*lightRGB;
40             // hey the per-component multiplication is in matRGB*lightRGB             rayRGB = rayRGB + rayTransp*matRGBA[3]*pntRGB;
41             vec<3> pntRGB = (ka + kd*ldotn)*matRGB*lightRGB + ks*pow(hdotn,psh)*lightRGB;             rayTransp = rayTransp*(1.0 - matRGBA[3]);
            rayRGB = rayRGB + rayTranps*matRGBA[3]*matRGB;  
            rayTransp = rayTranps*(1.0 - matRGBA[3]);  
42          }          }
43          if (t > 1.0 || rayTransp < 0.01) // a little odd; ray terminates at length=1          if (t > 1.0 || rayTransp < 0.01) // a little odd; ray terminates at length=1
44              stabilize;              stabilize;
# Line 50  Line 46 
46          t = t + stepSz;          t = t + stepSz;
47      }      }
48    
   
49  }  }
50    
51    initially [ RayCast(r, c) | r in 0..1023, c in 0..1023 ];

Legend:
Removed from v.46  
changed lines
  Added in v.1927

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