It is currently Tue Mar 26, 2019 8:03 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: Mon Mar 06, 2006 4:51 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
I've finally finished a release-worthy version of the NES NTSC composite video filter library for use in a NES emulator. This has a ton of improvements and is very efficient. It's written in C and can easily be used from C or C++, and licensed under the GNU LGPL.

nes_ntsc-0.1.6.zip

* Standard TV controls: hue, saturation, contrast, brightness, sharpness
* Extra parameters: custom decoder matrix, adjustable "hue warping" that some TVs employ to keep flesh and sky tones from being off-hue
* Even/odd artifact merging for when host monitor's refresh rate doesn't match emulator's frame rate, or when taking a screenshot. No performance impact.
* Support for user-defined custom blitter, allowing customization of source NES pixel format, output format (32/24/16/15-bit RGB), scanline effects (doubling, darkening, etc.), and platform-specific optimization. Default blitter reads 6-bit NES pixels and writes 16-bit RGB pixels without any scanline effects.
* Built-in horizontal rescaling to proper width, leaving it up to the emulator to double vertically
* Support for PPU emphasis/color tint bits on a per-pixel basis (in custom blitter only)
* All-integer blitter loop for good performance
* Compensation for rounding errors eliminates speckles in solid color areas, even when using 15-bit RGB color output
* Adjustable output width, with presets for showing just the 256 NES pixels, as many will fit within a 640x480 screen (about 8 overscan pixels on each side), and enough to show the proper 15 left and 11 right overscan pixels.
* Includes demo that displays NES image with mouse control of parameters, using SDL multimedia library
* Includes simple benchmark program to find performance on your machine and help with optimizing a custom blitter
* Includes better documentation

Thanks to everyone who contributed or gave feedback. Reply here with any questions about using it in an emulator.


Last edited by blargg on Sun Mar 12, 2006 11:52 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 12, 2006 5:12 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Updated library available:

nes_ntsc-0.1.7.zip

* Fixed color emphasis to affect xD colors instead of incorrectly leaving them as always gray
* Added ability to generate a 64- or 512-color RGB palette for use when full NTSC emulation isn't desired
* Documented more accurate burst_phase handling and included three test ROMs for verifying proper implementation
* Moved color emphasis support to new nes_ntsc_emph_t structure, eliminating the ugly global NES_NTSC_DISABLE_EMPHASIS configuration macro
* Extended demo to use optional Sony decoder matrix and write standard 192-byte NES .PAL file using current settings
* Improved documentation slightly
* Lowered maximum saturation to avoid overflow of blue when blue color emphasis is enabled


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 12, 2006 10:16 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
I finally added the filter to my full-featured NES emulator yesterday (still unreleased) and played Metroid for a bit. I was surprised at how much the filter helped create the feeling of playing the NES back in the day. I thought I didn't like the filter that much but now that I can easily switch between it and the usual palette-based one I am liking it a lot.

I made some comparisons and found Blaster Master to be the most improved by full NTSC emulation. Using a matching RGB palette for a normal pixellated blitter, the colors in the NTSC one come out significantly different due to the effect of nearby pixels. I had to zoom in with the dropper tool to persuade myself that the RGB colors were in fact the same (the horizontal runs at the top of the doorway are a good place to compare).

Image

Full-screen versions: NTSC, palette-based

The palette-based rock wall looks much more red-orange than the NTSC image, and the gray looks very ugly in it. The brown gradient towards the middle blue line looks very coarse and uninteresting in the palette-based image. In the NTSC image the blues in the tree trunk (bottom right in cropped image below) almost disappear. Finally, the diagonal artifacts on the vertical portion of the door keep it from looking really plain.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 12:44 am 
Offline

Joined: Sun Jan 08, 2006 12:22 pm
Posts: 23
Nice work. In the NTSC image, the blue in the trees is clearly a lot darker than in the solid horizontal band of blue. If the same colour values give very different appearance depending on the surrounding pixels and this is something that developers have taken into account, then the argument for a solution that involves NTSC emulation as opposed to only indexing a fixed palette is pretty solid. It appears that is the case.

Will your emulator have a mode which doesn't simulate scanlines? It looks like yours does it pretty tastefully, but I'd still want to turn them off -- my display is already dimmer than a TV as it is.
Edit: Never mind - I noticed the previous release of Nestopia already has scanline options (including 'none'). Great :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 2:56 am 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
I took a video capture and tried to apply the same Sony TV decoder matrix I used for the above screenshots, but apparently it uses a different decoder matrix. I also attempted to get a capture of the TV, but my video camera is really low-end (and it had to then be video captured). When I have a digital camera soon I'll be able to get some much better shots of the TV.

Image

Full video capture (128K)

Image

Quote:
It looks like yours does it pretty tastefully, but I'd still want to turn them off -- my display is already dimmer than a TV as it is.


Tell me about it! With my TV even at half intensity it's very bright in comparison. Unfortunately without scanline darkening the pixels come out way too crisp and rectangular, and the artifacts stand out too much, so it's a hard tradeoff to make. I used 75% brightness doubled scanlines in all these examples (including the video captured one). The library itself doesn't do any scanline doubling, so it's up to the emulator author to decide how to handle that aspect. I'm told that Nestopia 1.28 will allow the adjustable darkening of any level. It will also use the latest version of this library, and apparently on some machines the overall frame rate has doubled as compared to version 1.27.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 3:29 am 
Offline
User avatar

