SCM Repository
Annotation of /branches/charisee_dev/examples/dti/dti-vr-byhand.diderot
Parent Directory
|
Revision Log
Revision 3283 - (view) (download)
1 : | cchiw | 3276 | |
2 : | input real isoval = 0.5; | ||
3 : | input real thick = 0.8; | ||
4 : | |||
5 : | |||
6 : | field#2(3)[3,3] V = bspln3 ⊛ image("/Users/chariseechiw/diderot/charisee_dev/ertest/data/tball.nrrd"); | ||
7 : | cchiw | 3283 | field#0(3)[3,3,3] G=∇⊗V; |
8 : | cchiw | 3276 | |
9 : | |||
10 : | |||
11 : | field#2(3)[3] hackRGB = bspln3 ⊛ image("/Users/chariseechiw/diderot/charisee_dev/data/const-curl3d.nrrd"); | ||
12 : | function vec3 color(vec3 x) = hackRGB(x); | ||
13 : | |||
14 : | |||
15 : | vec3 cutVec = [-1,-0.03,0.02]; | ||
16 : | real cutPos = -1.5; | ||
17 : | |||
18 : | real refStep = 1; | ||
19 : | |||
20 : | // set camera, image, and rendering parameters | ||
21 : | input vec3 camEye = [440.499, 66.673, 175.265]; | ||
22 : | input vec3 camAt = [69.6939, 103.067, 41.4651]; | ||
23 : | input vec3 camUp = [-0.0808311, 0.0976636, 0.991932]; | ||
24 : | input real camNearAtRel = -90; | ||
25 : | input real camFarAtRel = 90; | ||
26 : | input real camFOV = 17; | ||
27 : | input int iresU = 520; | ||
28 : | input int iresV = 370; | ||
29 : | input real phongKa = 0.3; | ||
30 : | input real phongKd = 0.7; | ||
31 : | input real rayStep = 0.4; | ||
32 : | input vec3 lightVsp = [-2.0, -2.5, -8.0]; | ||
33 : | |||
34 : | // (boilerplate) computation of camera and light info | ||
35 : | real camDist = |camAt - camEye|; | ||
36 : | real camNear = camNearAtRel + camDist; | ||
37 : | real camFar = camFarAtRel + camDist; | ||
38 : | vec3 camN = normalize(camAt - camEye); // away from eye | ||
39 : | vec3 camU = normalize(camN × camUp); // right | ||
40 : | vec3 camV = camN × camU; // down | ||
41 : | real camVmax = tan(camFOV*π/360)*camDist; | ||
42 : | real camUmax = camVmax*iresU/iresV; | ||
43 : | vec3 light = transpose([camU,camV,camN])•normalize(lightVsp); | ||
44 : | |||
45 : | function real alpha(real v, real g) = 1.0 if (v > 0) else clamp(0, 1, 1.3*(1 - |v|/(g*thick))); | ||
46 : | |||
47 : | strand raycast(int ui, int vi) { | ||
48 : | real rayU = lerp(-camUmax, camUmax, -0.5, ui, iresU-0.5); | ||
49 : | real rayV = lerp(-camVmax, camVmax, -0.5, vi, iresV-0.5); | ||
50 : | real rayN = camNear; | ||
51 : | vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist; | ||
52 : | real transp = 1; | ||
53 : | vec3 rgb = [0, 0, 0]; | ||
54 : | output vec4 rgba = [0, 0, 0, 0]; | ||
55 : | |||
56 : | update { | ||
57 : | vec3 x = camEye + rayN*rayVec; | ||
58 : | if (inside(x,V) && (x - camAt)•normalize(cutVec) > cutPos) { | ||
59 : | real val = 0; | ||
60 : | vec3 grad = [0,0,0]; | ||
61 : | cchiw | 3283 | |
62 : | |||
63 : | real m=|V(x)|; | ||
64 : | tensor[3,3,3] g=G(x); | ||
65 : | tensor[3] t1=(1/2)*(V(x):g+g:V(x))/m; | ||
66 : | cchiw | 3276 | |
67 : | cchiw | 3283 | vec3 t2=[g[0,0,0]+g[0,1,1]+g[0,2,2],g[1,0,0]+g[1,1,1]+g[1,2,2],g[2,0,0]+g[2,1,1]+g[2,2,2]]; |
68 : | tensor [3,3] E = V(x) - trace(V(x))*identity[3]/3; | ||
69 : | tensor[3,3,3] t3= g-t2⊗identity[3]/3; | ||
70 : | real t4=|E|; | ||
71 : | tensor [3] t5=(1/2)*(t3:E +E:t3)/(E:E); | ||
72 : | cchiw | 3276 | |
73 : | cchiw | 3283 | val=sqrt(3.0/2.0)*t4/m - isoval; |
74 : | |||
75 : | real t8=sqrt(3.0/2.0); | ||
76 : | vec3 t6 =(m*t5); | ||
77 : | vec3 t7 = (t4*t1); | ||
78 : | grad =t8*(t6- t7)/(m*m); | ||
79 : | cchiw | 3276 | |
80 : | real a = alpha(val, |grad|); | ||
81 : | if (a > 0) { | ||
82 : | a = 1 - pow(1-a, rayStep); | ||
83 : | real depth = lerp(1.1, 0.8, camNear, rayN, camFar); | ||
84 : | real shade = max(0, normalize(grad)•light); | ||
85 : | vec3 thisrgb = (phongKa + phongKd*shade)*color(x); | ||
86 : | if ((x - camAt)•normalize(cutVec) < cutPos + 1.1*rayStep) { | ||
87 : | thisrgb = phongKd*color(x); | ||
88 : | } | ||
89 : | rgb += transp*a*depth*thisrgb; | ||
90 : | transp *= 1 - a; | ||
91 : | } | ||
92 : | } | ||
93 : | if (transp < 0.01) { // early ray termination | ||
94 : | transp = 0; | ||
95 : | stabilize; | ||
96 : | } | ||
97 : | if (rayN > camFar) { | ||
98 : | stabilize; | ||
99 : | } | ||
100 : | rayN = rayN + rayStep; | ||
101 : | } | ||
102 : | stabilize { | ||
103 : | real a = 1-transp; | ||
104 : | if (a > 0) rgba = [rgb[0]/a, rgb[1]/a, rgb[2]/a, a]; | ||
105 : | } | ||
106 : | } | ||
107 : | initially [ raycast(ui, vi) | vi in 0..iresV-1, ui in 0..iresU-1 ]; |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |