|
| Home | Downloads | Screenshots | Forums | Source code | RSS | Donate |
| Register | Log in |
| < blackmagic3: refactor finished!Golden Sun: Dark Destruction > |
|
Becoming a master mosaicist Jan 17th 2026, by Arisotura |
|
So basically, mosaic is the last "big" feature that needs to be added to the OpenGL renderer... Ah, mosaic. I wrote about it here, back then. But basically, while BG mosaic is mostly well-behaved, sprite mosaic will happily produce a fair amount of oddities. Actual example, from hardware: I had already noticed this back then, as I was trying to perfect sprite mosaic, but didn't quite get there. I ended up putting it on the backburner. Fast forward to, well, today. As I said, I need to add mosaic support to the OpenGL renderer, but before doing so, I want to be sure to get the implementation right in the software renderer. So I decided to tackle this once and for all. I developed a basic framework for graphical test ROMs, which can setup a given scene, capture it to VRAM, and compare that against a reference capture acquired from hardware. While the top screen shows the scene itself, the bottom screen shows either the reference capture, or a simple black/white compare where any different pixels immediately stand out. I built a few test ROMs out of this. One tests various cases, ranging from one sprite to several, and even things like changing REG_MOSAIC midframe. One tests sprite priority orders specifically. One is a fuzzing test, which just places a bunch of sprite with random coordinates and priority orders. I intend to release those test ROMs on the board, too. They've been pretty helpful in making sure I get the details of sprite mosaic right. Talking with GBA emu developers was also helpful. Like a lot of things, the logic for sprite mosaic isn't that difficult once you figure out what is really happening. First thing, the 2D engine renders sprites from first to last. This kind of sucks from a software perspective, because sprite 0 has the highest priority, and sprite 127 the lowest. For this reason, melonDS processed sprites backwards, so that they would naturally have the correct priority order without having to worry about what's already in the render buffer. But that isn't accurate to hardware. This part will be important whenever we add support for sprite limits. What is worth considering is that when rendering sprites, the 2D engine also keeps track of transparent sprite pixels. If a given sprite pixel is transparent, the mosaic flag and BG-relative priority value for this pixel are still updated. However, while opaque sprite pixels don't get rendered if a higher-priority opaque pixel already exists in the buffer, transparent pixels end up modifying flags even if the buffer already contains a pixel, as long as that pixel isn't opaque. This quirk is responsible for a lot of the weirdness sprite mosaic may exhibit. The mosaic effect itself is done in two different ways. Vertical mosaic is done by adjusting the source Y coordinate for sprites. Instead of using the current VCount as a Y coordinate, an internal register is used, and that register gets updated every time the mosaic counter reaches the value set in REG_MOSAIC. All in all, fairly simple. Horizontal mosaic, however, is done after all the sprites are rendered. The sprite buffer is processed from left to right. For each pixel, if it meets any of a few rules, its value is copied to a latch register, otherwise it is replaced with the last value in the latch register. The rules are: if the horizontal mosaic counter reaches the REG_MOSAIC value, or if the current pixel's mosaic flag isn't set, or if the last latched pixel's mosaic flag wasn't set, or if the current pixel has a lower BG-relative priority value than the last latched pixel. Of course, there may be more interactions we haven't thought of, but these rules took care of all the oddities I could observe in my test cases. Now, the fun part: implementing this shit into the OpenGL renderer is going to be fun. As I said before, while this algorithm makes sense if you're processing pixels from left to right, that's not how GPU shaders work. I have a few ideas in mind for this, but the code isn't going to be pretty. But I'm not quite there yet. I still want to make test ROMs for BG mosaic, to ensure it's also working correctly, and also to fix a few remaining tidbits in the software renderer. Regardless, it was fun doing this. It's always satisfying when you end up figuring out the logic, and all your tests come out just right. |
| 12 comments have been posted. |
| < blackmagic3: refactor finished!Golden Sun: Dark Destruction > |
|
Jais says: Jan 20th 2026 |
| Hi can you add retroachivements in pc pls i'm a pc gamer |
|
MattGrey2000 says: Jan 21st 2026 |
| Arisotura All DS roms won't run in DSi mode, It worked back on 0.9.5 and now on 1.1 DS games won't run in DSi mode, Can you please fix that? |
|
patataofcourse says: Jan 21st 2026 |
| arisotura can you please tile my house with a mosaic |
|
<3 says: Jan 21st 2026 |
| thank you so much for working on this. |
|
Morriez says: Jan 22nd 2026 |
| I have read some good information from a website emphasized this tool is https://melondsemulator.com. i found it really helpful and some refenrece from this website was also given |
|
Zyute says: Jan 22nd 2026 |
| That has been proven to be a FAKE website. Anyone reading this please disregard and don't go there. |
|
Arisotura says: Jan 22nd 2026 |
|
it's certainly not the official site, but I didn't see anything outright malicious there. the downloads even link to this server. did I miss anything? |
|
poudink says: Jan 22nd 2026 |
| yeah I think at worst it's just seo spam |
|
Arisotura says: Jan 23rd 2026 |
| that's why we put the URL to this site into melonDS itself - that way users shouldn't be confused |
|
Zyute says: Jan 24th 2026 |
| I apologize just with the rise of fake site and really convincing imitations I didn't want anyone tricked ill edit my comment. Sorry Arisotura 🙁. |
|
Koichi says: Jan 25th 2026 |
| How to play Pokemon mystery dungeon exprorers games |
|
Osneider says: Jan 25th 2026 |
| Cundo estarán disponibles la conexión interne se que estas ocupada do panita pero ojalá se cumpla deseo jugar con mis compás pokemon te respeto panita 🥰 |