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