NTSC color palette emulation, with the square wave modulator

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
James
Posts: 429
Joined: Sat Jan 22, 2005 8:51 am
Location: Chicago, IL
Contact:

Post by James » Tue Nov 29, 2011 8:09 am

*Spitfire_NES* wrote: thank you james. and great work on nemulator. :)
thanks!

Bisqwit
Posts: 248
Joined: Fri Oct 14, 2011 1:09 am

Post by Bisqwit » Fri Jan 27, 2012 5:28 am

Related link, interesting reading: http://hitmen.c02.at/temp/palstuff/

neet
Posts: 14
Joined: Tue Jan 31, 2012 6:14 pm

Post by neet » Tue Jan 31, 2012 6:34 pm

As I have been heavily working on "lo-fi'ing" graphics in the last months, I want to share some results with you (as it was nesdev which has inspired me a lot).
First some informations about my current algorithm (general):
I'm emulating a TV screen using a virtual composite signal, real demodulation, some glow and a little bit of pixel grid (composite is unbiased). The virtual TV gets rendered at 752x240, "scanlined" to 752x720 and stretched to 960x720.

How does this fit here? Well, after reading about how the NES generates it's colors I did a quick hack which should resemble the way, the NES works:
- chroma information is a pure square wave (50% duty) which gets phase shifted dependent on which hue is to be produced (period is 12 cycles). Now I generate 13 x 14 boxes of 16x16 pixels each, shifting the hue phase from left to right (last box is zero hue) and increasing the luma from top to bottom. Each pixel is 8 clock cycles.
Dot crawl is also correctly emulated (4 clocks per line). This composite signal is then correctly downsampled and fed into my NTSCTv. The final image gets 2.2 gamma corrected and voila, it works ;)

Two things about NES NTSC:
1. The 'sawtooth' pattern only affects chroma, luma is untouched.
2. The rainbow effect on checkerboard patterns (even without chroma) is an artifact of pixel mixing (a NES pixel is 2.6667 NTSC 'clocks' (4x3.5MHz)) and of course aliasing

I will have to implement this into an existing NES emu to see how it works in realtime :D

The images won't have the correct saturation, as I don't adapt to real NES signal levels, but as the TV emu supports brightness, contrast, saturation and color controls this should not be a problem.

Anyways, here are two images. The first is a 'snapshot' of a crawl phase (a single frame), the second is 'field mixed', i.e. all three crawl phases are mixed into one frame:

http://dl.dropbox.com/u/11133993/pal2.png
http://dl.dropbox.com/u/11133993/pal1.png

The effect also looks nice as a postprocessing step on RGB NES screenshots, but I will have to get my hands on some 'real' NES screenshots (NES color per pixel) to try it out.

Edit: The 'snapshot' image shows some heavy dot-crawling and luma-chroma crosstalk because of a heavily opened luma filter. I turned it up for some testings and forgot to reduce it again^^

Another edit: Here's an image of a 'correct' checkerboard (single frame snapshot):
http://dl.dropbox.com/u/11133993/checkerboard.png

Edit again: Here are some hacked NES screenshots. The images get converted to native NES colors and then composited. All images are 'field merged'. The colors are created in a very naive way: level/3.f is luma, chroma wave is just -1, 1 ... still looks neat I think.
http://dl.dropbox.com/u/11133993/gradius.png
http://dl.dropbox.com/u/11133993/zelda.png
http://dl.dropbox.com/u/11133993/mario.png
http://dl.dropbox.com/u/11133993/iceclimber.png

Here we go again (another edit):
After checking out how the NES PPU really works I figured out that it doesn't use 3 crawl phases but only 2 (scanline 20), so there's just 0 and 120 degree color carrier shifts. (It still has a 3 line crawl pattern) Knowing this I changed my algorithm to merge just 2 fields and use correct NES colors. Here are two Castlevania shots:

http://dl.dropbox.com/u/11133993/castle2.png
http://dl.dropbox.com/u/11133993/castle3.png

