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

SCM Repository

[diderot] Annotation of /benchmarks/programs/illust-vr/bmark-diderot.diderot
ViewVC logotype

Annotation of /benchmarks/programs/illust-vr/bmark-diderot.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3052 - (view) (download)

1 : jhr 1581 // illust-vr
2 :     //
3 :     // Demonstration of "illustrative volume rendering"
4 :     //
5 :     // process output with:
6 :     // unu reshape -i illust-vr.txt -s 4 640 480 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255 -o illust-vr.png
7 :    
8 : jhr 3052 //field#2(3)[] F = bspln3 ⊛ image("../data/vfrhand-nohip.nhdr");
9 :     field#2(3)[] F = bspln3 ⊛ image("../../data/vfrhand-nohip-smooth.nrrd");
10 : jhr 1581
11 : jhr 3052 field#0(1)[] silho = tent ⊛ image("../../data/txf/silho.nrrd");
12 :     field#0(1)[] shade = tent ⊛ image("../../data/txf/shade.nrrd");
13 :     field#0(2)[] rival = tent ⊛ image("../../data/txf/ridgvall.nrrd");
14 :     field#0(2)[] alpha = tent ⊛ image("../../data/txf/alpha-bone.nrrd"); // image("../data/txf/alpha-skin.nrrd");
15 :     field#0(1)[3] depth = tent ⊛ image("../../data/txf/depth.nrrd");
16 : jhr 1581
17 :     // set camera, image, and rendering parameters
18 :     vec3 camEye = [127.331, -1322.05, 272.53];
19 :     vec3 camAt = [63.0, 82.6536, 98.0];
20 :     vec3 camUp = [0.9987, 0.0459166, -0.0221267];
21 :     real camNear = -78.0;
22 :     real camFar = 78.0;
23 :     real camFOV = 5.0;
24 : glk 1610
25 : jhr 1581 int imgResU = 640;
26 :     int imgResV = 480;
27 :     real rayStep = 0.15;
28 : glk 1610 /*
29 :     int imgResU = 480;
30 :     int imgResV = 360;
31 :     real rayStep = 1.0;
32 :     */
33 : jhr 1581 vec3 lightVspDir = [-2.0, -3.0, -2.0];
34 :     real sthick = 0.4;
35 :     real refStep = 1.5;
36 :    
37 :     // (boilerplate) computation of camera and light info
38 :     real camDist = |camAt - camEye|;
39 :     real camVspNear = camNear + camDist;
40 :     real camVspFar = camFar + camDist;
41 :     vec3 camN = normalize(camAt - camEye);
42 :     vec3 camU = normalize(camN × camUp);
43 :     vec3 camV = camN × camU;
44 :     real camVmax = tan(camFOV*π/360.0)*camDist;
45 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
46 :     vec3 lightDir = normalize(lightVspDir[0]*camU +
47 :     lightVspDir[1]*camV +
48 :     lightVspDir[2]*camN);
49 :    
50 :     strand RayCast (int ui, int vi) {
51 :     real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
52 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
53 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
54 :     vec3 vv = -normalize(rayVec);
55 :    
56 :     real rayN = camVspNear;
57 :     real rayTransp = 1.0;
58 :     vec3 rayRGB = [0.0, 0.0, 0.0];
59 :     output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0];
60 :    
61 :     update {
62 :     vec3 pos = camEye + rayN*rayVec;
63 :     if (inside (pos,F)) {
64 :     real val = F(pos);
65 :     vec3 grad = -∇F(pos);
66 :     real gmag = |grad|;
67 :     real aa = alpha([max(0.0, min(2000.0, val)), max(0.0, min(900.0, gmag))]);
68 :     if (aa > 0.0) { // we have some opacity
69 :     vec3 norm = grad/gmag;
70 :     aa = 1.0 - pow(1.0-aa, rayStep/refStep);
71 :     real gray = 1.0;
72 : jhr 1613 gray *= shade(norm • lightDir);
73 : jhr 1581 tensor[3,3] Proj = identity[3];
74 :     tensor[3,3] Gten = identity[3];
75 : jhr 1613 tensor[3,3] Hess = ∇⊗∇F(pos);
76 :     Proj = identity[3] - norm⊗norm;
77 :     Gten = -(Proj•Hess•Proj)/gmag;
78 :     real kv = max(0.0, min(1.0/sthick, (vv•Gten•vv)/(vv•Proj•vv)));
79 :     real vdn = vv•norm;
80 :     vdn = vdn*(1.0 + 2.0*vdn*vdn); // limit silhouette on front-facing surfaces
81 :     gray *= silho(max(0.0, min(2.0, vdn^2 + (sthick*(kv - 1.0/sthick))^2)));
82 :     real disc = max(0.0, sqrt(2.0*|Gten|^2 - trace(Gten)^2));
83 :     real k1 = (trace(Gten) + disc)/2.0;
84 :     real k2 = (trace(Gten) - disc)/2.0;
85 :     gray *= rival([min(0.55, |Gten|)/0.55, atan2(k2,k1)]);
86 : jhr 1655 vec3 matRGB = depth(lerp(0.0, 1.0, camVspNear, rayN, camVspFar));
87 : jhr 1581 rayRGB = rayRGB + rayTransp*aa*gray*matRGB;
88 :     rayTransp = rayTransp*(1.0 - aa);
89 :     }
90 :     }
91 :     if (rayTransp < 0.01) { // early ray termination
92 :     rayTransp = 0.0;
93 :     stabilize;
94 :     }
95 :     if (rayN > camVspFar) {
96 :     stabilize;
97 :     }
98 :     rayN = rayN + rayStep;
99 :     }
100 : glk 1610
101 :     stabilize {
102 :     rayRGB = 0.9*rayRGB;
103 :     outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp];
104 :     }
105 : jhr 1581 }
106 :    
107 :     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