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

SCM Repository

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

Annotation of /benchmarks/programs/vr-lite-cam/bmark-diderot.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1581 - (view) (download)

1 : jhr 1533 // vr-lite-cam
2 :     //
3 :     // simple volume renderer, now with a single directional light,
4 :     // Phong shading, and the new camera.
5 :     //
6 :     // The main thing missing from this is a more general transfer function
7 :     //
8 :     // process output with:
9 :     // 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-lite-cam.png
10 :    
11 : jhr 1572 string dataFile = "../../data/vfrhand-nohip.nhdr";
12 : jhr 1533 vec3 camEye = [127.331, -1322.05, 272.53];
13 :     vec3 camAt = [63.0, 82.6536, 98.0];
14 :     vec3 camUp = [0.9987, 0.0459166, -0.0221267];
15 :     real camNear = -78.0;
16 :     real camFar = 78.0;
17 :     real camFOV = 5.0;
18 :     int imgResU = 480;
19 :     int imgResV = 345;
20 :     real rayStep = 0.1;
21 :     real valOpacMin = 400.0; // 400.0 for skin, 1150.0 for bone
22 :     real valOpacMax = 700.0; // 700.0 for skin, 1450.0 for bone
23 :    
24 :     real camDist = |camAt - camEye|;
25 :     real camVspNear = camDist + camNear;
26 :     real camVspFar = camDist + camFar;
27 :     vec3 camN = normalize(camAt - camEye);
28 :     vec3 camU = normalize(camN × camUp);
29 :     vec3 camV = camN × camU;
30 :     real camVmax = tan(camFOV*π/360.0)*camDist;
31 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
32 :    
33 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
34 :     vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
35 :    
36 :     real phongKa = 0.05;
37 :     real phongKd = 0.65;
38 :     real phongKs = 0.45;
39 :     real phongSp = 50.0;
40 :    
41 :     field#2(3)[] F = bspln3 ⊛ load(dataFile);
42 :    
43 :     strand RayCast (int ui, int vi)
44 :     {
45 :     real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
46 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
47 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
48 :     vec3 toEye = normalize(-rayVec);
49 :    
50 :     real rayN = camVspNear;
51 :     real rayTransp = 1.0;
52 :     real rayGrey = 0.0;
53 :     output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0];
54 :    
55 : jhr 1581 update {
56 : jhr 1533 vec3 rayPos = camEye + rayN*rayVec;
57 :     if (inside (rayPos,F)) {
58 :     real val = F(rayPos);
59 :     if (val > valOpacMin) { // we have some opacity
60 :     vec3 grad = ∇F(rayPos); // (here as easy target for optimization)
61 :     vec3 norm = normalize(-∇F(rayPos));
62 :     real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
63 :     real ld = max(0.0, norm • lightDir);
64 :     real hd = max(0.0, norm • normalize(lightDir + toEye));
65 :     real mat = lerp(0.2, 1.0, 1.0, rayPos[0], 8.0);
66 :     real pnt = phongKa * mat
67 :     + phongKd * ld * mat
68 :     + phongKs * hd^phongSp;
69 :     rayGrey += rayTransp*alpha*pnt;
70 :     rayTransp = rayTransp*(1.0 - alpha);
71 :     }
72 :     }
73 :     if (rayTransp < 0.01) { // early ray termination
74 :     rayTransp = 0.0;
75 :     stabilize;
76 :     }
77 :     if (rayN > camVspFar) {
78 :     stabilize;
79 :     }
80 :     rayN += rayStep;
81 :     }
82 :    
83 :     stabilize {
84 : jhr 1581 outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp];
85 : jhr 1533 }
86 :    
87 :     }
88 :    
89 :     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