Homebrew TWPatcher - DS(i) mode screen filters and patches

  • Thread starter Sono
  • Start date
  • Views 745,655
  • Replies 2,428
  • Likes 101

Are you interested in a complete replacement of TwlBg which includes all patches?

  • Yes, I don't care how broken it will be!

    Votes: 188 79.3%
  • No, I don't want to use even more broken stuff

    Votes: 20 8.4%
  • Yes, but only in GBA mode, because I play DSi exclusives

    Votes: 12 5.1%
  • No, because I only use DS and DSi mode

    Votes: 17 7.2%

  • Total voters
    237
  • Poll closed .

lordkaos

Well-Known Member
Member
Joined
Mar 13, 2009
Messages
597
Trophies
1
XP
1,582
Country
United States
can i ask you something?, is it normal for the 3DS to return to the home menu when I press the L+R+Select+Start or L+R+Down+B button combination while playing a DS game using twilightmenu?, I read you could return to the twilightmenu homescreen pressing one of those combinations but it has never worked for me, I'm on the latest version.
 

RocketRobz

Stylish TWiLight Hero
Developer
Joined
Oct 1, 2010
Messages
16,571
Trophies
3
Age
24
XP
20,947
Country
United States
can i ask you something?, is it normal for the 3DS to return to the home menu when I press the L+R+Select+Start or L+R+Down+B button combination while playing a DS game using twilightmenu?, I read you could return to the twilightmenu homescreen pressing one of those combinations but it has never worked for me, I'm on the latest version.
It doesn't work on O3DS.
On N3DS, it only fails to work sometimes.
 

ghjfdtg

Well-Known Member
Member
Joined
Jul 13, 2014
Messages
1,360
Trophies
1
XP
3,274
Country
I tried wide screen but really couldnt get into it. seems like its the same res just stretched so your getting an even worse image with only a bit more FOV. this isnt Sonos fault by any means just what we have to deal with
Exactly. It uses the same resolution but stretched up which means there is quite a loss in quality. I don't understand how someone can do that to their eyes.
 

Vague Rant

Deceptively cute
Member
Joined
Aug 7, 2008
Messages
2,463
Trophies
2
Location
Melbourne
Website
vaguerant.tumblr.com
XP
3,302
Country
I tried wide screen but really couldnt get into it. seems like its the same res just stretched so your getting an even worse image with only a bit more FOV. this isnt Sonos fault by any means just what we have to deal with

My thoughts exactly. I'll just have the Linear Sharpen 1 filter instead, it's more effective.

Hello, just got the widescreen fix working, but god pokémon platinum is looking pixelated and horrible, any way of adding these aforementioned filters ? At least using a phone, no pc for the moment, also thanks a lot for the effort guys :]

Exactly. It uses the same resolution but stretched up which means there is quite a loss in quality. I don't understand how someone can do that to their eyes.

Sorry to batch quote you all here, but I think the majority of what you're objecting to is probably the filtering (or lack thereof) that's currently applied by the patched TwlBg when stretching games to widescreen. I don't understand the technical details whatsoever, but part of what the currently-available widescreen patch is doing is disabling all filtering on the horizontal axis, so you're seeing the bare, unfiltered, non-integer scaled pixels. The simple fact of this is that it's not going to look great, especially at the extremely low resolutions of the DS/3DS screens.

Of course it's more than just that, and it's true that stretching the same number of pixels over a wider area is reducing the overall picture quality, but including some smoothing filter/s on the vertical and horizontal (which I believe Sono has said is possible) will go a long way to mitigate the visual artifacts of scaling up by another 20% from the default. I agree that right now the picture quality is not all that it could be, but--without intending to put any additional pressure on Sono, sorry--I do believe it's partly just the nature of a feature that's in its infancy and can/will be improved upon with (considerable) time and effort.

EDIT: I went back and found Sono's post on widescreen and filtering:
The 3DS version will have support for both [filters and widescreen], but the filter will only be applied on the Y matrix, so the filter will only be visible vertically, because the widescreen patch HAS TO write an identity matrix in order to enable proper stretching. This could be easily fixed, but not now. I still have to do the automatic pattern generation for unique matrixes to work.
 