Joined: Thu Mar 24, 2005 3:17 pm
Posts: 355
Screenshots look very nice!
I've hardly touched my emulator lately, but if I get motivated/interested again I'll certainly update to this new version.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 11:14 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21217
Location: NE Indiana, USA (NTSC)
blargg wrote:
Unfortunately without scanline darkening the pixels come out way too crisp and rectangular, and the artifacts stand out too much, so it's a hard tradeoff to make. I used 75% brightness doubled scanlines in all these examples (including the video captured one). The library itself doesn't do any scanline doubling, so it's up to the emulator author to decide how to handle that aspect.

I think linear interpolation plus adjustable darkening of interpolated scanlines might be the most realistic choice here.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 3:38 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Quote:
I think linear interpolation plus adjustable darkening of interpolated scanlines might be the most realistic choice here.


Thanks for the suggestion! It looks better and I was surprised that it only results in a 7% speed hit on my PowerPC-tuned blitter (it keeps the previous scanline in a local buffer). Once the next Nestopia is released I'm going to make its x86-optimized NTSC blitter into a standalone module and see about having this incorporated.

I put together a page with more examples of NTSC and palette-based images that significantly differ, using a little program to automate the process (and the scanline interpolation mentioned above):

NES NTSC vs. Palette Comparison

UPDATE: Wow, I connected the computer's composite video out to a TV and it's really close to a NES. The NTSC filter to normal palette-based filter is imporant for reproducing the shimmering artifacts when scrolling. I had figured it wouldn't help much when using composite video. The main problem is that my computer's composite video out uses interlace, and a more minor problem is the dot crawl. Plain scanline doubling with no linear interpolation or darkening looked b est; using anything else made the image flicker a lot (and turning on the PC's flicker-reducing convolution filter made the image too blurry). Using the non-interlace mode of Ultimarc's Arcade VGA video card with a TV would probably get very close to matching a NES. Even with my setup the image is so nice that I'm considering finding a place for a TV somewhere near the desk.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 12:30 pm 
Offline

Joined: Wed Feb 09, 2005 9:31 am
Posts: 418
I wish somebody would make a version of that video card with component video output as opposed to VGA. While VGA works nicely with JAMMA cabinets, component is a far more common feature for consumer level TVs. blargg, is there any chance that you could make a good video of your real NES on the same TV as the upcoming version of Nestopia? Can consumer digital video cameras be setup to sync to a TVs refresh?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 3:51 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21217
Location: NE Indiana, USA (NTSC)
A 15.7 kHz VGA to component converter is probably just a few resistors and op-amps, along with a bit of stuff to generate NTSC sync signals based on the 15.7 kHz VGA sync signals. Has anyone already made such a schematic?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 10:01 am 
Offline

Joined: Wed Feb 09, 2005 9:31 am
Posts: 418
What would it look like if you combined NTSC emulation with one of the modernizing pixel filters that is supposed to make the graphics look better? NTSC emulation makes the graphics look more accurate, which sometimes means better and sometimes means uglier (in a faithful way of course). Would it be possible to have the best of both worlds? That is, combine the part of NTSC emulation that makes the graphics look better, without the warts, along with a modernizing pixel filter such as hq2x. BTW, what modernizing pixel filter is considered the best for the NES these days?

It wouldn't be of interest to hardcore accuracy folks... I'd stick to "accurate NTSC" myself, but a "sexy NTSC" filter would definitely be popular amongst those who want to make their old NES games as good looking as possible. NTSC seems to do good things for colors, dither patterns, etc, while hq2x does good things for sharp lines, curves, etc.
http://www.hiend3d.com/hq2x.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 11:21 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21217
Location: NE Indiana, USA (NTSC)
For that, you'd use hq2x, convert to YUV, blur the U and V channels, and convert back to RGB.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 9:09 am 
Offline
User avatar

Joined: Tue Mar 28, 2006 6:22 am
Posts: 16
On a technical note, nes_ntsc 0.1.7 is ~41% faster than the C/C++ version of HQ2X. I'd say it's fairly well optimized. :p

Edit: Oh, and that's even with the very slow interpolated (instead of simply duplicated) scanline doubling in my implementation!

- randi

_________________
<3


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 11:33 am 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
When I first started I didn't think I'd really ever get it running real-time on my ancient computer. Did you find the custom blitter interface easy to use? Be sure to look at Nestopia 1.28's custom nes_ntsc blitter function, since it does several things to run fast on PC hardware, even with scanline doubling and darkening (it's all in NstVideoFilterNtsc.hpp).

HQ2x involves conditionals (branches) so it is expensive, though I recently made some optimizations to make it mostly branchless. The NTSC filtering is just a big convolution (with clamping done using bit operations without any branches), so it allows lots of parallelism in calculation.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 12:31 pm 
Offline
User avatar

Joined: Tue Mar 28, 2006 6:22 am
Posts: 16
blargg wrote:
Did you find the custom blitter interface easy to use? Be sure to look at Nestopia 1.28's custom nes_ntsc blitter function, since it does several things to run fast on PC hardware, even with scanline doubling and darkening (it's all in NstVideoFilterNtsc.hpp).

To be honest, I didn't use it. :oops: I generally take the easiest route to implement a feature, which in this case was hacking my color-converting HQ2X/HQ3X/HQ4X code to wrap around your demo code. I've no idea if it works properly, as it is a fairly poor implementation (but such is the case with everything in FakeNES, since it's a generally half-assed done emulator in every way). However, I will definitely look at it later if I get a chance. :)

- randi

_________________
<3


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group