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

SCM Repository

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

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

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

revision 49, Tue Apr 13 23:16:22 2010 UTC revision 104, Tue Jun 1 16:04:19 2010 UTC
# Line 5  Line 5 
5    
6  input string dataFile;          // name of dataset  input string dataFile;          // name of dataset
7  input real stepSz;              // size of steps  input real stepSz;              // size of steps
8  input vec<3> lightDir;  input vec3 lightDir;
9  input vec<3> lightCol;  input vec3 lightRGB;
10  input vec<3> eye;               // location of eye point  input vec3 eye;               // location of eye point
11  input vec<3> orig;              // location of pixel (0,0)  input vec3 orig;              // location of pixel (0,0)
12  input vec<3> cVec;              // vector between pixels horizontally  input vec3 cVec;              // vector between pixels horizontally
13  input vec<3> rVec;              // vector between pixels vertically  input vec3 rVec;              // vector between pixels vertically
14  input real pka;  input real ka;
15  input real pkd;  input real kd;
16  input real pks;  input real ks;
17  input real psh;  input real sh;
18    
19  image[3] img = load (dataFile);  image(3)[] img = load (dataFile);
20    
21  field#1[3] F = convolve (bspln3, img);  //field#1(3)[] F = convolve (bspln3, img);
22    field#2(3)[] F = convolve (bspln3, img);
23    
24  field#0<4>[1] txf = convolve (tent, load("txf-rgba.nrrd"));  field#0(1)[4] txf = convolve (tent, load("txf-rgba.nrrd"));
25    
26  actor RayCast (int row, int col)  actor RayCast (int row, int col)
27  {  {
28      vec<3>      pos = orig + row*rVec + col*cVec;      //// * : int x vec3 -> vec3
29      vec<3>      dir = pos - eye/|pos - eye|;      //// + : vec3 x vec3 -> vec3
30        vec3        pos = orig + real(row)*rVec + real(col)*cVec;
31        //// |()| : vec -> real
32        //// - : vec3 x vec3 -> vec3
33        //// / : vec3 x real -> vec3
34        vec3        dir = (pos - eye)/|pos - eye|;
35      real        t = 0.0;      real        t = 0.0;
36      vec<3>      rayRGB = (0.0, 0.0, 0.0);      vec3        rayRGB = [0.0, 0.0, 0.0];
37      real        rayTransp = 1.0;      real        rayTransp = 1.0;
38    
39      update      update
40      {      {
41          if (inside (pos,F)) {          if (inside (pos,F)) {
42               //// @ : field x vec3 -> real
43             real val = F@pos;             real val = F@pos;
44             vec<3> grad = (D F)@pos;             //// D : field -> field
45             vec<3> norm = grad/|grad|;             vec3 grad = (D F)@pos;
46             vec<3> half = lightDir - dir/|lightDir - dir|;             vec3 norm = grad/|grad|;
47             vec<4> matRGBA = txf@val;             vec3 halfDir = (lightDir - dir)/|lightDir - dir|;
48             vec<3> matRGB = (matRGBA[0],matRGBA[1],matRGBA[2]);             vec4 matRGBA = txf@[val];
49               vec3 matRGB = [matRGBA[0],matRGBA[1],matRGBA[2]];
50               //// dot : vec3 x vec3 -> real
51             real ldotn = dot(lightDir,norm);             real ldotn = dot(lightDir,norm);
52             real hdotn = dot(halfDir,norm);             real hdotn = dot(halfDir,norm);
53             // hey the per-component multiplication is in matRGB*lightRGB             // hey the per-component multiplication is in matRGB*lightRGB
54             vec<3> pntRGB = (ka + kd*ldotn)*matRGB*lightRGB + ks*pow(hdotn,psh)*lightRGB;             //// * : real x vec3 -> vec3
55             rayRGB = rayRGB + rayTranps*matRGBA[3]*matRGB;             //// modulate : vec3 x vec3 -> vec3
56             rayTransp = rayTranps*(1.0 - matRGBA[3]);             //// + : vec3 x vec3 -> vec3
57               //// pow : real x real -> real
58               vec3 pntRGB = (ka + kd*ldotn)*modulate(matRGB,lightRGB) + ks*pow(hdotn,sh)*lightRGB;
59               rayRGB = rayRGB + rayTransp*matRGBA[3]*pntRGB;
60               //// * : real x real -> real
61               //// - : real x real -> real
62               rayTransp = rayTransp*(1.0 - matRGBA[3]);
63          }          }
64            //// > : real x real -> bool
65            //// < : real x real -> bool
66            //// || : bool x bool -> bool
67          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
68              stabilize;              stabilize;
69          pos = pos + stepSz*dir;          pos = pos + stepSz*dir;
70          t = t + stepSz;          t = t + stepSz;
71      }      }
72    
   
73  }  }
74    
75    initially [ RayCast(r, c) | r in 0..1023, c in 0..1023 ];

Legend:
Removed from v.49  
changed lines
  Added in v.104

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