Last edited by Vague Rant,

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,310
Country
Hungary
Sorry to batch quote you all here, but I think the majority of what you're objecting to is probably the filtering (or lack thereof) that's currently applied by the patched TwlBg when stretching games to widescreen. I don't understand the technical details whatsoever, but part of what the currently-available widescreen patch is doing is disabling all filtering on the horizontal axis, so you're seeing the bare, unfiltered, non-integer scaled pixels. The simple fact of this is that it's not going to look great, especially at the extremely low resolutions of the DS/3DS screens.

Of course it's more than just that, and it's true that stretching the same number of pixels over a wider area is reducing the overall picture quality, but including some smoothing filter/s on the vertical and horizontal (which I believe Sono has said is possible) will go a long way to mitigate the visual artifacts of scaling up by another 20% from the default. I agree that right now the picture quality is not all that it could be, but--without intending to put any additional pressure on Sono, sorry--I do believe it's partly just the nature of a feature that's in its infancy and can/will be improved upon with (considerable) time and effort.

Exactly.

The main reason I clear the scaling on the X axis is because I didn't have enough time to do patches which patch the X and Y matrixes individually (because the scale ratio isn't equal on both axises).
The reason I write an identity scale matrix is because the ratio count (stretch / contract) doesn't match both axes, so I'd have to store X and Y matrixes individually, for which I didn't make a patch yet because I have yet to find enough space to fit it, and I'd have to write my own matrix uploader code into a very small space, so I didn't do it yet.

Let's say we want to upscale the image by 5/3 (widescreen GBA). Here 5 is the "stretch" (k) amount, and 3 is the "contract" (j) amount. If you multiply the GBA screen width with that ratio, you get the 3DS's top screen width of 400 (= 240 * (5 / 3))

