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 1604 - (view) (download)

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