Photo-Sensitive Epilepsy Safe NES/SNES Emulation?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Tygerbug
Posts: 60
Joined: Sun Jan 19, 2014 5:15 pm

Photo-Sensitive Epilepsy Safe NES/SNES Emulation?

Post by Tygerbug » Wed Sep 23, 2020 6:25 am

viewtopic.php?f=22&t=20919

Previous thread ^^

Tetrahedrus and others have been helping out by creating hacks of NES/SNES games to be safe for those with photo-sensitive epilepsy, and we're very grateful.

I'm curious about how viable it would be for an emulator (like Mesen) to detect and remove (or lessen) this sort of full-screen flashing, or an emulator script to do it.

Many triggers come from rapid writes to color 0 of the background palette (universal background color). This could be unchecked.

One thing that might work would be setting a minimum frame count for checking writes to that address, ignoring any further writes that land within that time window, and when no further writes are detected, apply the most recently attempted write only.

calima
Posts: 1306
Joined: Tue Oct 06, 2015 10:16 am

Re: Photo-Sensitive Epilepsy Safe NES/SNES Emulation?

Post by calima » Wed Sep 23, 2020 9:51 am

It'd be very simple to do at the image level, though only for large areas flashing.

1. Grayscale the image
2. Repeatedly downscale it in half, until you only have one pixel left. You now have the screen's average brightness
3. If the new frame changes enough pixels and is brighter enough, don't show it / slowly overlay it / etc etc. This could turn the common white screen flash into a slow glow effect

You do need to edit the emulator code for this, and I can't imagine testing would be easy, for those affected. False positives are an issue.

Fiskbit
Posts: 259
Joined: Sat Nov 18, 2017 9:15 pm

Re: Photo-Sensitive Epilepsy Safe NES/SNES Emulation?

Post by Fiskbit » Wed Sep 23, 2020 1:21 pm

(Sorry, didn't see this thread before responding in the Mesen one. Here's what I posted there:)

I think you could automatically detect this with something along the lines of looking for large changes in a color histogram across adjacent frames, and doing some kind of effect when this is detected too many times in a short window. Maybe the effect would be to fade the palette to the new one over several frames. If it's beneficial for the emulator to know this before a frame is rendered instead of after (which I'd guess would be less effective because you'd miss mid-screen changes, such as greyscale toggles after a top HUD), you could maybe track how many pixels on the screen come from each palette index on the previous frame and see what the overall change would be from palette or mask changes made during vblank for the upcoming frame. Any anti-flash mechanism would need to be looking for multiple transitions, not just one, because it might otherwise detect switching to things like a menu or transitioning to a new screen. I'd probably start with a threshold of 3 or more rapid transitions, maybe also detecting 2 if going from dark to light to dark (since I suspect legitimate screen transitions are more likely to go light to dark to light.).

M_Tee
Posts: 427
Joined: Sat Mar 30, 2013 12:24 am
Contact:

Re: Photo-Sensitive Epilepsy Safe NES/SNES Emulation?

Post by M_Tee » Wed Sep 23, 2020 3:52 pm

Does Mesen handle scripts like FCEUX does?
Would something like this even be possible to tackle via scripts?

Is it common or possible for emulators to display data at a delay from when it's processing it?

Fiskbit
Posts: 259
Joined: Sat Nov 18, 2017 9:15 pm

Re: Photo-Sensitive Epilepsy Safe NES/SNES Emulation?

Post by Fiskbit » Wed Sep 23, 2020 4:17 pm

Mesen has Lua scripting (see documentation). It can write to palette RAM. It can also read/write the color of a given pixel or even the whole screenbuffer, apparently with 32-bit ARGB color. I think this is good enough to do what I've suggested, though it could get confused if there are two identical colors and only one of them changes (which could be a significant problem, actually).

Edit: Thinking some more about it, with Lua, I think your best bet would be to analyze after the frame instead of before, looking at the overall color across the whole screen and then doing the effect. An easy effect might just be to reduce brightness for some number of frames when big swings are detected (perhaps just dark to light).

Post Reply