I hope this was the last edit (don't want to double post^^).

And: I'm the new one, greetings from a retro gaming lover :D

psycopathicteen
Posts: 2979
Joined: Wed May 19, 2010 6:12 pm

Post by psycopathicteen » Sat Mar 31, 2012 9:33 am

Sorry to bump up this thread, but I have a question about the color palette.

I'm trying several different formulas, but the color at 120 degrees always comes out as brown instead of red? When I darken the gamma it comes out red, but it is too dark. Does NTSC lighten the gamma of the luma but darken the RGB values?

BTW, I'm using the formula:

R = Y + amplitude*sin(phase)/.877
B = Y + amplitude*cos(phase)/.492


EDIT: Wait, I figured out why it is comming out brown and not red. The color I am refering to is $x6 and it is located at 105 degrees, not 120 degrees. Tepples keeps stating that $x8 is colorburst, but from analysing everybody's palettes, it appears that the colorburst is inbetween $x8 and $x9.

User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: NTSC color palette emulation, with the square wave modul

Post by thefox » Fri Aug 17, 2012 3:46 pm

Bisqwit wrote:Image
Bad Bisqwit, bad! You should have gotten permission from yourself to use the images! (Is this because the forum moved?)
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 521
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: NTSC color palette emulation, with the square wave modul

Post by Jarhmander » Fri Aug 17, 2012 6:35 pm

Hmm, file name is "idiot.png"...
((λ (x) (x x)) (λ (x) (x x)))

Bisqwit
Posts: 248
Joined: Fri Oct 14, 2011 1:09 am

Re: NTSC color palette emulation, with the square wave modul

Post by Bisqwit » Sat Aug 18, 2012 2:36 am

thefox wrote:Is this because the forum moved?
Yes, it was because of that. Fixed now.
Sorry about that.

nintendo8
Posts: 54
Joined: Tue Jul 10, 2012 1:37 pm

Re: NTSC color palette emulation, with the square wave modul

Post by nintendo8 » Sat Aug 18, 2012 8:16 pm

I am working on a program that needs the NES palette and it appears that there is some debate on how a palette should look so I should of course have the option to load a pal file but no one posted a pal file with the emphasis bits does anybody have accurate pal file with the emphasis bits?

lidnariq
Posts: 10238
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: NTSC color palette emulation, with the square wave modul

Post by lidnariq » Sat Aug 18, 2012 10:01 pm

I am going to repeat what was said when you asked the last time:

There isn't a single correct palette.

No, really, there isn't. Color $19 is greenish, except when it's next to other pixels that aren't. And it's definitely not precisely, say, #287200.

As a result, at least some of the emulation scene has done away with .pal files, because they're horrifically inaccurate.

Best practices is to either appropriate parts of blargg's nes-ntsc library, bisqwit's implementation, or implement your own NTSC demodulator.

A neat feature you could do with the last is actually replace each color swatch with a gradient of all the resultant colors a given palette entry could end up with.

User avatar
rainwarrior
Posts: 8000
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NTSC color palette emulation, with the square wave modul

Post by rainwarrior » Sat Aug 18, 2012 10:57 pm

Well, even though there's no one true palette, that doesn't mean you can't create a palette that is fairly practical for using to colour your work prior to putting it on an NES. A ballpark palette is still better than just being told there is no real answer.

nintendo8
Posts: 54
Joined: Tue Jul 10, 2012 1:37 pm

Re: NTSC color palette emulation, with the square wave modul

Post by nintendo8 » Sun Aug 19, 2012 7:06 am

rainwarrior wrote:Well, even though there's no one true palette, that doesn't mean you can't create a palette that is fairly practical for using to colour your work prior to putting it on an NES. A ballpark palette is still better than just being told there is no real answer.
That is exactly what I want to do. I would like to use a general purpose palette then if somebody for whatever reason does not like the default palette then they can load their own. Right now I am using bisqwit's code but like you said there is no right answer so people should be able to use their own pal file.

tepples
Posts: 22278
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: NTSC color palette emulation, with the square wave modul

Post by tepples » Sun Aug 19, 2012 7:44 am

The Super NES has the same dot clock and the same 341-pixel line length as the NES, which produces the same diagonal artifact pattern in composite output. Its palette is nominally RGB with 32 levels per component, but does it also have the same problem of e.g. (5, 14, 0) being "greenish, except when it's next to other pixels that aren't"? I have a few hypotheses that'll need testing, and the tests will need an interdisciplinary SNESdev team. The goal is that ultimately, the "right color" for each NES color value is the Super NES color value that produces the closest composite waveform.

User avatar
mikejmoffitt
Posts: 1352
Joined: Sun May 27, 2012 8:43 pm

Re: NTSC color palette emulation, with the square wave modul

Post by mikejmoffitt » Wed Aug 22, 2012 7:21 am

tepples wrote:The Super NES has the same dot clock and the same 341-pixel line length as the NES, which produces the same diagonal artifact pattern in composite output. Its palette is nominally RGB with 32 levels per component, but does it also have the same problem of e.g. (5, 14, 0) being "greenish, except when it's next to other pixels that aren't"? I have a few hypotheses that'll need testing, and the tests will need an interdisciplinary SNESdev team. The goal is that ultimately, the "right color" for each NES color value is the Super NES color value that produces the closest composite waveform.
I would want to see if this differs between different SNES revisions that use the S-ENC encoder versus the S-RGB encoder.

User avatar
Eugene.S
Posts: 298
Joined: Sat Apr 18, 2009 4:36 am
Location: Russia (UTC+3)
Contact:

Re: NTSC color palette emulation, with the square wave modul

Post by Eugene.S » Tue Sep 25, 2012 1:41 am

neet wrote:As I have been heavily working on "lo-fi'ing" graphics in the last months, I want to share some results with you (as it was nesdev which has inspired me a lot).
First some informations about my current algorithm (general):
I'm emulating a TV screen using a virtual composite signal, real demodulation, some glow and a little bit of pixel grid (composite is unbiased). The virtual TV gets rendered at 752x240, "scanlined" to 752x720 and stretched to 960x720.
Try to arrange TV dots as RGB-subpixels for each luminofor:

Image Image
Image Image

fcism
Posts: 9
Joined: Wed Sep 25, 2013 8:49 pm

Re: NTSC color palette emulation, with the square wave modul

Post by fcism » Wed Sep 25, 2013 9:03 pm

Interestingly,i found bisqwit's palette generator=nestopia's palette generator(YUV)=nintendulator's palette generator(NTSC)
sat1.57+gamma2.2=nestopia's palette
sat1.87+gamma2.2=nintendulator's palette

Post Reply