It is currently Fri Apr 28, 2017 2:54 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sat Nov 05, 2016 7:50 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5045
Location: Canada
I found myself a little bit interested in the pattern of colour artifacts the NTSC NES produces. I decided to make a test ROM that shows off the patterns easily. Most of the shapes are arranged in groups of 3 pixels so they tend to align with diagonal 3-pixel groupings the artifacts seem to have.

Basically it's just a screen with some dot patterns. You can scroll it around with the D-pad. Press select to modify the background or foreground colours. Press start to reset.

Attachment:
File comment: comparison picture captured from my NES
ntsc_torture_compare.png
ntsc_torture_compare.png [ 276.88 KiB | Viewed 3279 times ]


Of particular interest I think is the square of dots at the top right, and the stripes at the top left. Both of these will appear as a single "colour", which you should be able to see three distinct states of depending what pixel they are scrolled to. As expected, I also notice that the phase changes when I reset my NES (there are two groups of states with red/green/blue vs cyan/magenta/yellow patterns). These effects aren't really new information or anything, but I thought a good visual demonstration might help understand the nature of these patterns.

(Note: the image is just a raw capture from my cheap capture device. It is an interlaced image, so it represents two consecutive frames. The specific colour depends on the startup alignment of the PPU, and the sharpness/definition of various things is highly specific to this capture device. It's not meant to represent any kind of ideal target for emulation.)


Attachments:
File comment: NTSC pattern torture test ROM
ntsc_torture.nes [40.02 KiB]
Downloaded 123 times
File comment: source code for ntsc_torture.nes
ntsc_torture_src.zip [5.66 KiB]
Downloaded 54 times


Last edited by rainwarrior on Fri Dec 30, 2016 6:06 pm, edited 2 times in total.
Top
 Profile  
 
PostPosted: Mon Dec 26, 2016 3:09 pm 
Offline

Joined: Sun Feb 07, 2016 6:16 pm
Posts: 193
I decided to have a stab at implementing bisqwit's NTSC filter code (the one he posted earlier this year with integer math).

This is what it ends up looking like at full resolution (the top left part makes me wonder if the coloring is correct - it doesn't match neither your screen capture nor blargg's filter, but any change I make produces the wrong palette in games).
Attachment:
File comment: ntsc_torture (2048x1920)
ntsc_torture.png
ntsc_torture.png [ 642.5 KiB | Viewed 2339 times ]

I'm not completely certain my implementation is correct though - the old tvfailpass/tv.nes test doesn't look that great compared to blargg's filter.
Though I can't test on an actual console/TV, so I have no way to know.
Attachment:
tvpassfail.png
tvpassfail.png [ 101.23 KiB | Viewed 2339 times ]

And this is what it looks like on an actual game:
Attachment:
smb3.png
smb3.png [ 2.36 MiB | Viewed 2339 times ]

Performance-wise, the code is pretty mean (although I'm sure my code is far from optimal). Between creating the NTSC signal from the palette output, converting it to RGB, and resampling the height to 1920px, it takes 2 threads to run the filter at 70fps (on my 7-year-old i5) while a 3rd core is running the emulation.
At quarter resolution though (1024x960), it's not that bad (approx 140fps)


Top
 Profile  
 
PostPosted: Wed Dec 28, 2016 10:58 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5045
Location: Canada
Sour wrote:
the top left part makes me wonder if the coloring is correct

There are six possible colourings depending on the phase of the PPU at time of reset.

On any given reset, you should be able to see three of the six possibilities by using the d-pad to move the screen around in 1 pixel increments.


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 1:25 am 
Offline
User avatar

Joined: Fri Oct 14, 2011 1:09 am
Posts: 248
Here are some sample pictures of what my QuickBASIC NES emulator produces for this test ROM:

Image Image Image
The horizontal lines in the bottom left of the screen (border region) disappear if I scroll it upwards (00 EF or lower).

The QuickBASIC code has a newer version of the filter that runs much much faster than the C++ version does (if the language difference is ignored), because it updates a running variable only once per channel per pixel, instead of doing 12 or 24 multiplications per pixel. But it is also less accurate, because it rounds to integers. It is unique compared to (probably) every other NES emulator in the world in that it simulates a full frame of television signal, with borders, syncs, colorbursts and all, with the NTSC decoder knowing absolutely nothing about what is happening inside the PPU (things like current scanline number, etc). The only interface between the NTSC decoder and the rest of the emulator is the 1 integer that represents the current voltage level of the NTSC signal that changes about 5 million times in a second.

The older and more accurate C++ version (the one that is documented in the Wiki) flickers between these two (click to zoom):
Image Image Image

The third picture is produced if the code merges all three fields.

Note that any possible hardware screen captures depend entirely on what ever postprocessing your television set / composite decoder happens to do with the signal.
If I change my (C++) emulator to merge two fields into one (which a television is certainly not required to do), here is one of the outcomes:

Image
It is quite a close match to the first sample posted by rainwarrior, if we ignore saturation differences.


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 4:33 am 
Offline
User avatar

Joined: Sat Apr 18, 2009 4:36 am
Posts: 255
Location: Russia
MESEN implementation:

feos want to modify this algorithm for PAL-Filter in near future.
But sines must be recalculated.


Attachments:

[ Play Quicktime file ] tor.mp4 [ 1.54 MiB | Viewed 2156 times ]
Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 8:26 am 
Offline
User avatar

Joined: Tue Apr 19, 2011 11:26 am
Posts: 106
Location: RU
I'd be really grateful if someone modifies the constants to the PAL standard.

Bisqwit wrote:
The QuickBASIC code has a newer version of the filter that runs much much faster than the C++ version does (if the language difference is ignored), because it updates a running variable only once per channel per pixel, instead of doing 12 or 24 multiplications per pixel. But it is also less accurate, because it rounds to integers. It is unique compared to (probably) every other NES emulator in the world in that it simulates a full frame of television signal, with borders, syncs, colorbursts and all, with the NTSC decoder knowing absolutely nothing about what is happening inside the PPU (things like current scanline number, etc). The only interface between the NTSC decoder and the rest of the emulator is the 1 integer that represents the current voltage level of the NTSC signal that changes about 5 million times in a second.

Is it here?


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 11:48 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5045
Location: Canada
Bisqwit wrote:
The horizontal lines in the bottom left of the screen (border region) disappear if I scroll it upwards (00 EF or lower).

Is there some explanation as to why they appear at all in your emulator? The ROM isn't doing any kind of raster manipulation, it's just a static screen.


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 12:27 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 18210
Location: NE Indiana, USA (NTSC)
feos wrote:
I'd be really grateful if someone modifies the constants to the PAL standard.

That depends on someone with a PAL NES being willing to run test patterns on hardware on short notice. Are you such a someone?


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 12:53 pm 
Offline
User avatar

Joined: Tue Apr 19, 2011 11:26 am
Posts: 106
Location: RU
I meant the constants in the Bisqwit's filter, and yes, myself and Eugene.S will run any tests that are needed.

We don't exactly have PAL NES, but this thing that we have should work very well, since Dendy uses a clone of PAL PPU:
viewtopic.php?f=9&t=14861


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 1:20 pm 
Offline
User avatar

Joined: Fri Oct 14, 2011 1:09 am
Posts: 248
feos wrote:
I'd be really grateful if someone modifies the constants to the PAL standard.

It is not only the matter of modifying the constant.
You have to reverse the phase of the colorburst for every other scanline, too (or something like that, I don't remember the specifics).

feos wrote:
Bisqwit wrote:
The QuickBASIC code has a newer version of the filter that runs much much faster than the C++ version does (if the language difference is ignored), because it updates a running variable only once per channel per pixel, instead of doing 12 or 24 multiplications per pixel. But it is also less accurate, because it rounds to integers. It is unique compared to (probably) every other NES emulator in the world in that it simulates a full frame of television signal, with borders, syncs, colorbursts and all, with the NTSC decoder knowing absolutely nothing about what is happening inside the PPU (things like current scanline number, etc). The only interface between the NTSC decoder and the rest of the emulator is the 1 integer that represents the current voltage level of the NTSC signal that changes about 5 million times in a second.

Is it here?

Yes, that would be it.

rainwarrior wrote:
Bisqwit wrote:
The horizontal lines in the bottom left of the screen (border region) disappear if I scroll it upwards (00 EF or lower).

Is there some explanation as to why they appear at all in your emulator? The ROM isn't doing any kind of raster manipulation, it's just a static screen.

I can't offhand think of any explanation. The border color is determined by the address internally accessed by the PPU during the border rendering (i.e. if it's 3Fxx...), and/or the background color from the palette, so there may be a bug somewhere in that processing.


Eugene.S wrote:
<video attachment>

The video is chroma-supersampled (YUV 420p colorspace). It rather completely defeats the purpose of trying to show something where colors of individual pixels matter.


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 6:40 pm 
Offline

Joined: Tue Nov 23, 2004 9:35 pm
Posts: 567
I took a video capture of the ROM running in my real NES, and the capture is surprisingly faithful to what I saw on my TV screen :

https://youtu.be/l-y9gaU-pR4

When you watch this in 60fps, you can see some that combinations of colors cause the upper left square to visibly flicker, which I thought weird. I would have lingered longer, but I couldn't see it on the capture device's viewer, so I thought the effect was lost. When I converted the video to 60fps, it reappeared.

_________________
Nerdly Pleasures - My Vintage Video Game & Computing Blog


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 8:24 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5045
Location: Canada
Great Hierophant wrote:
When you watch this in 60fps, you can see some that combinations of colors cause the upper left square to visibly flicker, which I thought weird. I would have lingered longer, but I couldn't see it on the capture device's viewer, so I thought the effect was lost. When I converted the video to 60fps, it reappeared.

My captured picture is actually an interlaced image. If you look closely at the top left square, you can see that it is two alternating fields of magenta and yellow, i.e. the output is alternating frames this way.

I didn't intend for the capture image to be a thing to verify your emulators against, just a sample image demonstrating some of the colour artifacts that can be produced. For instance, the edges of white text via the capture card show a lot of rainbow stripes there, but a different decoder, like the one in my TV, produces much cleaner definition on that. A lot of this stuff varies significantly from device to device. (Also don't forget there are 6 possible alignments of the PPU!)


Top
 Profile  
 
PostPosted: Thu Dec 29, 2016 10:24 pm 
Offline
User avatar

Joined: Tue Apr 19, 2011 11:26 am
Posts: 106
Location: RU
Bisqwit wrote:
It is not only the matter of modifying the constant.
You have to reverse the phase of the colorburst for every other scanline, too (or something like that, I don't remember the specifics).

Yes. Here's what I used in my FCEUX attempt (with a lookup table and 768 pixel long line):
Code:
const  float   phasex  = (float) 5/18*2;
const  float   phasey  = (float) 1/ 6*2;
const  float   pi      = 3.14f;

float alpha = (x*phasex + y*phasey)*pi;          // 2*pi*freq*t
if (y%2 == 0) alpha = -alpha;                    // phase alternating line!
moire[x+y*18] = Y + U*sin(alpha) + V*cos(alpha); // modulated composite signal


EDIT:

The 768-pixel approach was bad, because it matched neither tuner result, not TV result, because of oversampling of YUV. But I was generating too little versions of each color: tuner output (640 pixel wide) shows about 17 versions of each color, which is how pixel freq alignes with Luma sample freq. The end value is a direct average of the Luma samples present in that pixel:

Image


Last edited by feos on Fri Dec 30, 2016 2:59 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Fri Dec 30, 2016 1:59 pm 
Offline
User avatar

Joined: Fri Oct 14, 2011 1:09 am
Posts: 248
rainwarrior wrote:
My captured picture is actually an interlaced image.

I was wondering why the per-scanline color alterations appear to be twice as thin/frequent as in my screenshots.
Thanks for explaining.

EDIT: Hmm, I wonder if you can generate composite video in real time with e.g. Raspberry Pi GPIO DAC (or some ARM Nucleo board), for testing different outcomes.


Top
 Profile  
 
PostPosted: Fri Dec 30, 2016 5:14 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 2983
Location: Brazil
Does not work here.

---------------------------
Mesen
---------------------------
Mesen não pode iniciar pois foi incapaz de carregar MesenCore.dll devido a falta de dependências.
---------------------------
OK
---------------------------

"Mesen cannot start because it was unable to load MesenCore.dll due to the lack of dependencies".


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: gauauu, Google [Bot], Punch, Revenant and 11 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