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 > Help wanted: fog

#96627 - ecurtz - Fri Aug 04, 2006 6:26 am

Has anybody done anything with fogging in 3d scenes? I haven't been able to find any information about how to enable it.

#96915 - omaremad - Sun Aug 06, 2006 3:43 pm

for fog i would do the following ( this is my own technique which i theorised but never tested)

I would have a huge quad inclinded at a 45 deg angle to the camera


Code:

  /
C-------/(top)
  \       /
         /
        /(bottom)


the quad would be the same colour as the fog, and for a volumetric effect rather than bland fog you could use POLYFRMT and set the polyalpha to higher on the lower polygons of the quad(the bottom ones)

you could even use a fog texture

:)[/code]

#97044 - ecurtz - Mon Aug 07, 2006 4:32 pm

Thanks, but I'm actually interested in using the hardware fog. Anybody have even the registers? I'd be willing to do some testing.

#97059 - omaremad - Mon Aug 07, 2006 7:04 pm

I dont think the fog registers have been found yet, besides hw fog is ugly, compare resident evil 4 fog to hw fog, RE4 is polygonal based like mine therefore could be textured and depth based

#97623 - dovoto - Thu Aug 10, 2006 9:08 pm

I have done a hardware fog demo...I will see if i can locate or reproduce the source. I had updated libnds but had a bit of data loss prior to checkin.
_________________
www.drunkencoders.com

#97715 - ecurtz - Fri Aug 11, 2006 6:16 am

dovoto wrote:
I have done a hardware fog demo...I will see if i can locate or reproduce the source. I had updated libnds but had a bit of data loss prior to checkin.


Excellent, thanks. It's really what I need for this particular application.

#97779 - dj-ceejay - Fri Aug 11, 2006 2:44 pm

You could use a set of fog billboards throughout your level with their alpha levels based on their distance from the camera (transparent when near the camera, opaque when far away from the camera). You would have to watch the fillrate as you would need the billboards quite big to cover the screen.
_________________
Fruit Machine Games:
http://www.fmsoftware.info/

#97810 - omaremad - Fri Aug 11, 2006 6:31 pm

Because the ds uses some sort of weird scan line renderer it stays always at 60fps no matter the texturing lighting etc... (provdidng you are under 2000 polies)

#97887 - M3d10n - Sat Aug 12, 2006 4:26 am

Even so, polygons will only blend against one with a different ID (I think the ID specifies at which order they'll get blended during render, but I haven't tested that), and since there are only 64 unique IDs, you'll get 64 overlapping planes at most.

Finding out how to get the hardware per-pixel fog to work would be great, since it looks very good (MP:H makes very good use of it for mood and depth).

#97903 - crossraleigh - Sat Aug 12, 2006 8:22 am

Sometime recently (I guess with the release of no$gba 2.3), Martin Korth quietly added a 3D section to GBATEK which has info on hardware fog.

#97957 - dak - Sat Aug 12, 2006 3:48 pm

I've been playing around with the fog registers as documented on GBATEK, but have not gotten very far myself. I enabled bits 6 and 7 in the GFX_CONTROL (enabling alpha fogging effects), but enabling bit 15 on GFX_POLY_FMT (to enable poly-fogs) simply seems to clear my screen of any polygons at all!

I assume fog color wouldn't have to be set as I'm using alpha fog (but I set it anyway just in case to red). The tech documents make mention that bits 8-11 in GFX_CONTROL (fog shift?) are related somehow to the FOG_OFFSET. My knowledge in this area is VERY little and I assumed that fog offset is the distance between the eye and the fog (if so, what is the data type?). Anyway; anyother explorers have any insight they unearthed on this?

XD I'm anxiously waiting for Dovoto to slap some sample code up here to play with!

-dak

#97974 - omaremad - Sat Aug 12, 2006 5:10 pm

hey if you want to activate fog on the background as a testing method before we manage polygons use this

Quote:


4000350h - CLEAR_COLOR - Clear Color Attribute Register (W)

0-4 Clear Color, Red
5-9 Clear Color, Green
10-14 Clear Color, Blue
15 Fog (enables Fog to the rear-plane) (doesn't affect Fog of polygons)
16-20 Alpha
21-23 Not used
24-29 Clear Polygon ID (affects edge-marking, at the screen-edges?)
30-31 Not used
[/b]

#97976 - omaremad - Sat Aug 12, 2006 5:21 pm

the fog offset probably describes the polygon ID the fog should act on

Seems the set up is similar to toon edges where you enable edges then

yo specify the color and the id shifted by >>3

so maybe the offset defines the poly id the fog should work on

btw i would drool if we can use this in some way useful
Quote:

13 Polygon/Vertex RAM Overflow (0=None, 1=Overflow/Acknowledge)

#98042 - ecurtz - Sat Aug 12, 2006 9:59 pm

Thanks everybody, haven't got the specifics worked out yet, but it seems to work. Here are the relevant bits of my project...

Code:

#define POLY_FOG  (1<<15)

#define GL_FOG_ALPHA    (1<<6)
#define GL_FOG          (1<<7)
#define GL_FOG_SHIFT(n)   ((n)<<8)

#define GL_RDLINE_UNDERFLOW   (1<<12)
#define GL_VERTEX_OVERFLOW    (1<<13)

#define GFX_FOG_COLOR   (*(vuint32*) 0x04000358)
#define GFX_FOG_OFFSET  (*(vuint32*) 0x0400035C)
#define GFX_FOG_TABLE   ((vuint8*)  0x04000360)

void glFogColor(uint8 red, uint8 green, uint8 blue, uint8 alpha) { GFX_FOG_COLOR = (red) | ((green)<<5) | ((blue)<<10) | ((alpha)<<16); }
void glFogDepth(uint16 depth) { GFX_FOG_OFFSET = depth; }


// Set up the fog stuff
   glFogColor(63, 0, 0, 31);
   glFogDepth(0x400);
   int i;
   for (i = 0; i < 32; i++) {
      GFX_FOG_TABLE[i] = i<<2;
   }


      GFX_CONTROL = GL_FOG | GL_FOG_SHIFT(3) | GL_RDLINE_UNDERFLOW | GL_VERTEX_OVERFLOW | GL_TEXTURE_2D /*| GL_BLEND*/;

      glPolyFmt(POLY_ALPHA(31) | POLY_FOG | POLY_ID(2) | culling | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2);
         glBegin(GL_TRIANGLE_STRIP);




GL_FOG_SHIFT() seems to actually be a shift, larger values mean smaller fog bands, it wasn't working with a shift of 0. I'm not sure exactly how the scales correspond to the vertex scales yet, I just played with numbers until it looked ok.