SCM Repository
Annotation of /trunk/test/vr-curv-quad.diderot
Parent Directory
|
Revision Log
Revision 1124 - (view) (download)
1 : | jhr | 1115 | // vr-curv |
2 : | // | ||
3 : | // Demonstration of curvature-based transfer functions in volume rendering | ||
4 : | // | ||
5 : | // process output with: | ||
6 : | // unu reshape -i mip.txt -s 4 480 345 | overrgb -i - -b 0.1 0.15 0.2 -g 1.2 -o - | unu quantize -b 8 -min 0 -max 255 -o vr-curv-quad.png | ||
7 : | |||
8 : | field#2(3)[] F = bspln3 ⊛ load("../data/quad-patches-pad.nrrd"); | ||
9 : | field#0(2)[3] RGB = tent ⊛ load("../data/txf/2d-bow.nrrd"); | ||
10 : | |||
11 : | // set camera, image, and rendering parameters | ||
12 : | vec3 camEye = [183.021, -411.857, 686.458]; | ||
13 : | vec3 camAt = [55.4037, 40.2407, 4.32732]; | ||
14 : | vec3 camUp = [0.0, 0.0, 1.0]; | ||
15 : | real camNear = -42.0; | ||
16 : | real camFar = 42.0; | ||
17 : | real camFOV = 7.15; | ||
18 : | int imgResU = 480; | ||
19 : | int imgResV = 345; | ||
20 : | real rayStep = 0.2; | ||
21 : | real valOpacMin = -0.25; | ||
22 : | real valOpacMax = -0.10; | ||
23 : | vec3 lightVspDir = [0.9, -2.5, -2.5]; | ||
24 : | vec3 lightRGB = [1.0, 1.0, 1.0]; | ||
25 : | real phongKa = 0.1; | ||
26 : | real phongKd = 0.7; | ||
27 : | real phongKs = 0.3; | ||
28 : | real phongSp = 45.0; | ||
29 : | |||
30 : | // (boilerplate) computation of camera and light info | ||
31 : | real camDist = |camAt - camEye|; | ||
32 : | real camVspNear = camNear + camDist; | ||
33 : | real camVspFar = camFar + camDist; | ||
34 : | vec3 camN = normalize(camAt - camEye); | ||
35 : | vec3 camU = normalize(camN × camUp); | ||
36 : | vec3 camV = camN × camU; | ||
37 : | real camVmax = tan(camFOV*π/360.0)*camDist; | ||
38 : | real camUmax = camVmax*real(imgResU)/real(imgResV); | ||
39 : | vec3 lightDir = normalize(lightVspDir[0]*camU + | ||
40 : | lightVspDir[1]*camV + | ||
41 : | lightVspDir[2]*camN); | ||
42 : | |||
43 : | strand RayCast (int ui, int vi) { | ||
44 : | real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5); | ||
45 : | real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5); | ||
46 : | vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist; | ||
47 : | glk | 1124 | vec3 vv = normalize(-rayVec); |
48 : | jhr | 1115 | |
49 : | real rayN = camVspNear; | ||
50 : | real rayTransp = 1.0; | ||
51 : | vec3 rayRGB = [0.0, 0.0, 0.0]; | ||
52 : | output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0]; | ||
53 : | |||
54 : | update { | ||
55 : | vec3 pos = camEye + rayN*rayVec; | ||
56 : | if (inside (pos,F)) { | ||
57 : | real val = F(pos); | ||
58 : | if (val > valOpacMin) { // we have some opacity | ||
59 : | vec3 grad = -∇F(pos); | ||
60 : | vec3 norm = normalize(grad); | ||
61 : | // begin curvature computation | ||
62 : | tensor[3,3] H = ∇(∇F)(pos); | ||
63 : | tensor[3,3] P = identity[3] - norm⊗norm; | ||
64 : | tensor[3,3] G = -(P•H•P)/|grad|; | ||
65 : | real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2)); | ||
66 : | real k1 = (trace(G) + disc)/2.0; | ||
67 : | real k2 = (trace(G) - disc)/2.0; | ||
68 : | // finished curvature computation; begin finding sample RGBA | ||
69 : | glk | 1124 | k1 = max(-1.0, min(1.0, 6.0*k1)); |
70 : | k2 = max(-1.0, min(1.0, 6.0*k2)); | ||
71 : | jhr | 1115 | vec3 matRGB = RGB([k1,k2]); |
72 : | real alpha = min(1.0, lerp(0.0, 1.0, | ||
73 : | valOpacMin, val, valOpacMax)); | ||
74 : | real ld = max(0.0, norm • lightDir); | ||
75 : | glk | 1124 | real hd = max(0.0, norm • normalize(lightDir + vv)); |
76 : | jhr | 1115 | // Phong shading |
77 : | vec3 pntRGB = (phongKa*matRGB | ||
78 : | + phongKd*ld*modulate(matRGB, lightRGB) | ||
79 : | + phongKs*hd^phongSp*lightRGB); | ||
80 : | // composite with existing ray color and transparency | ||
81 : | rayRGB = rayRGB + rayTransp*alpha*pntRGB; | ||
82 : | rayTransp = rayTransp*(1.0 - alpha); | ||
83 : | } | ||
84 : | } | ||
85 : | if (rayTransp < 0.01) { // early ray termination | ||
86 : | rayTransp = 0.0; | ||
87 : | outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp]; | ||
88 : | stabilize; | ||
89 : | } | ||
90 : | if (rayN > camVspFar) { | ||
91 : | outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp]; | ||
92 : | stabilize; | ||
93 : | } | ||
94 : | rayN = rayN + rayStep; | ||
95 : | } | ||
96 : | |||
97 : | /* render: output maxval */ | ||
98 : | } | ||
99 : | |||
100 : | 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 |