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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1529 - (view) (download)

1 : jhr 1386 // vr-curv-quad
2 : glk 866 //
3 : glk 911 // Demonstration of curvature-based transfer functions in volume rendering
4 :     //
5 :     // process output with:
6 : jhr 1386 // 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 : glk 866
8 : jhr 1529 // volume dataset
9 : glk 1071 field#2(3)[] F = bspln3 ⊛ load("../data/quad-patches-pad.nrrd");
10 : jhr 1529
11 :     // RGB colormap of (kappa1,kapp2)
12 : glk 1071 field#0(2)[3] RGB = tent ⊛ load("../data/txf/2d-bow.nrrd");
13 : glk 1025
14 : glk 913 // set camera, image, and rendering parameters
15 : glk 866 vec3 camEye = [183.021, -411.857, 686.458];
16 :     vec3 camAt = [55.4037, 40.2407, 4.32732];
17 :     vec3 camUp = [0.0, 0.0, 1.0];
18 :     real camNear = -42.0;
19 :     real camFar = 42.0;
20 :     real camFOV = 7.15;
21 :     int imgResU = 480;
22 :     int imgResV = 345;
23 : glk 911 real rayStep = 0.2;
24 :     real valOpacMin = -0.25;
25 :     real valOpacMax = -0.10;
26 : glk 913 vec3 lightVspDir = [0.9, -2.5, -2.5];
27 :     vec3 lightRGB = [1.0, 1.0, 1.0];
28 :     real phongKa = 0.1;
29 :     real phongKd = 0.7;
30 :     real phongKs = 0.3;
31 :     real phongSp = 45.0;
32 : glk 866
33 : jhr 1529 // boilerplate computation of camera and light info
34 : glk 866 real camDist = |camAt - camEye|;
35 :     real camVspNear = camNear + camDist;
36 :     real camVspFar = camFar + camDist;
37 :     vec3 camN = normalize(camAt - camEye);
38 :     vec3 camU = normalize(camN × camUp);
39 :     vec3 camV = camN × camU;
40 : glk 1105 real camVmax = tan(camFOV*π/360.0)*camDist;
41 : glk 866 real camUmax = camVmax*real(imgResU)/real(imgResV);
42 : glk 911 vec3 lightDir = normalize(lightVspDir[0]*camU +
43 :     lightVspDir[1]*camV +
44 :     lightVspDir[2]*camN);
45 : glk 866
46 : jhr 1529 // RayCast(ui,vi) computes rendered color for pixel (ui,vi)
47 : glk 911 strand RayCast (int ui, int vi) {
48 : glk 866 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);
50 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
51 : jhr 1127 vec3 vv = normalize(-rayVec);
52 : glk 866
53 :     real rayN = camVspNear;
54 : glk 911 real rayTransp = 1.0;
55 :     vec3 rayRGB = [0.0, 0.0, 0.0];
56 :     output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0];
57 : glk 866
58 : glk 911 update {
59 : glk 866 vec3 pos = camEye + rayN*rayVec;
60 :     if (inside (pos,F)) {
61 : glk 911 real val = F(pos);
62 : glk 866 if (val > valOpacMin) { // we have some opacity
63 : glk 1025 vec3 grad = -∇F(pos);
64 :     vec3 norm = normalize(grad);
65 : glk 911 // begin curvature computation
66 : jhr 1386 tensor[3,3] H = ∇⊗∇F(pos);
67 : glk 1101 tensor[3,3] P = identity[3] - norm⊗norm;
68 : glk 1078 tensor[3,3] G = -(P•H•P)/|grad|;
69 : glk 866 real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2));
70 : glk 911 real k1 = (trace(G) + disc)/2.0;
71 :     real k2 = (trace(G) - disc)/2.0;
72 : jhr 1529 // find material RGBA
73 :     vec3 matRGB = RGB([clamp(-1.0, 1.0, 6.0*k1),
74 :     clamp(-1.0, 1.0, 6.0*k2)]);
75 : glk 911 real alpha = min(1.0, lerp(0.0, 1.0,
76 :     valOpacMin, val, valOpacMax));
77 :     real ld = max(0.0, norm • lightDir);
78 : jhr 1127 real hd = max(0.0, norm • normalize(lightDir + vv));
79 : glk 911 // Phong shading
80 :     vec3 pntRGB = (phongKa*matRGB
81 : jhr 1529 + phongKd*ld*modulate(matRGB, lightRGB)
82 :     + phongKs*hd^phongSp*lightRGB);
83 : glk 911 // composite with existing ray color and transparency
84 : jhr 1529 rayRGB += rayTransp*alpha*pntRGB;
85 :     rayTransp *= 1.0 - alpha;
86 : glk 866 }
87 :     }
88 : glk 911 if (rayTransp < 0.01) { // early ray termination
89 :     rayTransp = 0.0;
90 : glk 866 stabilize;
91 :     }
92 :     if (rayN > camVspFar) {
93 :     stabilize;
94 :     }
95 :     rayN = rayN + rayStep;
96 :     }
97 :    
98 : glk 1528 stabilize {
99 :     outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp];
100 :     }
101 :    
102 : glk 866 /* render: output maxval */
103 :     }
104 :    
105 :     initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ];

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