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

SCM Repository

[diderot] Annotation of /branches/vis12/rtest/tests/vr-taxi/vr-taxi.diderot
ViewVC logotype

Annotation of /branches/vis12/rtest/tests/vr-taxi/vr-taxi.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1809 - (view) (download)

1 : jhr 1809 /*! \file vr-taxi.diderot
2 :     *
3 :     * \author Gordon Kindlmann
4 :     *
5 :     * volume renders test axis dataset
6 :     */
7 : glk 1208
8 : jhr 1809 /*
9 :     * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
10 :     * All rights reserved.
11 :     */
12 : glk 1208
13 :     vec3 camEye = [35.1699, 30.3308, 18.77];
14 :     vec3 camAt = [5.26698, 4.74983, 4.66349];
15 :     vec3 camUp = [0.0, 0.0, 1.0];
16 :     real camNear = -2.0;
17 :     real camFar = 4.0;
18 :     real camFOV = 9.5;
19 :     int imgResU = 320;
20 :     int imgResV = 240;
21 :     real rayStep = 0.1;
22 :     real valOpacMin = 0.2;
23 :     real valOpacMax = 0.5;
24 :     vec3 backRGB = [0.8, 0.9, 1.0];
25 :    
26 :     real camDist = |camAt - camEye|;
27 :     real camVspNear = camDist + camNear;
28 :     real camVspFar = camDist + camFar;
29 :     vec3 camN = normalize(camAt - camEye);
30 :     vec3 camU = normalize(camN × camUp);
31 :     vec3 camV = camN × camU;
32 :     real camVmax = tan(camFOV*π/360.0)*camDist;
33 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
34 :    
35 :     vec3 lightVspDir = [0.9, -1.0, -2.5];
36 :     vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN);
37 :     vec3 lightRGB = [1.0, 0.9, 0.8];
38 :    
39 :     real phongKa = 0.05;
40 :     real phongKd = 0.65;
41 :     real phongKs = 0.45;
42 :     real phongSp = 50.0;
43 :    
44 :     field#1(3)[] F = ctmr ⊛ load("../../data/taxi.nrrd");
45 :    
46 :     strand RayCast (int ui, int vi) {
47 :     real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5);
48 :     real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5);
49 :     vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist;
50 :     vec3 toEye = normalize(-rayVec);
51 :    
52 :     real rayN = camVspNear;
53 :     real rayTransp = 1.0;
54 :     vec3 rayRGB = [0.0, 0.0, 0.0];
55 : jhr 1809 output vec3 out = [0.0, 0.0, 0.0];
56 : glk 1208
57 :     update {
58 :     vec3 rayPos = camEye + rayN*rayVec;
59 :     if (inside (rayPos,F)) {
60 :     real val = F(rayPos);
61 :     if (val > valOpacMin) { // we have some opacity
62 :     vec3 grad = ∇F(rayPos); // (here as easy target for optimization)
63 :     vec3 norm = normalize(-∇F(rayPos));
64 :     real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax));
65 :     real ld = max(0.0, norm • lightDir);
66 :     real hd = max(0.0, norm • normalize(lightDir + toEye));
67 :     // contrived assignment of RGB from XYZ, only sensible
68 :     vec3 matRGB = [lerp(0.2, 1.0, 1.0, rayPos[0], 8.0)^0.8,
69 :     lerp(0.2, 1.0, 1.0, rayPos[1], 8.0)^0.8,
70 :     lerp(0.2, 1.0, 1.0, rayPos[2], 8.0)^0.8];
71 :     vec3 pntRGB = (phongKa*matRGB
72 :     + phongKd*ld*modulate(matRGB, lightRGB)
73 :     + phongKs*hd^phongSp*lightRGB);
74 :     rayRGB = rayRGB + rayTransp*alpha*pntRGB;
75 :     rayTransp = rayTransp*(1.0 - alpha);
76 :     }
77 :     }
78 :     if (rayTransp < 0.001) { // early ray termination
79 : jhr 1809 out = rayRGB;
80 : glk 1208 stabilize;
81 :     }
82 :     if (rayN > camVspFar) {
83 : jhr 1809 out = lerp(rayRGB, backRGB, rayTransp);
84 : glk 1208 stabilize;
85 :     }
86 :     rayN = rayN + rayStep;
87 :     }
88 :    
89 :     }
90 :    
91 :     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