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 > [SOLVED] another NDS riddle: why am i an idiot today? (fog)

#157949 - silent_code - Mon Jun 02, 2008 11:09 am

so, after getting textures back to work correctly, my only problem left is fog.

it works and i can adjust it to fit my needs, there's just one problem: it's periodically repeating and everything i have tried to fix that behaviour just didn't work.

what i should do is clamp the fog to the specified "near" and "far" distances and then interpolate fogging between those values. :^(

i've put up a video. the demo still uses gbfs, so it requires a slot2 solution to work and the currently available free no$gba version doesn't support all features used in the demo, which unfortunately still includes fogging.

you can find the video here: vsd_fog.avi
and in case you'd prefer a photo: vsd_fog_bug.JPG

thanks for any advise on what to look for to fix it. :^)

greetings!
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.


Last edited by silent_code on Mon Jun 02, 2008 12:39 pm; edited 1 time in total

#157950 - Maxxie - Mon Jun 02, 2008 12:01 pm

How did you set up the fog density table?

If the info on the site correct then once you get out of the tableindizes (via depth and shift) it should use the outter (0,31) values

#157951 - silent_code - Mon Jun 02, 2008 12:09 pm

sorry, i mean to include this infor aswell. ;^)

i do this once on initialization:
Code:
   const int32 Mass = 5; // intentionally high for emphasis, reduce it to make the effect less noticable

   glFogColor(31, 0, 0, 0);
   glFogDepth(1);

   for(int8 i = 2; i <= 64; i += 2)
   {
      GFX_FOG_TABLE[(i - 2) / 2 ] = (i << Mass);
   }


and later this on a frame base:
Code:
#define GL_FOG_SHIFT(n)   ((n) << 8)
   const int Shift = 9;
   glEnable(GL_TEXTURE_2D | GL_ANTIALIAS | GL_BLEND | GL_COLOR_UNDERFLOW | GL_POLY_OVERFLOW | GL_FOG | GL_FOG_SHIFT(Shift));


with:
Code:
static inline void glFogColor(uint8 red, uint8 green, uint8 blue, uint8 alpha)
{
    GFX_FOG_COLOR = ((alpha & 31) << 16) | ((blue & 31) << 10) | ((green & 31) << 5) | (red & 31);
}

static inline void glFogDepth(uint16 depth) { GFX_FOG_OFFSET = depth; }


NOTE: i use w-depth!

it's a problem with overflowing density values!
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.


Last edited by silent_code on Mon Jun 02, 2008 12:24 pm; edited 1 time in total

#157952 - Maxxie - Mon Jun 02, 2008 12:24 pm

silent_code wrote:
sorry, i mean to include this infor aswell. ;^)

i do this once on initialization:
Code:
   const int32 Mass = 5; // intentionally high for emphasis, reduce it to make the effect less noticable

   glFogColor(31, 0, 0, 0);
   glFogDepth(1);

   for(int8 i = 2; i <= 64; i += 2)
   {
      GFX_FOG_TABLE[(i - 2) / 2 ] = (i << Mass);
   }



Won't this overflow and thus create this begin-again-effect?

GFX_FOG_TABLE[] takes values from 0-127 (bit0-6) at i=4 you will overflow it and start again at 0 (4 << 5 = 128)


:edit: hey! same time on the eureka-call :p

#157953 - silent_code - Mon Jun 02, 2008 12:30 pm

jupp!
i just realized that it aren't u16, but u8 entries! damn me!
thanks for playing along, anyway! :^)

sometimes it simply takes a stupid, unnecessary post to make you look at your code from a different angle (the right one)! :^D

obviously, i am having an idiot day! at least sometimes, i should listen to the advises i give others, myself! ;^D

the following code fixed it:
Code:
void UpdateFog()
{
   const int32 Mass = 8;
   int32 density = 0;

   glFogColor(31, 0, 0, 15);
   glFogDepth(8);

   for(int8 i = 2; i <= 64; i += 2)
   {
      density = i * Mass;
      if(density > 127) density = 127;
      GFX_FOG_TABLE[(i - 2) / 2 ] = density;
   }
}


! 1!K35 Z F06z!!!! ;^D
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.