gpsp icon indicating copy to clipboard operation
gpsp copied to clipboard

Green swap support

Open GValiente opened this issue 1 year ago • 15 comments

Thanks for your work on this core, compatibility is much better than I expected! Most of Butano games and examples work without issues.

Would it be too hard to add support for the green swap effect? I know that it's a niche thing and no commercial games used it, but it would be cool to see it on this core too.

Here's a test ROM and a couple of screenshots: Test ROM

green_swap-0 green_swap-1

GValiente avatar Dec 30 '23 11:12 GValiente

Ah - is that the undocumented mode in DISPCNT? Not sure how hard that would be to implement - can't speak for David but I might have a look at some point out of curiosity - although ultimately it's probably a bit far down the priority list given there's still issues with commercial games to resolve! Will keep you updated here tho.

andymcca avatar Dec 30 '23 16:12 andymcca

Yeah I am aware of this bit, however since no commercial games used it I did not bother :D Do homebrew games use this often? I'm curious what's the usecase. Is it to "mimic" some sort of mosaic effect? We have been fixing many bugs related to new homebrew (for instance Good Boy has uncovered a bunch of bugs) so any bugs and/or fixes are welcome!

davidgfnet avatar Jan 13 '24 10:01 davidgfnet

I use it quite a bit, usually to mimic a short full screen blur:

  • Butano Fighter shows it when the MC is hit.
  • Varooom 3D shows it when the car is hit or when a turbo boost is used.
  • GBA-NICCC uses it to show the black and white antialiased mode.

GValiente avatar Jan 13 '24 12:01 GValiente

Some pics taken with mGBA: bf_off bf_on v3d_off v3d_on gba-niccc_off gba-niccc_on

GValiente avatar Jan 13 '24 14:01 GValiente

Cool! Will give it a look! It might require some work since gpsp tries really hard to optimize stuff like palette writes and conversion (for speed) and there's palette calculations all over the place :D It's also a case that should be really optimized for it being disabled, since literally 99% of games dont use it. Thanks!!

davidgfnet avatar Jan 14 '24 10:01 davidgfnet

Isn't it just a full screen effect after the final image has been composed?

According to gbatek, green swap "appears to be applied to the final picture (ie. after mixing the separate BG and OBJ layers)."

Anyway, thanks a lot for looking at it.

GValiente avatar Jan 14 '24 11:01 GValiente

Ah right! For some reason I recalled it being like mosaic (with BG/OBJ bits), but it's just a full effect at the end! Yeah we can just add some routine at the end, won't be very fast tho, but it's OK since nobody uses it. I have some plan to rewrite some of these parts in gpsp to make it faster. We currently have color correction (which is also a full-screen effect), and we could merge some of these effects so that they don't require a full screen update at the end (and save a lot of cycles, right now video rendering is 50% of the consumed cpu cycles for the emulator). Thanks!

davidgfnet avatar Jan 14 '24 17:01 davidgfnet

Hey @GValiente, I just opened draft PRs that implement Green Swap - PR #260 and PR #261. I used the mgba implementation as a guide. Looks pretty straightforward but any chance you can build and test it for me? It looks correct to me when I try the test ROM you gave in the first message but my eyes aren't what they used to be!!!

@davidgfnet I added the code to video.cc rather than in post-processing in libretro.c - as this is a native effect rather an emulation feature this seemed more correct?

andymcca avatar Aug 25 '24 20:08 andymcca

https://github.com/user-attachments/assets/146a737c-e4f8-4722-a7ef-85e3a90ce4cd

Just me pressing A at random times on your demo to toggle between AA on/off. Think it seems to be working ok?

andymcca avatar Aug 25 '24 21:08 andymcca

There's no fake antialiasing like with mGBA:

green_swap

GValiente avatar Aug 26 '24 08:08 GValiente

@GValiente I think I've fixed it - needed to use RGB565 values but also a dumb error on my part with overwriting the previous pixel value before getting the next green channel to swap. Please try testing again? Thanks!

https://github.com/user-attachments/assets/1dd86cc6-267f-4030-994b-02f215e8e6e0

andymcca avatar Aug 26 '24 09:08 andymcca

The new video looks better, yeah.

Here's a test ROM, if you want to compare it against a real GBA and other emulators: green_swap.zip

EDIT: I already posted it in the first post xD

GValiente avatar Aug 26 '24 18:08 GValiente

Thanks - yes I used green_swap.gba primarily to compare gpsp to mgba and Nanoboy when troubleshooting intially. The results are now pretty much identical since my latest commit to the PR.

andymcca avatar Aug 26 '24 22:08 andymcca

mgba Screenshot 2024-08-31 122356

andymcca avatar Aug 31 '24 11:08 andymcca

gpsp (with PR #260 / PR #261) Screenshot 2024-08-31 122614

andymcca avatar Aug 31 '24 11:08 andymcca