[Solved] Pixel perfect upscaling

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
simba975
Newbie
Posts: 22
Joined: Sun Jul 23, 2023 12:05 pm
Contact:

[Solved] Pixel perfect upscaling

#1 Post by simba975 »

My game uses a 640x480 resolution. Problem is, it is a resolution that if you have a standard 1080 screen, it will be in a tiny window, and if you go on fullscreen, it will be not pixel perfect, meaning it will have some sort of antialiasing which doesn't really good great. I wonder how I could Implement a option to make it run in a 2 times bigger window and/or a fullscreen version that makes the image 2 times as big and puts black bars.

I got the idea from the game "Needy Girl Overdose" which does the same, but it runs in unity.
Last edited by simba975 on Sat Feb 10, 2024 5:36 am, edited 1 time in total.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1011
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Pixel perfect upscaling

#2 Post by m_from_space »

simba975 wrote: Sat Nov 04, 2023 1:01 amI wonder how I could Implement a option to make it run in a 2 times bigger window and/or a fullscreen version that makes the image 2 times as big and puts black bars.
Renpy supports all of this, black bars are added if the window/full screen ratio doesn't match the game's ratio.

I'm not sure what you are asking here, because if you increase the size of the window, the images will increase as well. If you talk about upscaling low resolution images to 2x bigger images with same quality, then remember that's not possible. Unless you like upscaled images using A.I., which certainly won't look super great.

What is not "pixel perfect" in your case? If you use absolut positions inside the screen, then things should work. If you use relative positions like "xpos 0.5" or "xalign 0.2", then rounding errors will occur I guess.

User avatar
simba975
Newbie
Posts: 22
Joined: Sun Jul 23, 2023 12:05 pm
Contact:

Re: Pixel perfect upscaling

#3 Post by simba975 »

I mean "pixel perfect" in the pixel-art kind of way. I want to upscale in full intervals like 2 because that way each part of the image that previously used 1 pixel now will use 4, making it so the screen doesn't has to go with making the intermediate of 2 pixels. The problem is that 480 and 1080 are in a proportion of 1:2.25, which means that It can't be pixel perfect, and for example if there is an image that has completely white and completely black lines, if you upscale it a resolution that has a proportion with decimals, it will result in the pixels between the black and white lines to be grey, because a pixel is between two colors and instead of picking one of them makes an average of the two. That's why I want to make a preset of "x2 size", so the screen doesn't average between two pixels and it manages to get a "pixel perfect" look.
In this case if I wanted It to look correctly, the window size should be exactly 1280x960, no more no less.

Edit: investigating, it seems like "config.physical_width" and "config.physical_high" is exactly what I need, but I can't seem to make it work. I tried with "define config.physical_width = 1280" and "init python: config.physical_width = 1280" but it desn't do anything.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1011
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Pixel perfect upscaling

#4 Post by m_from_space »

simba975 wrote: Sat Nov 04, 2023 4:20 am I mean "pixel perfect" in the pixel-art kind of way. I want to upscale in full intervals like 2 because that way each part of the image that previously used 1 pixel now will use 4...
Ah I see. So it seem you just might want to set the following. This defines the upscaling method.

Code: Select all

define config.nearest_neighbor = True
P.S. There is also one method that allows fonts to be rendered like you digitally zoom into them, instead of having a smooth font all the time. But I forgot which config variable that is.

User avatar
simba975
Newbie
Posts: 22
Joined: Sun Jul 23, 2023 12:05 pm
Contact:

Re: Pixel perfect upscaling

#5 Post by simba975 »

Thank you, define config.nearest_neighbor = True works really well, tho I would still want to know if I can do a x2 upscale since nearest neighbor can always get the exact proportion of things wrong, I will keep searching.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1011
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Pixel perfect upscaling

#6 Post by m_from_space »

simba975 wrote: Sat Nov 04, 2023 12:44 pm Thank you, define config.nearest_neighbor = True works really well, tho I would still want to know if I can do a x2 upscale since nearest neighbor can always get the exact proportion of things wrong, I will keep searching.
You can change the screen size yourself using the preferences while running Renpy.

Code: Select all

$ renpy.set_physical_size((1280, 960))
In my project I change the size to the default value if the player accidentally changed it (and is not in fullscreen), when loading a game:

Code: Select all

label after_load:
    if not preferences.fullscreen and renpy.get_physical_size() != (1280, 720):
        $ renpy.set_physical_size((1280, 720))

User avatar
simba975
Newbie
Posts: 22
Joined: Sun Jul 23, 2023 12:05 pm
Contact:

Re: Pixel perfect upscaling

#7 Post by simba975 »

Yes I found that, I also found this:

Code: Select all

textbutton _("x2") action Preference("display", 2.0)
which I put on my preferences so people can manually select it.

Now I just wonder tho, is there any way I can get something like this but running fullscreen instead of windowed? I mean the same size (1280, 960) but with the black bars that come with fullscreen, so that players don't get distracted with things in the background while enjoying a pixel-perfect experience.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Pixel perfect upscaling

#8 Post by PyTom »

Take a look at config.adjust_view_size. There's an example there in the documentation of how to force integer scaling, which can ensure that your game window is an integer multiple of the game size. (So it could be 1x, 2x, 3x, etc, but not between.)

Ren'Py will add a black (by default) border around the game to enforce this.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot]