Game resolution, render target, 4K, DefOS (Again)

Similar questions were asked several times, but i couldn’t find right answers for my case and i just want to clarify something.

What i want
I want to implement resolution settings for my game. I am already using DefOS for fullscreen, so it also has function to set desired resolution. Basically i want always have fullscreen window with different “quality”, so players can decide what they want: higher resolution or better performance.

What is happening
I’ve been experimenting for a while and come to some results:
When i set width and height in game settings to 1920x1080 and use defos.set_view_size(0, 0, 1920, 1080) everything looks fine. Fullscreen also set via defos:

This time i set defos.set_view_size(0, 0, 1280,720). Width and height in game.settings 1920x1080

Okay, let’t try 4k resolution. Width and height in game settings to 4096x2160 and defos.set_view_size(0, 0, 4096, 2160)

And width and height in game settings to 4096x2160 and defos.set_view_size(0, 0, 1920, 1080)

If you look at logo, you will see the difference: when both in 4k, logo looks more sharp. Both logos were zoomed on the same level.

And the last one: width and height in game settings to 1920x1080 and defos.set_view_size(0, 0, 4096, 2160)

And width and height in game settings to 1920x1080 and defos.set_view_size(0, 0, 1920, 1080)

You can hardly see any difference in quality, but this probably was influenced by original assets quality.
As i correctly understand there is no way to set width and height in game settings during runtime, so i have to stick with 1920x1080.

What i think i should do
Set width and height in game settings to 1920x1080. Let player select resolution and render it to render target with his resolution and then “downscale” or “upscale” it to final render target with 1920x1080.

Am i thinking right or i miss something? I still do not finally understand defold rendering pipeline.

hello @russelkgd do you use rendercam? I use rendercam and have issues when change the resolution. thanks

1 Like

Hey Elpidoforos. Thanks for your suggestion, i am gonna check it. But at first glance that’s not what am looking for.

This lack of sharpness is likely due to mipmapping taking effect. You can test this by creating a duplicate of the builin sprite material, set the mipmap off, then enabling that material on the sprite.

If you want a viewport that can be resized without the assets appearing to scale at all this is possible to do. I don’t have a 4k monitor so can’t give you insights related to that but @dapetcu21 might know.

Yes. Don’t fiddle with defos for the window size. That won’t get you anywhere.

The solution is as follows:

Create a render target at screen size times a multipler (In Interrogation you can pick between 0.75x, 0.5x, 0.25x).

Restrict your rendering viewport to your render target’s size.

Draw as usual (you shouldn’t really change anything to your projection matrices since the aspect ratio didn’t change, just assume the window’s size as you did before).

Then set your viewport back to 0, 0, screen_width, screen_height.

Now render the render target to a full screen quad.

When the screen is resized, don’t forget to resize the render target as well.

Also, as an optimisation, if the scale factor is 1x, you can, of course, skip the render target and draw directly as usual.

(Believe it or not, this is the recommended solution in Apple’s macOS guidelines too. They’re very against changing the actual resolution of the user’s screen, and I get it, it’s bad UX, which is why I didn’t implement it in DefOS either)

7 Likes

Thanks @dapetcu21 for detailed answer. Gonna try it in couple of days.

3 Likes