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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

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