SCM Repository
Annotation of /benchmarks/programs/vr-lite-cam/bmark-diderot.diderot
Parent Directory
|
Revision Log
Revision 1533 - (view) (download)
1 : | jhr | 1533 | // vr-lite-cam |
2 : | // | ||
3 : | // simple volume renderer, now with a single directional light, | ||
4 : | // Phong shading, and the new camera. | ||
5 : | // | ||
6 : | // The main thing missing from this is a more general transfer function | ||
7 : | // | ||
8 : | // 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 | ||
10 : | |||
11 : | //string dataFile = "../data/txs-pad3.nrrd"; | ||
12 : | //vec3 camEye = [25.0, 15.0, 10.0]; | ||
13 : | //vec3 camAt = [3.0, 3.0, 3.0]; | ||
14 : | //vec3 camUp = [0.0, 0.0, 1.0]; | ||
15 : | //real camNear = -5.0; | ||
16 : | //real camFar = 5.0; | ||
17 : | //real camFOV = 16.0; | ||
18 : | //int imgResU = 480; | ||
19 : | //int imgResV = 345; | ||
20 : | //real rayStep = 0.1; | ||
21 : | //real valOpacMin = 0.15; // highest value with opacity 0.0 | ||
22 : | //real valOpacMax = 0.20; // lowest value with opacity 1.0 | ||
23 : | |||
24 : | string dataFile = "../data/vfrhand-nohip.nhdr"; | ||
25 : | vec3 camEye = [127.331, -1322.05, 272.53]; | ||
26 : | vec3 camAt = [63.0, 82.6536, 98.0]; | ||
27 : | vec3 camUp = [0.9987, 0.0459166, -0.0221267]; | ||
28 : | real camNear = -78.0; | ||
29 : | real camFar = 78.0; | ||
30 : | real camFOV = 5.0; | ||
31 : | int imgResU = 480; | ||
32 : | int imgResV = 345; | ||
33 : | real rayStep = 0.1; | ||
34 : | real valOpacMin = 400.0; // 400.0 for skin, 1150.0 for bone | ||
35 : | real valOpacMax = 700.0; // 700.0 for skin, 1450.0 for bone | ||
36 : | |||
37 : | real camDist = |camAt - camEye|; | ||
38 : | real camVspNear = camDist + camNear; | ||
39 : | real camVspFar = camDist + camFar; | ||
40 : | vec3 camN = normalize(camAt - camEye); | ||
41 : | vec3 camU = normalize(camN × camUp); | ||
42 : | vec3 camV = camN × camU; | ||
43 : | real camVmax = tan(camFOV*π/360.0)*camDist; | ||
44 : | real camUmax = camVmax*real(imgResU)/real(imgResV); | ||
45 : | |||
46 : | vec3 lightVspDir = [0.9, -1.0, -2.5]; | ||
47 : | vec3 lightDir = normalize(lightVspDir[0]*camU + lightVspDir[1]*camV + lightVspDir[2]*camN); | ||
48 : | //vec3 lightRGB = [1.0, 1.0, 1.0]; | ||
49 : | |||
50 : | real phongKa = 0.05; | ||
51 : | real phongKd = 0.65; | ||
52 : | real phongKs = 0.45; | ||
53 : | real phongSp = 50.0; | ||
54 : | |||
55 : | //field#4(3)[] F = bspln5 ⊛ load(dataFile); | ||
56 : | field#2(3)[] F = bspln3 ⊛ load(dataFile); | ||
57 : | //field#1(3)[] F = ctmr ⊛ load(dataFile); | ||
58 : | //field#1(3)[] F = c1tent ⊛ load(dataFile); | ||
59 : | |||
60 : | strand RayCast (int ui, int vi) | ||
61 : | { | ||
62 : | real rayU = lerp(-camUmax, camUmax, -0.5, real(ui), real(imgResU)-0.5); | ||
63 : | real rayV = lerp(-camVmax, camVmax, -0.5, real(vi), real(imgResV)-0.5); | ||
64 : | vec3 rayVec = (camDist*camN + rayU*camU + rayV*camV)/camDist; | ||
65 : | vec3 toEye = normalize(-rayVec); | ||
66 : | |||
67 : | real rayN = camVspNear; | ||
68 : | // ########## BEGIN per-ray initialization | ||
69 : | real rayTransp = 1.0; | ||
70 : | // vec3 rayRGB = [0.0, 0.0, 0.0]; | ||
71 : | real rayGrey = 0.0; | ||
72 : | output vec4 outRGBA = [0.0, 0.0, 0.0, 0.0]; | ||
73 : | // ########## END per-ray initialization | ||
74 : | |||
75 : | update | ||
76 : | { | ||
77 : | vec3 rayPos = camEye + rayN*rayVec; | ||
78 : | if (inside (rayPos,F)) { | ||
79 : | // ########## BEGIN per-sample code | ||
80 : | real val = F(rayPos); | ||
81 : | if (val > valOpacMin) { // we have some opacity | ||
82 : | vec3 grad = ∇F(rayPos); // (here as easy target for optimization) | ||
83 : | vec3 norm = normalize(-∇F(rayPos)); | ||
84 : | real alpha = min(1.0, lerp(0.0, 1.0, valOpacMin, val, valOpacMax)); | ||
85 : | real ld = max(0.0, norm • lightDir); | ||
86 : | real hd = max(0.0, norm • normalize(lightDir + toEye)); | ||
87 : | // contrived assignment of RGB from XYZ, only sensible | ||
88 : | // for txs-pad3.nrrd, not for vfrhand-nohip.nhdr!! | ||
89 : | // vec3 matRGB = [lerp(0.2, 1.0, 1.0, rayPos[0], 8.0), | ||
90 : | // lerp(0.2, 1.0, 1.0, rayPos[1], 8.0), | ||
91 : | // lerp(0.2, 1.0, 1.0, rayPos[2], 8.0)]; | ||
92 : | // vec3 pntRGB = (phongKa*matRGB | ||
93 : | // + phongKd*ld*modulate(matRGB, lightRGB) | ||
94 : | // + phongKs*hd^phongSp*lightRGB); | ||
95 : | // rayRGB += rayTransp*alpha*pntRGB; | ||
96 : | real mat = lerp(0.2, 1.0, 1.0, rayPos[0], 8.0); | ||
97 : | real pnt = phongKa * mat | ||
98 : | + phongKd * ld * mat | ||
99 : | + phongKs * hd^phongSp; | ||
100 : | rayGrey += rayTransp*alpha*pnt; | ||
101 : | rayTransp = rayTransp*(1.0 - alpha); | ||
102 : | } | ||
103 : | // ########## END per-sample code | ||
104 : | } | ||
105 : | if (rayTransp < 0.01) { // early ray termination | ||
106 : | rayTransp = 0.0; | ||
107 : | // outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */ | ||
108 : | outRGBA = [rayGrey, rayGrey, rayGrey, 1.0-rayTransp]; /* FIXME */ | ||
109 : | stabilize; | ||
110 : | } | ||
111 : | if (rayN > camVspFar) { | ||
112 : | // outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; /* FIXME */ | ||
113 : | outRGBA = [rayGrey, rayGrey, rayGrey, 1.0-rayTransp]; /* FIXME */ | ||
114 : | stabilize; | ||
115 : | } | ||
116 : | rayN += rayStep; | ||
117 : | } | ||
118 : | |||
119 : | stabilize { | ||
120 : | // outRGBA = [rayRGB[0], rayRGB[1], rayRGB[2], 1.0-rayTransp]; | ||
121 : | } | ||
122 : | |||
123 : | } | ||
124 : | |||
125 : | 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 |