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

SCM Repository

[diderot] Diff of /branches/pure-cfg/test/vr-curv-quad.diderot
ViewVC logotype

Diff of /branches/pure-cfg/test/vr-curv-quad.diderot

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

revision 1039, Sun May 1 21:20:35 2011 UTC revision 1529, Fri Oct 14 18:02:04 2011 UTC
# Line 1  Line 1 
1  // vr-curv  // vr-curv-quad
2  //  //
3  // Demonstration of curvature-based transfer functions in volume rendering  // Demonstration of curvature-based transfer functions in volume rendering
4  //  //
5  // process output with:  // process output with:
6  // unu reshape -i mip.txt -s 4 480 345 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255  -o vr-curv.png  // unu reshape -i vr-curv-quad.txt -s 4 480 345 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255  -o vr-curv-quad.png
7    
8  field#2(3)[] F = load("../data/quad-patches-pad.nrrd") ⊛ bspln3;  // volume dataset
9  field#0(2)[3] RGB = load("../data/hue.nhdr") ⊛ tent;  field#2(3)[] F = bspln3 ⊛ load("../data/quad-patches-pad.nrrd");
10    
11    // RGB colormap of (kappa1,kapp2)
12    field#0(2)[3] RGB = tent ⊛ load("../data/txf/2d-bow.nrrd");
13    
14  // set camera, image, and rendering parameters  // set camera, image, and rendering parameters
15  vec3 camEye = [183.021, -411.857, 686.458];  vec3 camEye = [183.021, -411.857, 686.458];
# Line 27  Line 30 
30  real phongKs = 0.3;  real phongKs = 0.3;
31  real phongSp = 45.0;  real phongSp = 45.0;
32    
33  // (boilerplate) computation of camera and light info  // boilerplate computation of camera and light info
34  real camDist = |camAt - camEye|;  real camDist = |camAt - camEye|;
35  real camVspNear = camNear + camDist;  real camVspNear = camNear + camDist;
36  real camVspFar = camFar + camDist;  real camVspFar = camFar + camDist;
37  vec3 camN = normalize(camAt - camEye);  vec3 camN = normalize(camAt - camEye);
38  vec3 camU = normalize(camN × camUp);  vec3 camU = normalize(camN × camUp);
39  vec3 camV = camN × camU;  vec3 camV = camN × camU;
40  real camVmax = tan(camFOV*3.1415926536/360.0)*camDist;  real camVmax = tan(camFOV*π/360.0)*camDist;
41  real camUmax = camVmax*real(imgResU)/real(imgResV);  real camUmax = camVmax*real(imgResU)/real(imgResV);
42  vec3 lightDir = normalize(lightVspDir[0]*camU +  vec3 lightDir = normalize(lightVspDir[0]*camU +
43                            lightVspDir[1]*camV +                            lightVspDir[1]*camV +
44                            lightVspDir[2]*camN);                            lightVspDir[2]*camN);
45    
46    // RayCast(ui,vi) computes rendered color for pixel (ui,vi)
47  strand RayCast (int ui, int vi) {  strand RayCast (int ui, int vi) {
48      real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);      real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
49      real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);      real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
50      vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;      vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
51        vec3 vv = normalize(-rayVec);
52    
53      real rayN = camVspNear;      real rayN = camVspNear;
54      real rayTransp = 1.0;      real rayTransp = 1.0;
# Line 58  Line 63 
63                vec3 grad = -∇F(pos);                vec3 grad = -∇F(pos);
64                vec3 norm = normalize(grad);                vec3 norm = normalize(grad);
65                // begin curvature computation                // begin curvature computation
66                tensor[3,3] H = -∇(∇F)(pos);                tensor[3,3] H = ∇⊗∇F(pos);
67                tensor[3,3] P = identity[3] - norm⊗norm;                tensor[3,3] P = identity[3] - norm⊗norm;
68                tensor[3,3] G = (P•H•P)/|grad|;                tensor[3,3] G = -(P•H•P)/|grad|;
69                real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));                real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));
70                real k1 = (trace(G) + disc)/2.0;                real k1 = (trace(G) + disc)/2.0;
71                real k2 = (trace(G) - disc)/2.0;                real k2 = (trace(G) - disc)/2.0;
72                // finished curvature computation; begin finding sample RGBA                // find material RGBA
73                k1 = max(-1.0, min(1.0, 4.2*k1));                vec3 matRGB = RGB([clamp(-1.0, 1.0, 6.0*k1),
74                k2 = max(-1.0, min(1.0, 4.2*k2));                                   clamp(-1.0, 1.0, 6.0*k2)]);
               vec3 matRGB = RGB([k1,k2]) if inside([k1,k2],RGB)  
                             else [1.0,0.0,1.0];  
75                real alpha = min(1.0, lerp(0.0, 1.0,                real alpha = min(1.0, lerp(0.0, 1.0,
76                                           valOpacMin, val, valOpacMax));                                           valOpacMin, val, valOpacMax));
77                real ld = max(0.0, norm • lightDir);                real ld = max(0.0, norm • lightDir);
78                real hd = max(0.0, norm • normalize(lightDir +                real hd = max(0.0, norm • normalize(lightDir + vv));
                                                   normalize(camEye - pos)));  
79                // Phong shading                // Phong shading
80                vec3 pntRGB = (phongKa*matRGB                vec3 pntRGB = (phongKa*matRGB
81                               + phongKd*ld*modulate(matRGB, lightRGB)                               + phongKd*ld*modulate(matRGB, lightRGB)
82                               + phongKs*hd^phongSp*lightRGB);                               + phongKs*hd^phongSp*lightRGB);
83                // composite with existing ray color and transparency                // composite with existing ray color and transparency
84                rayRGB = rayRGB + rayTransp*alpha*pntRGB;                rayRGB += rayTransp*alpha*pntRGB;
85                rayTransp = rayTransp*(1.0 - alpha);                rayTransp *= 1.0 - alpha;
86            }            }
87         }         }
88         if (rayTransp < 0.01) {  // early ray termination         if (rayTransp < 0.01) {  // early ray termination
89            rayTransp = 0.0;            rayTransp = 0.0;
           outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];  
90            stabilize;            stabilize;
91         }         }
92         if (rayN > camVspFar) {         if (rayN > camVspFar) {
           outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];  
93            stabilize;            stabilize;
94         }         }
95         rayN = rayN + rayStep;         rayN = rayN + rayStep;
96      }      }
97    
98        stabilize {
99           outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];
100        }
101    
102      /* render: output maxval */      /* render: output maxval */
103  }  }
104    

Legend:
Removed from v.1039  
changed lines
  Added in v.1529

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