8 |
// process output with: |
// process output with: |
9 |
// 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-lite-cam.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-lite-cam.png |
10 |
|
|
|
//string dataFile = "../data/txs-pad3.nrrd"; |
|
|
//vec3 camEye = [25.0, 15.0, 10.0]; |
|
|
//vec3 camAt = [3.0, 3.0, 3.0]; |
|
|
//vec3 camUp = [0.0, 0.0, 1.0]; |
|
|
//real camNear = -5.0; |
|
|
//real camFar = 5.0; |
|
|
//real camFOV = 16.0; |
|
|
//int imgResU = 480; |
|
|
//int imgResV = 345; |
|
|
//real rayStep = 0.1; |
|
|
//real valOpacMin = 0.15; // highest value with opacity 0.0 |
|
|
//real valOpacMax = 0.20; // lowest value with opacity 1.0 |
|
|
|
|
11 |
string dataFile = "../../data/vfrhand-nohip.nhdr"; |
string dataFile = "../../data/vfrhand-nohip.nhdr"; |
12 |
vec3 camEye = [127.331, -1322.05, 272.53]; |
vec3 camEye = [127.331, -1322.05, 272.53]; |
13 |
vec3 camAt = [63.0, 82.6536, 98.0]; |
vec3 camAt = [63.0, 82.6536, 98.0]; |
32 |
|
|
33 |
vec3 lightVspDir = [0.9, -1.0, -2.5]; |
vec3 lightVspDir = [0.9, -1.0, -2.5]; |
34 |
vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN); |
vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN); |
|
//vec3 lightRGB = [1.0, 1.0, 1.0]; |
|
35 |
|
|
36 |
real phongKa = 0.05; |
real phongKa = 0.05; |
37 |
real phongKd = 0.65; |
real phongKd = 0.65; |
38 |
real phongKs = 0.45; |
real phongKs = 0.45; |
39 |
real phongSp = 50.0; |
real phongSp = 50.0; |
40 |
|
|
|
//field#4(3)[] F = bspln5 ⊛ load(dataFile); |
|
41 |
field#2(3)[] F = bspln3 ⊛ load(dataFile); |
field#2(3)[] F = bspln3 ⊛ load(dataFile); |
|
//field#1(3)[] F = ctmr ⊛ load(dataFile); |
|
|
//field#1(3)[] F = c1tent ⊛ load(dataFile); |
|
42 |
|
|
43 |
strand RayCast (int ui, int vi) |
strand RayCast (int ui, int vi) |
44 |
{ |
{ |
48 |
vec3 toEye = normalize(-rayVec); |
vec3 toEye = normalize(-rayVec); |
49 |
|
|
50 |
real rayN = camVspNear; |
real rayN = camVspNear; |
|
// ########## BEGIN per-ray initialization |
|
51 |
real rayTransp = 1.0; |
real rayTransp = 1.0; |
|
// vec3 rayRGB = [0.0, 0.0, 0.0]; |
|
52 |
real rayGrey = 0.0; |
real rayGrey = 0.0; |
53 |
output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0]; |
output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0]; |
|
// ########## END per-ray initialization |
|
54 |
|
|
55 |
update |
update { |
|
{ |
|
56 |
vec3 rayPos = camEye + rayN*rayVec; |
vec3 rayPos = camEye + rayN*rayVec; |
57 |
if (inside (rayPos,F)) { |
if (inside (rayPos,F)) { |
|
// ########## BEGIN per-sample code |
|
58 |
real val = F(rayPos); |
real val = F(rayPos); |
59 |
if (val > valOpacMin) { // we have some opacity |
if (val > valOpacMin) { // we have some opacity |
60 |
vec3 grad = ∇F(rayPos); // (here as easy target for optimization) |
vec3 grad = ∇F(rayPos); // (here as easy target for optimization) |
62 |
real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax)); |
real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax)); |
63 |
real ld = max(0.0, norm • lightDir); |
real ld = max(0.0, norm • lightDir); |
64 |
real hd = max(0.0, norm • normalize(lightDir + toEye)); |
real hd = max(0.0, norm • normalize(lightDir + toEye)); |
|
// contrived assignment of RGB from XYZ, only sensible |
|
|
// for txs-pad3.nrrd, not for vfrhand-nohip.nhdr!! |
|
|
// vec3 matRGB = [lerp(0.2, 1.0, 1.0, rayPos[0], 8.0), |
|
|
// lerp(0.2, 1.0, 1.0, rayPos[1], 8.0), |
|
|
// lerp(0.2, 1.0, 1.0, rayPos[2], 8.0)]; |
|
|
// vec3 pntRGB = (phongKa*matRGB |
|
|
// + phongKd*ld*modulate(matRGB, lightRGB) |
|
|
// + phongKs*hd^phongSp*lightRGB); |
|
|
// rayRGB += rayTransp*alpha*pntRGB; |
|
65 |
real mat = lerp(0.2, 1.0, 1.0, rayPos[0], 8.0); |
real mat = lerp(0.2, 1.0, 1.0, rayPos[0], 8.0); |
66 |
real pnt = phongKa * mat |
real pnt = phongKa * mat |
67 |
+ phongKd * ld * mat |
+ phongKd * ld * mat |
69 |
rayGrey += rayTransp*alpha*pnt; |
rayGrey += rayTransp*alpha*pnt; |
70 |
rayTransp = rayTransp*(1.0 - alpha); |
rayTransp = rayTransp*(1.0 - alpha); |
71 |
} |
} |
|
// ########## END per-sample code |
|
72 |
} |
} |
73 |
if (rayTransp < 0.01) { // early ray termination |
if (rayTransp < 0.01) { // early ray termination |
74 |
rayTransp = 0.0; |
rayTransp = 0.0; |
|
// outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */ |
|
|
outRGBA = [rayGrey, rayGrey, rayGrey, 1.0-rayTransp]; /* FIXME */ |
|
75 |
stabilize; |
stabilize; |
76 |
} |
} |
77 |
if (rayN > camVspFar) { |
if (rayN > camVspFar) { |
|
// outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */ |
|
|
outRGBA = [rayGrey, rayGrey, rayGrey, 1.0-rayTransp]; /* FIXME */ |
|
78 |
stabilize; |
stabilize; |
79 |
} |
} |
80 |
rayN += rayStep; |
rayN += rayStep; |
81 |
} |
} |
82 |
|
|
83 |
stabilize { |
stabilize { |
84 |
// outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; |
outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; |
85 |
} |
} |
86 |
|
|
87 |
} |
} |