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

1 : jhr 1602 // bmark-diderot.diderot
2 : jhr 1533 //
3 : jhr 3349 // This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     //
5 :     // COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 1602 // All rights reserved.
7 :     //
8 : jhr 1533 // simple volume renderer, now with a single directional light,
9 :     // Phong shading, and the new camera.
10 :     //
11 :    
12 :     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 : glk 1599 real phongKd = 0.80;
38 :     real phongKs = 0.20;
39 : jhr 1533 real phongSp = 50.0;
40 :    
41 : jhr 3052 field#2(3)[] F = bspln3 ⊛ image("../../data/vfrhand-nohip.nhdr");
42 : jhr 1533
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 : glk 1599 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 pnt = phongKa
66 :     + phongKd * ld
67 :     + phongKs * hd^phongSp;
68 :     rayGrey += rayTransp*alpha*pnt;
69 :     rayTransp = rayTransp*(1.0 - alpha);
70 :     }
71 : jhr 1533 }
72 :     if (rayTransp < 0.01) { // early ray termination
73 :     rayTransp = 0.0;
74 :     stabilize;
75 :     }
76 :     if (rayN > camVspFar) {
77 :     stabilize;
78 :     }
79 :     rayN += rayStep;
80 :     }
81 :    
82 :     stabilize {
83 : jhr 1586 outRGBA = [rayGrey, rayGrey, rayGrey, 1.0-rayTransp];
84 : jhr 1533 }
85 :    
86 :     }
87 :    
88 :     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