Here's how the scale matrix works (on an understandable level, in hardware it's entirely different, and not even I can understand it fully):
- there are k matrixes, which output k pixels from j pixels (this is how upscaling works)
- j is actually not a number, but a k long list of yes/no which tell if we should check the next source pixel or not (j as a number is just the amount of "yes" in the list, which is 3 in this example)
- we take a j block of pixels and store it somewhere, along with its position on the source image, so we can still find the neighboring pixels
- currently the source index (the center of a single scale matrix) is the first pixel of the j block of pixels
- for each k matrix entry in the matrix list
- put the pixel at the source index into the middle number
- put neighboring pixels also into the matrix
- do a weighted pixel average into the center of the scale matrix (weighted averaging means that you take for example 25% of the pixel on the left, 25% on the right, 50% of the current pixel, and add them together (this is also how blurring works))
- write the resulting pixel into the output
- if the current index into j says "yes" then move to the next pixel in the "j" block into the center of the matrix (so you just push the entire image to the left so it'll be in the center), otherwise the current source index stays as-is

(if you didn't understand anything I said, just search for how 1D image matrix filtering works)

The problem is that both k and j are limited to being anywhere between 1 and 8 (inclusive), and that's a harware limitation, and I can't get around it.

So, because the scale matrix can only step integer amounts of pixels (can't read only half pixels for example), you have to mathematically recalculate each matrix entry in a whole scale matrix, otherwise the pixels will be off. And also the j list has to be also matching, otherwise you can "delaminate" the screen, which can cause major headaches for people because it looks like double vision ghosting.
tl;dr: I have to clear the filtering on the X axis because it would look even worse without clearing it because you have to "reprogram" the matrix hardware for each scaling ratio to look right, and that requires mathematically recalculating it again, which I can't do due to the lack of my mathematical knowledge.

I can't enable X scaling until I can make the GUI be aware of it, and offer you to choose unique scale matrixes for both X and Y axis. I also have to develop a patch which can upload the X and Y axis individually (which is simple, but I have space problems, so it'll take a while to develop).
 
Last edited by Sono,

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,260
Country
United States
That sounds like a ton of work. Way more than applying the prior non-widescreen twl patcher to agb. Wonder what kind of bribe that would take. :P
 

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,310
Country
Hungary
That sounds like a ton of work. Way more than applying the prior non-widescreen twl patcher to agb. Wonder what kind of bribe that would take. :P

Nah, it's really simple, I just can't find a time in my nonexistant "schedule" where I'm not currently dying from the heat and not sleeping.
And also, I need to learn maths, so I can autogenerate the filters regardless of the scaling ratio.

The real work would be getting widescreen AND screen swap working. That IS a lot of work, because patching DMPGL (3DS' OpenGL driver) is nearly impossible, and most of the times I don't have enough code space and have to get very creative.
 

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,260
Country
United States
Well its not that hot here but I'm still too dumb. I located the active image matrix in AGB_FIRM and have been able to change it and pack back into agbbg.xci. Most changes result in black screen unless I have the start button held to skip scaling, that includes the one Sono suggested way back on page 3 when he probably knew less about this process, as well as trying to import any matrix from twlbg.xci. But one time I swapped the location of the hex 20s and 40s in the matrix and got it to run with a pointillistic effect (black pixel boxes surrounding light pixels), so I know I'm in the right area at least. I just don't know what makes an acceptable matrix, especially for something like (bi?)linear interpolation.

I'm guessing I should read these matricies as octal instead of hexidecimal, but I still have a hard time matching them up to your explanation. But it seems like it has to be more than just weighting how much of pixel X goes into the color of pixel Y if its so crash prone with the wrong values.
 

Sono

cripple piss
OP
Developer
Joined
Oct 16, 2015
Messages
2,820
Trophies
2
Location
home
XP
9,310
Country
Hungary
Well its not that hot here but I'm still too dumb. I located the active image matrix in AGB_FIRM and have been able to change it and pack back into agbbg.xci. Most changes result in black screen unless I have the start button held to skip scaling, that includes the one Sono suggested way back on page 3 when he probably knew less about this process, as well as trying to import any matrix from twlbg.xci. But one time I swapped the location of the hex 20s and 40s in the matrix and got it to run with a pointillistic effect (black pixel boxes surrounding light pixels), so I know I'm in the right area at least. I just don't know what makes an acceptable matrix, especially for something like (bi?)linear interpolation.

I'm guessing I should read these matricies as octal instead of hexidecimal, but I still have a hard time matching them up to your explanation. But it seems like it has to be more than just weighting how much of pixel X goes into the color of pixel Y if its so crash prone with the wrong values.

What do you mean you "located" the "active" image matrix? I never put patching instructions for AgbBg in the first post :wacko:

Also, the values are in hex, fixed-point. 4000 is 1.0, 2000 is 0.5, E000 is -0.5, C000 is -1.0
 

Rahkeesh

Well-Known Member
Member
Joined
Apr 3, 2018
Messages
2,178
Trophies
1
Age
42
XP
3,260
Country
United States
I meant the pattern

Code:
0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000
0000 0020 0040 0000 0020 0040
0040 0020 0000 0040 0020 0000
0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000

I find this around x4A190 in my code.bin extracted from my agbbg.xci. You suggested looking for this back on the 2nd or 3rd page.

Its "active" in the sense that I can see changes in game when I make small changes to the values, so it seems to be the right area. Someone else on 3rd page suggested instead editing what looks like an unused matrix right above this one, it avoided crashes but doesn't seem to do anything. (Guessing that is unused 1.25x scaling?)

Thanks for the obvious tip about treating these as fixed point decimals, makes these almost readable, maybe I will figure it out eventually.
 
Last edited by Rahkeesh,

AkitoUF

Well-Known Member
Member
Joined
Jan 5, 2016
Messages
296
Trophies
0
Age
32
XP
785
Country
Chile
I just wanted to thank you guys for this achievement.
Which is your preferred filter to play with?
 

VMM

Hamon > Stand
Member
Joined
Jul 1, 2010
Messages
3,132
Trophies
2
Age
33
XP
2,243
Country
Brazil
Nah, it's really simple, I just can't find a time in my nonexistant "schedule" where I'm not currently dying from the heat and not sleeping.

Duuuude... how many nights have you stayed awake since you started this project?
I think I can speak in behalf of all community in this:

We love the progress you're making, it's rather impressive and something good for the community,
but you should always prioritize your health.

This lack of sleeping will cause fatigue, can drive you sick and will hinder you as a developer.
I can't remember how many times that as a developer, I made stupid coding mistakes because I was tired from not sleeping.
Linters help a lot, but there is always something, calling a function with the wrong name,
some wrong math, you know things that would be simple if I had rested properly.

I see someone posted it before, but Sono actually is sleep in portuguese haha
So do yourself a favor and get some sleep :)

Also thank you very much for your work, been playing Heartgold again and your filter brought new life to it.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: @Psionic Roshambo, JonTron's back yet again until he disappears into the void for another 6 or...