gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > fog and transparence

#149021 - luss - Sun Jan 13, 2008 5:47 pm

Hello everyone,
I've learned a lot reading this forum, but now I'm stucked!

I try to use fog and transparence in the same time and it doesn't work properly... (sorry for poor english speaking)

For the example, I will use only two plane:

-plane n?1 for my ground with glPolyFmt(POLY_ID(1) | POLY_ALPHA(31) | POLY_FORMAT_LIGHT0 | POLY_CULL_NONE | POLY_FOG);

-plane n?2, placed in front of the camera and near it, like a window, with glPolyFmt(POLY_ID(2) | POLY_ALPHA(10) | POLY_FORMAT_LIGHT0 | POLY_CULL_NONE | POLY_FOG);

It seems the fog is rendered in front of my plane n?2, just like the nds renders first plane n?1, then plane n?2 and finally adds the fog on top of the previous result without taking care of my plane n?2...

For info, my plane n?2 will always be near the camera. So I don't really need to have fog on it... If it can help to find a solution...

I can't get ride of this problem...

Someone have a clue?
thanks by advance!

#149027 - M3d10n - Sun Jan 13, 2008 7:47 pm

I never tested fog+transparent polygons, but I know what might be causing your problem.

The fog on the DS seems to be rendered as a post-processing after the scanline was rendered, blending the scanline's pixels against the color value based on their depth. So, when you draw your ground plane, it writes depth values on the z-buffer. When you render your transparent plane, it doesn't change the depth values, and thus the fog is applied based as if only the ground had been rendered.

You can make your transparent plane update depth by enabling bit 11 on the polygon attribute, but that might cause the fog to not be rendered on the plane behind. Did you try disabling the fog (POLY_FOG) for the transparent plane?


Hmm... I booted Metroid Prime Hunters (which uses lots of fog) to test and it seems to have no problem fogging alpha-blended polygons. There might be some settings to get around that problem.

#149036 - luss - Sun Jan 13, 2008 11:30 pm

It seems you're right! When enabling bit 11 on my second plane, the fog isn't rendered for the part of the first plane that is behind. But it's a beginning and might be usefull: thanks for this tip!

In fact, I try to make a nice glow/lens flare effect... I really want that ^^

Disabling poly_fog for the second plane didn't change anything: exactly the same result ('cause my 2nd plane is near camera, there's no fog on it when enabling poly_fog).

Maybe rendering the frame in two pass? But it will use en vram block, isn't it? I hope the framerate can still be at 60fps, like I saw in a demo on this forum. But I won't be really satisfied by this solution because I need memory for textures and it's allready hard to deal with 512Ko max vram memory... :(

I've played to Metroid Prime Hunters too and I doubt they waste a block memory just for using fog and alpha-blend polygons ^^ maybe i'm wrong...

I thougt playing with GL_BLEND?? hmm... I've read that playing with GL_BLEND isn't a good solution (in a thread talking about shadow).