OpenGL - how to render object to 3D texture as a volumetric billboard
Asked Answered
E

1

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?

Elaterite answered 6/7, 2013 at 16:18 Comment(4)
I doubt that OpenGL is a way to go, there are voxelization algorithms out there I think you should dig them.Transition
and why do you think you need so much framebuffers? it is just 256*2 + 256*2 + 128*2Transition
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)Elaterite
you can use compute shaders, if you find method that can be paralleled well.Transition
F
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.

Fosdick answered 21/7, 2013 at 17:13 Comment(4)
So, does that mean you have to do a draw per slice? I can't render to the entire 3D texture in one go?Jilolo
@Jilolo yep, per sliceFosdick
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?Tommy
@Tommy 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://mcmap.net/q/1779929/-opengl-texture3d-fragmentshader-write-into-layers/1907004Timberlake

© 2022 - 2024 — McMap. All rights reserved.