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

SCM Repository

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

Diff of /trunk/test/vr-phong.diderot

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

revision 87, Wed May 26 23:07:39 2010 UTC revision 163, Tue Jul 20 18:55:32 2010 UTC
# Line 18  Line 18 
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(1)[4] 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  {  {
     //// * : int x vec3 -> vec3  
     //// + : vec3 x vec3 -> vec3  
28      vec3        pos = orig + real(row)*rVec + real(col)*cVec;      vec3        pos = orig + real(row)*rVec + real(col)*cVec;
     //// |()| : vec -> real  
     //// - : vec3 x vec3 -> vec3  
     //// / : vec3 x real -> vec3  
29      vec3        dir = (pos - eye)/|pos - eye|;      vec3        dir = (pos - eye)/|pos - eye|;
30      real        t = 0.0;      real        t = 0.0;
31      vec3        rayRGB = [0.0, 0.0, 0.0];      output vec3 rayRGB = [0.0, 0.0, 0.0];
32      real        rayTransp = 1.0;      real        rayTransp = 1.0;
33    
34      update      update
35      {      {
36          if (inside (pos,F)) {          if (inside (pos,F)) {
            //// @ : field x vec3 -> real  
37             real val = F@pos;             real val = F@pos;
            //// D : field -> field  
38             vec3 grad = (D F)@pos;             vec3 grad = (D F)@pos;
39             vec3 norm = grad/|grad|;             vec3 norm = grad/|grad|;
40             vec3 halfDir = (lightDir - dir)/|lightDir - dir|;             vec3 halfDir = (lightDir - dir)/|lightDir - dir|;
41             vec4 matRGBA = txf@[val];             vec4 matRGBA = txf@[val];
42             vec3 matRGB = [matRGBA[0],matRGBA[1],matRGBA[2]];             vec3 matRGB = [matRGBA[0],matRGBA[1],matRGBA[2]];
            //// dot : vec3 x vec3 -> real  
43             real ldotn = dot(lightDir, norm);             real ldotn = dot(lightDir, norm);
44             real hdotn = dot(halfDir, norm);             real hdotn = dot(halfDir, norm);
45             // hey the per-component multiplication is in matRGB*lightRGB             vec3 pntRGB = (ka + kd*ldotn)*modulate(matRGB,lightRGB) + ks*pow(hdotn,sh)*lightRGB;
            //// * : real x vec3 -> vec3  
            //// modulate : vec3 x vec3 -> vec3  
            //// + : vec3 x vec3 -> vec3  
            //// pow : real x real -> real  
            vec3 pntRGB = (ka + kd*ldotn)*modulate(matRGB,lightRGB) + ks*pow(hdotn,psh)*lightRGB;  
46             rayRGB = rayRGB + rayTransp*matRGBA[3]*pntRGB;             rayRGB = rayRGB + rayTransp*matRGBA[3]*pntRGB;
            //// * : real x real -> real  
            //// - : real x real -> real  
47             rayTransp = rayTransp*(1.0 - matRGBA[3]);             rayTransp = rayTransp*(1.0 - matRGBA[3]);
48          }          }
         //// > : real x real -> bool  
         //// < : real x real -> bool  
         //// || : bool x bool -> bool  
49          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
50              stabilize;              stabilize;
51          pos = pos + stepSz*dir;          pos = pos + stepSz*dir;
52          t = t + stepSz;          t = t + stepSz;
53      }      }
54    
   
55  }  }
56    
57    initially [ RayCast(r, c) | r in 0..1023, c in 0..1023 ];

Legend:
Removed from v.87  
changed lines
  Added in v.163

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