View Full Version : Blurfilter on 3d texture

03-04-2011, 06:30 AM
Hi everybody

I have build a small application to render volume graphic with a
raycasting algorithm. The volume is transferred via a texture 3d to the
gpu and in the fragment-shader the rays are casted into this
volume. No problem so far.

So now i want to blur the volumedata with a gauss filter kernel before
i use it. At the moment i do this job on the cpu but i wonder if i can
accomplish the task on the gpu. For 2D images i see no problem. You
can create two fbos and two fragment-shaders for each direction (x,y)
and ping-pong between them. Is it possible to something similar with
3D textures? And can i expect a speedup?

03-04-2011, 08:08 AM
Kinda the same for 3D :

for each Z value {
fixed Z: do the X 1D blur
fixed Z: do the Y 1D blur
for each X value {
fixed X: do the Z 1D blur

As for 2D blur, you should faster results on GPU.

03-08-2011, 01:19 AM
Thats clear, but my problem is how i save the result? Can i render directly to a texture 3d?

03-08-2011, 02:26 AM
Terse reply:
Two ways
1) using a FBO to render directly to a 3D texture
2) glTexSubImage3D and varying the z offset

03-08-2011, 03:06 AM
Yes, same as 2D, but using 'level' along Z to select a given XY slice.

03-08-2011, 07:31 AM
Still don't get it sorry. Let me try again.

I see that you can bind a texture3d to a framebuffer-object. But the fragment-shader can only create 2-dimensional images, right? So in order to do the gauss-blur on my 3d-volume, i have to cut it into slices, render each slice on a quad and do the blur with 3 passes in x,y and z-direction. The cutting can be done by using a fbo and glFramebufferTexture3D but i have to draw each slice manually on a quad.

Is this the right way to do it? If the answer is yes it seems to me that cuda is much more simple for this task.

Alfonse Reinheart
03-08-2011, 08:40 AM
I see that you can bind a texture3d to a framebuffer-object.

No, you can't; you can bind 2D slices to the framebuffer.

Layered rendering is simply a way to select which 2D slice you render to through a geometry shader. That is, your geometry shader can output multiple primitives, each of which will be written to a different 2D slice of a 3D texture.

03-09-2011, 02:33 AM
Hm ok. So i bind 2D slices to the framebuffer, the geometry shader emits the quads and with gl_Layer i tell the fragment shader to which slice he should render.