6

I'm trying to implement volumetric billboards in OpenGL 3.3+ as described here and video here. The problem I'm facing now (quite basic) is: how do I render a 3D object to a 3D texture (as described in the paper) efficiently? Assuming the object could be stored in a 256x256x128 tex creating 256*256*128*2 framebuffers (because it's said that it should be rendered twice at each axis: +X,-X,+Y,-Y,+Z,-Z) would be insane and there are too few texture units to process that many textures as far as I know (not to mention the amount of time needed).

Does anyone have any idea how to deal with something like that?

genpfault
  • 51,148
  • 11
  • 85
  • 139
hun7er
  • 157
  • 3
  • 7
  • I doubt that OpenGL is a way to go, there are voxelization algorithms out there I think you should dig them. – Vasaka Jul 08 '13 at 11:14
  • and why do you think you need so much framebuffers? it is just 256*2 + 256*2 + 128*2 – Vasaka Jul 08 '13 at 13:11
  • The problem is that I **have to** do it in OpenGL, I'm doing it for Computer Graphics classes at the University where we have to use OGL. I'll try to do it, if I achieve anything I will let you know. About framebuffers: sorry, you are right, my bad. Still it is too much to be passed to the shader afaik (the amount of texture units is the bottleneck) – hun7er Jul 08 '13 at 13:35
  • you can use compute shaders, if you find method that can be paralleled well. – Vasaka Jul 08 '13 at 13:51

1 Answers1

5

A slice of 3D texture can be directly attached to the current framebuffer. So, create a frame buffer, a 3D texture and then do rendering like:

glFramebufferTexture3D( GL_FRAMEBUFFER, Attachment, GL_TEXTURE_3D,
                        TextureID, 0, ZSlice );
...render to the slice of 3D texture...

So, you need only 1 framebuffer that will be iterated by the number of Z-slices in your target 3D texture.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
  • 1
    So, does that mean you have to do a draw per slice? I can't render to the entire 3D texture in one go? – Sekhat Feb 15 '15 at 16:44
  • @Sekhat yep, per slice – Sergey K. Feb 15 '15 at 22:07
  • 2
    Hi, I know this question is old, but just wanted to clarify. Should the number of ZSlices be equal to z dimension of the texture? i.e in the case of a 256x256x128 texture, would there be 128 zslices and hence 128 draw calls? – nitronoid Apr 02 '18 at 23:46
  • 1
    @nitronoid `ZSlice` is the slice you want to use as a framebuffer. If you want to render to every slice, you have to create 128 framebuffers, or switch the framebuffer 3D texture slice after every draw call. Either way you need to perform 128 drawcalls. There are other methods (compute shader or geometry shader) that do not require that many draw calls. See here for an example: https://stackoverflow.com/q/37286899/1907004 – Tara Jul 16 '22 at 14:13