Welcome! Log In Create A New Profile

Advanced

optimal rendering of 3D objects on 2D background

Posted by calvinss4 
optimal rendering of 3D objects on 2D background
December 02, 2009 11:08AM
Hello there. I'm new to Wii homebrew, but I have some familiarity with OpenGL.

I have a static 2D background that I'm drawing directly to the XFB. Now I want to draw 3D graphics on top of that background. I'm currently accomplishing this via the following:
// Draw 3D stuff, then...
GX_DrawDone();
GX_CopyDisp(xfb, GX_TRUE);
GX_DrawDone();
// Now I draw my background into the XFB, but I only overwrite pixels for which color == CLEAR_COLOR

Allow me to explain. Drawing 3D stuff draws to the EFB, and GX_DrawDone ensures the drawing has finished. GX_CopyDisp copies the EFB to the XFB, and GX_DrawDone ensures the copying has finished. At this point it is safe to directly modify the XFB. If an XFB pixel has color == CLEAR_COLOR, then no 3D stuff was drawn there, so I may safely copy my background color to that pixel. This method works fine, however, it's a bit clumsy.

The obvious alternative is to render my static 2D background into a texture, then write that texture to the EFB before drawing the 3D stuff. But this got me thinking. When a texture is drawn into the EFB, it's possible to do alpha and z comparison, which affects how that texture data is blended with the data already contained in the EFB. Wouldn't it be nice if we could apply a similar technique when the EFB is copied to the XFB? For example, only copy pixels from the EFB to the XFB if the z value is less than the clear value. I think this would be much more useful that just being able to specify a sub-region of the EFB to copy to the XFB. It would allow me to write my static 2D background to the XFB first, then copy (precisely) the 3D objects from the EFB to the XFB.

If anyone with an advanced understanding of GX wants to share any insight on this, it would be greatly appreciated.
Re: optimal rendering of 3D objects on 2D background
December 02, 2009 02:58PM
I would draw it from a GX texture, there is no way in hell your framebuffer pixel access can be as fast as GX.
Re: optimal rendering of 3D objects on 2D background
December 02, 2009 08:03PM
Sure, the graphics processor (GP) can take advantage of parallelization to draw into a buffer faster than the CPU can, but keep in mind the GP and CPU are asynchronous; while the GP is busy drawing 3D geometry into the EFB, I can tell the CPU to go ahead and draw my background into the XFB. Now, if it ever turns out that my application is CPU-bound, I would gladly switch to using a GX texture for my background, but I like having the option to go back and forth as needed.

Anyway, I think we're missing the point here. Any reason it wouldn't be possible to optionally apply z and alpha comparison when copying from the EFB to the XFB?
Re: optimal rendering of 3D objects on 2D background
December 03, 2009 11:03AM
Quote
calvinss4
Wouldn't it be nice if we could apply a similar technique when the EFB is copied to the XFB? For example, only copy pixels from the EFB to the XFB if the z value is less than the clear value

z value means depth, and depth is limited by far plane and near plane. So you just have to adjust those planes to the depth you want. Then only the pixels you want to copy will be rendered.

My advice is to make a texture from your background, disable writes to de z buffer, render it, and reenable writes to the z buffer for the rest of the scene.
Sorry, only registered users may post in this forum.

Click here to login