ihhub / fheroes2

fheroes2 is a recreation of Heroes of Might and Magic II game engine.
https://ihhub.github.io/fheroes2/
GNU General Public License v2.0
2.71k stars 376 forks source link

Add option to not fill the entire screen, only the amount of pixels of the selected resolution AKA pixel perfect mode #6612

Open zenseii opened 1 year ago

zenseii commented 1 year ago

Preliminary checks

Describe the problem requiring a solution

We should consider adding the possibility to not stretch the image to fill the screen in the vertical direction too. Currently if you select 1280x960 in fullscreen mode on a 1920x1080 screen the image will be stretched to fill the entire height of the screen, instead of leaving two horizontal borders of 120/2 px above and below the image. Please correct me if I'm wrong about this @oleg-derevenetz.

Now that we have integer scaling available I believe it makes sense to have such a "pixel perfect" mode available so that the users who want to can have the sharpest image possible with no stretching/non-integer upscaling. I realize some of this might be dependent on the gpu driver options?

A similar example is how the campaign videos are kept in the original resolution without stretching/upscaling when you have a higher resolution than 640x480 selected. Ideally it should be possible to have these videos upscaled too to match the selected resolution, this might be another issue all together.

If anything I think we should figure out how to make the current image options and the future ones as simple and as easy to understand for the users as possible.

Relates to https://github.com/ihhub/fheroes2/issues/5373 and https://github.com/ihhub/fheroes2/pull/6516 and https://github.com/ihhub/fheroes2/issues/6586#issuecomment-1420910870

Describe the possible solution

Points:

  1. Decide if we need a non-stretched mode. Potentially implement it.
  2. Figure out how to make all the scaling and image related options streamlined, like filters, aspect ratios, integer scaling.

Additional info

No response

ihhub commented 1 year ago

Hi @zenseii , is this issue still valid after the latest resolution changes?

zenseii commented 1 year ago

Hi, @ihhub. It has indeed been fixed with the latest resolution changes. I'm not sure which one it is, for later reference, but now I can select 640x512 (x2.0) and this gives perfectly square pixels by adding borders above and below the image.

It should be noted that people should use the "nearest" filtering mode to achieve unblurred pixels, and this is only available thru the config file fheroes2.cfg.

image

We should maybe open a separate issue/discussion about whether we should always add borders to the side as well for resolutions like the one shown above. I'm not sure if this is even possible.

zenseii commented 1 year ago

The only point still standing from my OP is about adding the option to switch between filters in the options, instead of having it locked behind fheroes2.cfg. All the other points have been solved.

zenseii commented 1 year ago

I see adding an option to switch between the filters has already been requested here: https://github.com/ihhub/fheroes2/issues/4946 and https://github.com/ihhub/fheroes2/issues/5656 so I'm closing this issue.

zenseii commented 1 year ago

Actually, I looked closer and it seems the issue about square pixels isn't solved. If you look closely at my picture above you can spot both horizontal and vertical pixels that aren't square when using 640x512 (x2.0): This part of the Y that is 3 pixels wide (x-direction) instead of 2:

x-direction ![image](https://github.com/ihhub/fheroes2/assets/12501091/4179cadb-b96b-4c6f-92a2-4ae3b15d3a8c)

And this line is 3 pixels tall (y-direction) instead of 2:

y-direction ![image](https://github.com/ihhub/fheroes2/assets/12501091/5910bd3c-580e-4f07-b35e-aa95c137d393)

Meanwhile I noticed that when in windowed mode the pixels are perfectly square.

The solution for a screen with a resolution of 1920x1080 px is to have the resolution of "640x480 (x2.0)" together with vertical borders above and below with each a height of 60 px so that you get 480 * 2 + 60 + 60 = 1080.

Currently for me 640x480 (x2.0) produces a stretched image without borders:

Click for 640x480 (x2.0) image ![image](https://github.com/ihhub/fheroes2/assets/12501091/475f2935-b4ca-44d4-b203-37c2cba5bf09)
zenseii commented 1 year ago

I went and simply added the resolution of 640x540 in my Intel GPU driver settings (this laptop has intel iGPU with Nvidia dGPU) and lo and behold I was able to get perfect square pixels with borders that are 60px wide: image

In other words I needed the resolution that was 640 x (480 + 30 + 30) = 540, which becomes 1280x1080 when multiplied by 2.

zenseii commented 1 year ago

Here are some additional notes:

  1. When using 960x540 (2.0x or not doesn't matter), which is generally the recommended for 1920x1080px screens, we have no issues in the adventure map, nor any other instance, except for the main menu background (*and credits, see edit below) which is stretched both vertically and horizontally.

The Sword's blade makes it pretty obvious (640x540 to the left, 960x540 to the right): sword

I've highlighted this in the Q from the quit button using nearest filtering:

Q letter Pixel perfect 640x540 with borders above and below the background: ![image](https://github.com/ihhub/fheroes2/assets/12501091/65f1367a-476a-4198-807d-8ef6599e4ba5) Stretched image in 960x540 (2.0x and not, it doesn't matter): ![image](https://github.com/ihhub/fheroes2/assets/12501091/d92decd1-3629-4e85-880b-1e07f977626f)
  1. The problem with 640x540 is that it obviously doesn't have the width of the adventure map that 960x540 has. The solution is obviously to make sure that the 960x540 modes have vertical borders in the main menu in addition to horizontal borders.

EDIT: Actually the Credits suffer from this too since they are stretched. Take a look at the fheroes2 engine text:

Credits text Pixel perfect 640x540: ![image](https://github.com/ihhub/fheroes2/assets/12501091/780da617-b04e-4eb0-b5b9-c8e65f5de6e5) Stretched 960x540 (2.0x and not): ![image](https://github.com/ihhub/fheroes2/assets/12501091/d360ebfe-a12e-4a9e-a1f4-ba59708261d4)