27 | | while(num_iterations>0 && fragColor.a<cutoff) |
28 | | { |
29 | | vec4 color = texture3D( volumeTexture, texcoord); |
30 | | |
31 | | if (color.a>AlphaFuncValue) |
32 | | { |
33 | | float r = color.a * ((1.0-fragColor.a)*scale); |
34 | | fragColor.rgb += color.rgb*r; |
35 | | fragColor.a += r; |
36 | | } |
37 | | |
38 | | texcoord += dt; |
39 | | |
40 | | --num_iterations; |
41 | | } |
42 | | |
43 | | if (num_iterations>0) fragColor.a = 1.0; |
44 | | |
45 | | return fragColor; |
46 | | } |
47 | | |
48 | | vec4 accumulateSamplesTransferFunction(vec3 ts, vec3 te, vec3 dt, float scale, float cutoff, int num_iterations) |
49 | | { |
50 | | vec3 texcoord = te.xyz; |
51 | | vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); |
52 | | |
53 | | while(num_iterations>0 && fragColor.a<cutoff) |
54 | | { |
55 | | float a = texture3D( volumeTexture, texcoord).a; |
56 | | float v = a * tfScale + tfOffset; |
57 | | vec4 color = texture1D( tfTexture, v); |
58 | | |
59 | | if (a>AlphaFuncValue) |
60 | | { |
61 | | float r = color.a * ((1.0-fragColor.a)*scale); |
62 | | fragColor.rgb += color.rgb*r; |
63 | | fragColor.a += r; |
64 | | } |
65 | | |
66 | | texcoord += dt; |
67 | | |
68 | | --num_iterations; |
69 | | } |
70 | | |
71 | | if (num_iterations>0) fragColor.a = 1.0; |
72 | | |
73 | | return fragColor; |
74 | | } |
75 | | |
76 | | vec4 accumulateSamplesLighting(vec3 ts, vec3 te, vec3 dt, float scale, float cutoff, int num_iterations) |
77 | | { |
78 | | vec3 texcoord = te.xyz; |
79 | | vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); |
80 | | |
81 | | float normalSampleDistance = length(dt); |
82 | | vec3 deltaX = vec3(normalSampleDistance, 0.0, 0.0); |
83 | | vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0); |
84 | | vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance); |
85 | | |
86 | | while(num_iterations>0 && fragColor.a<cutoff) |
87 | | { |
88 | | vec4 color = texture3D( volumeTexture, texcoord); |
89 | | |
90 | | if (color.a>AlphaFuncValue) |
91 | | { |
92 | | |
93 | | float px = texture3D( volumeTexture, texcoord + deltaX).a; |
94 | | float py = texture3D( volumeTexture, texcoord + deltaY).a; |
95 | | float pz = texture3D( volumeTexture, texcoord + deltaZ).a; |
96 | | |
97 | | float nx = texture3D( volumeTexture, texcoord - deltaX).a; |
98 | | float ny = texture3D( volumeTexture, texcoord - deltaY).a; |
99 | | float nz = texture3D( volumeTexture, texcoord - deltaZ).a; |
100 | | |
101 | | vec3 grad = vec3(px-nx, py-ny, pz-nz); |
102 | | if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0) |
103 | | { |
104 | | vec3 normal = normalize(grad); |
105 | | float lightScale = 0.1 + max(0.0, dot(normal.xyz, lightDirection))*0.9; |
106 | | |
107 | | color.r *= lightScale; |
108 | | color.g *= lightScale; |
109 | | color.b *= lightScale; |
110 | | } |
111 | | |
112 | | float r = color.a * ((1.0-fragColor.a)*scale); |
113 | | fragColor.rgb += color.rgb*r; |
114 | | fragColor.a += r; |
115 | | } |
116 | | |
117 | | texcoord += dt; |
118 | | |
119 | | --num_iterations; |
120 | | } |
121 | | |
122 | | if (num_iterations>0) fragColor.a = 1.0; |
123 | | |
124 | | return fragColor; |
125 | | } |
126 | | |
127 | | vec4 accumulateSamplesLightingTransferFunction(vec3 ts, vec3 te, vec3 dt, float scale, float cutoff, int num_iterations) |
128 | | { |
129 | | vec3 texcoord = te.xyz; |
130 | | vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); |
131 | | |
132 | | float normalSampleDistance = length(dt); |
133 | | vec3 deltaX = vec3(normalSampleDistance, 0.0, 0.0); |
134 | | vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0); |
135 | | vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance); |
136 | | |
137 | | while(num_iterations>0 && fragColor.a<cutoff) |
138 | | { |
139 | | float a = texture3D( volumeTexture, texcoord).a; |
140 | | float v = a * tfScale + tfOffset; |
141 | | vec4 color = texture1D( tfTexture, v); |
142 | | |
143 | | if (a>AlphaFuncValue) |
144 | | { |
145 | | |
146 | | float px = texture3D( volumeTexture, texcoord + deltaX).a; |
147 | | float py = texture3D( volumeTexture, texcoord + deltaY).a; |
148 | | float pz = texture3D( volumeTexture, texcoord + deltaZ).a; |
149 | | |
150 | | float nx = texture3D( volumeTexture, texcoord - deltaX).a; |
151 | | float ny = texture3D( volumeTexture, texcoord - deltaY).a; |
152 | | float nz = texture3D( volumeTexture, texcoord - deltaZ).a; |
153 | | |
154 | | vec3 grad = vec3(px-nx, py-ny, pz-nz); |
155 | | if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0) |
156 | | { |
157 | | vec3 normal = normalize(grad); |
158 | | float lightScale = 0.1 + max(0.0, dot(normal.xyz, lightDirection))*0.9; |
159 | | |
160 | | color.r *= lightScale; |
161 | | color.g *= lightScale; |
162 | | color.b *= lightScale; |
163 | | } |
164 | | |
165 | | float r = color.a * ((1.0-fragColor.a)*scale); |
166 | | fragColor.rgb += color.rgb*r; |
167 | | fragColor.a += r; |
168 | | } |
169 | | |
170 | | texcoord += dt; |
171 | | |
172 | | --num_iterations; |
173 | | } |
174 | | |
175 | | if (num_iterations>0) fragColor.a = 1.0; |
176 | | |
177 | | return fragColor; |
178 | | } |
179 | | |
180 | | |
181 | | vec4 accumulateSamplesIsosurface(vec3 ts, vec3 te, vec3 dt, float scale, float cutoff, int num_iterations) |
182 | | { |
183 | | vec3 texcoord = te.xyz; |
184 | | |
185 | | float normalSampleDistance = length(dt); |
186 | | vec3 deltaX = vec3(normalSampleDistance, 0.0, 0.0); |
187 | | vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0); |
188 | | vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance); |
189 | | |
190 | | vec4 previousColor = texture3D( volumeTexture, texcoord); |
191 | | |
192 | | float targetValue = IsoSurfaceValue; |
193 | | |
194 | | while(num_iterations>0) |
195 | | { |
196 | | vec4 color = texture3D( volumeTexture, texcoord); |
197 | | |
198 | | float m = (previousColor.a-targetValue) * (color.a-targetValue); |
199 | | if (m <= 0.0) |
200 | | { |
201 | | float r = (targetValue-color.a)/(previousColor.a-color.a); |
202 | | texcoord = texcoord - r*dt; |
203 | | |
204 | | #if 0 |
205 | | color = texture3D( volumeTexture, texcoord); |
206 | | #else |
207 | | color.r = 1.0; |
208 | | color.g = 1.0; |
209 | | color.b = 1.0; |
210 | | color.a = 1.0; |
211 | | #endif |
212 | | float px = texture3D( volumeTexture, texcoord + deltaX).a; |
213 | | float py = texture3D( volumeTexture, texcoord + deltaY).a; |
214 | | float pz = texture3D( volumeTexture, texcoord + deltaZ).a; |
215 | | |
216 | | float nx = texture3D( volumeTexture, texcoord - deltaX).a; |
217 | | float ny = texture3D( volumeTexture, texcoord - deltaY).a; |
218 | | float nz = texture3D( volumeTexture, texcoord - deltaZ).a; |
219 | | |
220 | | vec3 grad = vec3(px-nx, py-ny, pz-nz); |
221 | | if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0) |
222 | | { |
223 | | vec3 normal = normalize(grad); |
224 | | float lightScale = 0.1 + max(0.0, dot(normal.xyz, lightDirection))*0.9; |
225 | | |
226 | | color.r *= lightScale; |
227 | | color.g *= lightScale; |
228 | | color.b *= lightScale; |
229 | | } |
230 | | return color; |
231 | | } |
232 | | |
233 | | previousColor = color; |
234 | | |
235 | | texcoord += dt; |
236 | | |
237 | | --num_iterations; |
238 | | } |
239 | | |
240 | | return vec4(0.0, 0.0, 0.0, 0.0); |
241 | | } |
242 | | |
243 | | vec4 accumulateSamplesIsosurfaceTransferFunction(vec3 ts, vec3 te, vec3 dt, float scale, float cutoff, int num_iterations) |
244 | | { |
245 | | vec3 texcoord = te.xyz; |
246 | | |
247 | | float normalSampleDistance = length(dt); |
248 | | vec3 deltaX = vec3(normalSampleDistance, 0.0, 0.0); |
249 | | vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0); |
250 | | vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance); |
251 | | |
252 | | float previous_a = texture3D( volumeTexture, texcoord).a; |
253 | | |
254 | | float targetValue = IsoSurfaceValue; |
255 | | |
256 | | while(num_iterations>0) |
257 | | { |
258 | | float a = texture3D( volumeTexture, texcoord).a; |
259 | | float m = (previous_a-targetValue) * (a-targetValue); |
260 | | if (m <= 0.0) |
261 | | { |
262 | | float r = (targetValue-a)/(previous_a-a); |
263 | | texcoord = texcoord - r*dt; |
264 | | |
265 | | float v = targetValue * tfScale + tfOffset; |
266 | | vec4 color = texture1D( tfTexture, v); |
267 | | |
268 | | float px = texture3D( volumeTexture, texcoord + deltaX).a; |
269 | | float py = texture3D( volumeTexture, texcoord + deltaY).a; |
270 | | float pz = texture3D( volumeTexture, texcoord + deltaZ).a; |
271 | | |
272 | | float nx = texture3D( volumeTexture, texcoord - deltaX).a; |
273 | | float ny = texture3D( volumeTexture, texcoord - deltaY).a; |
274 | | float nz = texture3D( volumeTexture, texcoord - deltaZ).a; |
275 | | |
276 | | vec3 grad = vec3(px-nx, py-ny, pz-nz); |
277 | | if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0) |
278 | | { |
279 | | vec3 normal = normalize(grad); |
280 | | float lightScale = 0.1 + max(0.0, dot(normal.xyz, lightDirection))*0.9; |
281 | | |
282 | | color.r *= lightScale; |
283 | | color.g *= lightScale; |
284 | | color.b *= lightScale; |
285 | | } |
286 | | return color; |
287 | | } |
288 | | |
289 | | previous_a = a; |
290 | | |
291 | | texcoord += dt; |
292 | | |
293 | | --num_iterations; |
294 | | } |
295 | | |
296 | | return vec4(0.0, 0.0, 0.0, 0.0); |
297 | | } |
298 | | |
299 | | vec4 accumulateSamplesMaximumIntensityProjection(vec3 ts, vec3 te, vec3 dt, float scale, float cutoff, int num_iterations) |
300 | | { |
301 | | vec3 texcoord = te.xyz; |
302 | | vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); |
303 | | |
304 | | while(num_iterations>0) |
305 | | { |
306 | | vec4 color = texture3D( volumeTexture, texcoord); |
307 | | |
308 | | if (color.a>fragColor.a) |
309 | | { |
310 | | fragColor = color; |
311 | | } |
312 | | |
313 | | texcoord += dt; |
314 | | |
315 | | --num_iterations; |
316 | | } |
317 | | |
318 | | return fragColor; |
319 | | } |
320 | | |
321 | | vec4 accumulateSamplesMaximumIntensityProjectionTransferFunction(vec3 ts, vec3 te, vec3 dt, float scale, float cutoff, int num_iterations) |
322 | | { |
323 | | vec3 texcoord = te.xyz; |
324 | | vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); |
325 | | |
326 | | float max_a = 0.0; |
327 | | while(num_iterations>0) |
328 | | { |
329 | | float a = texture3D( volumeTexture, texcoord).a; |
330 | | |
331 | | if (a>max_a) |
332 | | { |
333 | | float v = a * tfScale + tfOffset; |
334 | | fragColor = texture1D( tfTexture, v); |
335 | | max_a = a; |
336 | | } |
337 | | |
338 | | texcoord += dt; |
339 | | |
340 | | --num_iterations; |
341 | | } |
342 | | |
343 | | return fragColor; |
344 | | } |
345 | | |
346 | | vec4 accumulateSamples(vec3 ts, vec3 te) |
| 15 | vec4 accumulateSegment(vec3 ts, vec3 te) |