1 |
// vr-curv |
// vr-curv-quad |
2 |
// |
// |
3 |
// Demonstration of curvature-based transfer functions in volume rendering |
// Demonstration of curvature-based transfer functions in volume rendering |
4 |
// |
// |
5 |
// process output with: |
// 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 |
// 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 |
|
// volume dataset |
9 |
field#2(3)[] F = bspln3 ⊛ load("../data/quad-patches-pad.nrrd"); |
field#2(3)[] F = bspln3 ⊛ load("../data/quad-patches-pad.nrrd"); |
10 |
|
|
11 |
|
// RGB colormap of (kappa1,kapp2) |
12 |
field#0(2)[3] RGB = tent ⊛ load("../data/txf/2d-bow.nrrd"); |
field#0(2)[3] RGB = tent ⊛ load("../data/txf/2d-bow.nrrd"); |
13 |
|
|
14 |
// set camera, image, and rendering parameters |
// set camera, image, and rendering parameters |
30 |
real phongKs = 0.3; |
real phongKs = 0.3; |
31 |
real phongSp = 45.0; |
real phongSp = 45.0; |
32 |
|
|
33 |
// (boilerplate) computation of camera and light info |
// boilerplate computation of camera and light info |
34 |
real camDist = |camAt - camEye|; |
real camDist = |camAt - camEye|; |
35 |
real camVspNear = camNear + camDist; |
real camVspNear = camNear + camDist; |
36 |
real camVspFar = camFar + camDist; |
real camVspFar = camFar + camDist; |
43 |
lightVspDir[1]*camV + |
lightVspDir[1]*camV + |
44 |
lightVspDir[2]*camN); |
lightVspDir[2]*camN); |
45 |
|
|
46 |
|
// RayCast(ui,vi) computes rendered color for pixel (ui,vi) |
47 |
strand RayCast (int ui, int vi) { |
strand RayCast (int ui, int vi) { |
48 |
real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5); |
real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5); |
49 |
real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5); |
real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5); |
69 |
real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2)); |
real disc = max(0.0, sqrt(2.0*|G|^2 - trace(G)^2)); |
70 |
real k1 = (trace(G) + disc)/2.0; |
real k1 = (trace(G) + disc)/2.0; |
71 |
real k2 = (trace(G) - disc)/2.0; |
real k2 = (trace(G) - disc)/2.0; |
72 |
// finished curvature computation; begin finding sample RGBA |
// find material RGBA |
73 |
k1 = max(-1.0, min(1.0, 6.0*k1)); |
vec3 matRGB = RGB([max(-1.0, min(1.0, 6.0*k1)), |
74 |
k2 = max(-1.0, min(1.0, 6.0*k2)); |
max(-1.0, min(1.0, 6.0*k2))]); |
|
vec3 matRGB = RGB([k1,k2]); |
|
75 |
real alpha = min(1.0, lerp(0.0, 1.0, |
real alpha = min(1.0, lerp(0.0, 1.0, |
76 |
valOpacMin, val, valOpacMax)); |
valOpacMin, val, valOpacMax)); |
77 |
real ld = max(0.0, norm • lightDir); |
real ld = max(0.0, norm • lightDir); |
97 |
rayN = rayN + rayStep; |
rayN = rayN + rayStep; |
98 |
} |
} |
99 |
|
|
100 |
/* render: output maxval */ |
// stabilize { |
101 |
|
// outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0 - rayTransp]; |
102 |
|
// } |
103 |
|
|
104 |
} |
} |
105 |
|
|
106 |
initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ]; |
initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ]; |