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 > scaling jittering help

#120720 - GPFerror - Mon Mar 05, 2007 8:02 pm

I am trying to make my Frodo c64 emulator port look a little better and was hoping for some suggestions or sample code.

Code:
   BG3_CR = BG_BMP8_512x512;
   BG3_XDX = DISPLAY_X-54;
   BG3_XDY = 0;
   BG3_YDX = 0;
   BG3_YDY = DISPLAY_X-108;
   BG3_CX = 28<<8;
   BG3_CY = 32<<8 ;
   frontBuffer = (uint8*)(0x06000000);
   bufmem = (uint8*)malloc(512*512);


and using DMA to copy it into VRAM
Code:
   DC_FlushRange(bufmem, 512*512);
   dmaCopy(bufmem,frontBuffer, (512*512)/2);



where DISPLAY_X=384, and DISPLAY_Y=272, since the Frodo C64 port has borders on the left and right of 32-37 pixels and top and bottom borders of 51-55 pixels, I am shifting the screen and chopping off most of the borders so that more of the screen is displayed.

Someone was telling me about using jitter to make the display look a little better, I was told something about using the scroll registers to either move the screen up and left a couple pixels(or down and right) and reset it every other vblank, for the above code how would I do that?

Thanks,
Troy(GPF)
http://gpf.dcemu.co.uk

#120729 - Lick - Mon Mar 05, 2007 8:43 pm

If you shift the background position 60 times a second, by a little offset, your eyes won't notice the movement. Instead, it will blur out this 'flickering' and in result you will see a smoother image.

Just shift the background by 1 pixel horizontally and vertically. You should beware of the background wrapping though, otherwise you might get unwanted colors at the edges of the screen.
_________________
http://licklick.wordpress.com

#120732 - tepples - Mon Mar 05, 2007 9:09 pm

And you do this by changing BG3_CX and BG3_CY.

Another tip: Use both BG2 and BG3, displaying the same thing at different scrolls, and use the blending registers to combine them.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#120734 - GPFerror - Mon Mar 05, 2007 9:25 pm

tepples wrote:
And you do this by changing BG3_CX and BG3_CY.

Another tip: Use both BG2 and BG3, displaying the same thing at different scrolls, and use the blending registers to combine them.


so in my vblank I need to do something like this move it 2 pixels down and left and then reset it ?

Code:
int swap=0;
void vblankhandler()
{
  if(swap ==1)
  {
     swap=0;
     BG3_CX = 30<<8;
     BG3_CY = 34<<8 ;
  }
  else
  {
     swap=1;
     BG3_CX = 28<<8;
     BG3_CY = 32<<8 ;
  }
}



and this BG2 and BG3 blending sounds intriguing is there any sample code anywhere that might help me understand what that means :)

Thanks,
Troy(GPF)

#120735 - tepples - Mon Mar 05, 2007 9:30 pm

Don't change them by 2 whole pixels. Try changing them by half a pixel: BG3_CX = 28<<8 vs. BG3_CX (28<<8) + 128.

Blending between two identical BGs has been done. I developed a proof of concept on the GBA called α-Lerp (al fuh lurp), and nesDS uses exactly this technique for its vertical scaling. There's a wealth of discussion on some other source that the admins prohibit us from citing on this forum.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#120758 - spinal_cord - Mon Mar 05, 2007 11:24 pm

half a pixel? GPF is attempting to scale 320 to 256 (or rather 384 to ~307)wouldnt he lose loads of pixels that way?

I did this with a two pixel jump, and it seems fine, and the text if perfectly legible.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#120774 - gabebear - Tue Mar 06, 2007 1:05 am

Jittering by more than one pixel is going to blur the scene; which may look better in some cases, but might make the screen unusable in other cases.

Page on anti-aliasing with jitter:
http://www.bluevoid.com/opengl/sig00/advanced00/notes/node125.html

I have some example code that does 3D jitter with accumulation using the video capture stuff on the DS. The video capture stuff lets you combine the current output with another image in VRAM; so you can jitter the camera and keep combining frames to get full screen anti-aliasing. It requires two of the 128kb banks and 4x anti-aliasing drops the frame rate to 15fps, but it can be useful. I was using this to clean up a 3D scene when nothing was moving. Jittering the 2D background may be a better option in this case.

#120821 - spinal_cord - Tue Mar 06, 2007 8:48 am

I think something like this. It should set a 1 pixel jitter.

Code:

int swap=0;
void vblankhandler()
{
  if(swap ==1)
  {
     swap=0;
     BG3_CX = 32;
     BG3_CY = 18;
     BG3_YDX = 0;
     BG3_YDY = 0;
  }
  else
  {
     swap=1;
     BG3_CX = 33;
     BG3_CY = 19;
     BG3_YDX = 1;
     BG3_YDY = 1;
  }
}


[edit] changed from earlyer.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#120921 - kvance - Wed Mar 07, 2007 8:28 am

This post helped me a great deal with scaling methods. I made a quick downscaling demo to compare the various methods. This is for scaling mode 13 (320x200) down to the DS screen, which isn't all that bad for photograph-like images.

The X, Y, A, and B buttons switch between hardware, flicker, alerp, and flicker alerp. L shows a prescaled image (GIMP cubic scaler). R switches between a worst-case test pattern and a raytraced image (guess the game it's from!).

I'd be interested to know if there are other downscaling methods, or if I misunderstood alpha lerping, or if anyone knows some better values for the jitter tables.
_________________
Corner Office: dev LJ
HexxagonDS, dsmzx, more...

#120946 - tepples - Wed Mar 07, 2007 2:45 pm

It looks OK. What you have (flicker α-Lerp) should be good for the first version. Try jittering the flicker scaling only horizontally (X) and jittering the two layers vertically (Y) and see if that looks any worse. Or try using rand() to generate jitter values.

Other downscaling methods include the following:
  • Overscan: Scale only horizontally, and just drop the top and bottom 4 lines.
  • HDMA to the alpha register, changing the blend value per scanline. In theory, this should look much nicer when scaling by a value close to 100% (such as the 96% needed to squeeze all of mode 13h onto the DS screen), but you'll need to learn raster effects first. Want a demo?
  • Full software interpolation. Does ScummVM use this?

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#121126 - kvance - Fri Mar 09, 2007 6:27 am

tepples wrote:
  • HDMA to the alpha register, changing the blend value per scanline. In theory, this should look much nicer when scaling by a value close to 100% (such as the 96% needed to squeeze all of mode 13h onto the DS screen), but you'll need to learn raster effects first. Want a demo?

I've updated the scaling test with my first crack at this. I set up the blending tables to blur the 7 artifacts that occur when the BG's have a Y difference of 1.0. Flicker is on the X-axis only. This handles alternating 1-pixel black and white lines very well, but actually seems to look worse on the raytraced image. I'm not sure why yet.

DMA on HBlank is very cool! I've never used anything like it.
_________________
Corner Office: dev LJ
HexxagonDS, dsmzx, more...

#121146 - tepples - Fri Mar 09, 2007 2:51 pm

It appears there may be a bug. Try making it so that the diagonal lines in the test pattern don't jiggle up and down so much between cubic scaling (R) and the new system (Start).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.