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 1208 - (view) (download)
Original Path: trunk/rtest/tests/vr-taxi/vr-taxi.diderot

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