Best strategy for rendering into cubemaps?

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
So, I currently have a roundabout method for cubemap rendering. I have a single "camera" with a 2D color & depth FBO. I render the six cube faces, one by one. After each pass I draw the FBO contents into the corresponding face of the cubemap.

It does work. But it's pretty convoluted, since it requires a lot of back and forth.

Now, as far as I can tell there's no such thing as a depth attachment for cubemaps, or at the very least, I'm going to assume that if there is, it's not available on my MBP ( ati x1600, 10.6.2 ).

So, is there a more clever way to do this? Perhaps by drawing directly into a cubemap face while using/re-using a discrete 2D depth buffer?

I'm about to implement omnidirectional shadow mapping by encoding depth into RGBA -- but I'm thinking that a more efficient way to render a scene into a cube map is an imperative first step.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
You can render directly to the cube faces:

Code:
void FramebufferTexture2DEXT(enum target, enum attachment,
                                     enum textarget, uint texture,
                                     int level);

... <texture> must either name an existing texture object with an target
    of <textarget>, or <texture> must name an existing cube map texture
    and <textarget> must be one of: TEXTURE_CUBE_MAP_POSITIVE_X,
    TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z,
    TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_Y, or
    TEXTURE_CUBE_MAP_NEGATIVE_Z.

If you want depth testing while rendering to a color cube map face, you'll need a depth attachment, of course. This can be a renderbuffer, or a 2D texture (the targets do not need to match across all attachments, only sizes.)

For omni shadows what you probably really want is a depth cube map, so you could do depth-only rendering and not worry about RGBA encoding. Depth cube maps are part of EXT_gpu_shader4 (and GL3) but the Radeon X1x00 can't support them.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
arekkusu Wrote:You can render directly to the cube faces:

Code:
void FramebufferTexture2DEXT(enum target, enum attachment,
                                     enum textarget, uint texture,
                                     int level);

... <texture> must either name an existing texture object with an target
    of <textarget>, or <texture> must name an existing cube map texture
    and <textarget> must be one of: TEXTURE_CUBE_MAP_POSITIVE_X,
    TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z,
    TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_Y, or
    TEXTURE_CUBE_MAP_NEGATIVE_Z.

If you want depth testing while rendering to a color cube map face, you'll need a depth attachment, of course. This can be a renderbuffer, or a 2D texture (the targets do not need to match across all attachments, only sizes.)

Awesome. I'll probably post back here soon with questions when my code inevitably goes pear shaped Rasp

Quote:For omni shadows what you probably really want is a depth cube map, so you could do depth-only rendering and not worry about RGBA encoding. Depth cube maps are part of EXT_gpu_shader4 (and GL3) but the Radeon X1x00 can't support them.

My plan right now is to encode the depth into RGBA by packing/swizzling.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
I just wanted to post an update that I was able to get a depth attachment to a cube fbo working. And it really does clean up my RTT/Cube pipeline... enough that I could render a lightprobe in real time, which is pretty cool.

Haven't implemented omnidirectional shadows yet, but hey, baby steps.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #5
FWIW, Apple posted sample code showing rendering to cubemaps with depth renderbuffers in 2006.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #6
arekkusu Wrote:FWIW, Apple posted sample code showing rendering to cubemaps with depth renderbuffers in 2006.

Actually, as soon as you mentioned that this was possible, I remembered that demo Wink

I was using it as a reference while updating my own fbo code.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #7
As a small update, I just got omnidirectional shadowmaps working, albeit crudely. I'm not using high-quality depth to color packing as I still have some bugs to work out, and until then it's useful to be able to visually read my depth with the unrolled cube overlay graphic.

[Image: PointLightin-2009-12-06-00.png]

[Image: PointLightin-2009-12-06-01.png]

[Image: PointLightin-2009-12-06-02.png]

But it's getting there!
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #8
It works!
http://shamyl.zakariya.net/screenshots/O...ow_Med.mov

Now, I just need to implement PCF and make certain verious corner cases pass well enough.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  cubemaps with shaders akb825 3 3,043 Apr 5, 2006 06:24 PM
Last Post: akb825
  Automatic cubemaps via PBuffers TomorrowPlusX 20 8,454 Feb 15, 2006 07:21 AM
Last Post: TomorrowPlusX
  Displaying my cubemaps in world space, rather than eye TomorrowPlusX 1 2,707 Jan 26, 2006 04:29 AM
Last Post: TomorrowPlusX
  Seams showing on my cubemaps TomorrowPlusX 4 3,837 Dec 14, 2005 12:56 PM
Last Post: TomorrowPlusX