Scaled Viewport renders unsharp! How can I fix this without changing the vieports size manually?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Olaf007

Heyo,
recently I wanted to add a camera shake to my project so I added a Camera2d-Node but in this way my GUI does move too because the camera has impact on all nodes in the current scene.
This is why I moved the Game-Scene into one viewport (+container) and the menu into another viewport. This works perfectly at first, but as soon as I scale the window, the viewport does not.
What I mean:
I set the display/window/stretch/aspekt setting on keep so all nodes are automatically scaled and black corners appear if the window-relation changes, so the format keeps the same. The problem: the viewport is streched on a bigger amount of pixels but still renders the old format. In this way it seems unsharp.
When I do not implement any viewport at all the keep-setting works perfectly. Is there any setting for viewports that can handle the pixel stretch like the main scene does?
Mhm, I hope you see the problem,
thank you,
Olaf :wink:

:bust_in_silhouette: Reply From: MrMrBlackDragon

If you scale a viewport up it will stay in its original resolution but is just bigger. The resolution of the viewport will stay the same if you scale up. It is like a photo on your smartphone, the more you zoom the more it will get unsharp. That si how a viewport behave.
If you could send some pictures of your work I might can help you :slight_smile:

Okay thanks, I recently published my Game in a GameJam :wink: → “Bounty Rain”

So what I had first:
before.jpg - Google Drive
→ The scene is rendered on the main viewport as the menu too.
→ Edges of the sprite-textures are very sharp and automatically change their resolution when the window size changes. I cannot manually change the resolution because the game runs in the Browser, so there is no OS.window_size - that is why I use the strech aspect project setting.
→ I cannot implement a Camerashake because it would shake the GUI too.

This is how I thaught it would solve my problem:
after.jpg - Google Drive
→ Scene is now in a extra Viewport, so the shaking camera does not impact on the menu - works perfectly!
→ Sadly, as you can see, the sprite textures are unsharp - because the view in the editor is smaller than the actual resolution of the viewport. (As you say, the viewport is scaled)
In game, this problem gets even worse if you set the window size on a way bigger amount then the viewport resolution. Ofcourse this scales the viewport, so it is unsharp.
But how can I solve the problem? I cannot reset the viewport.rect_size in code because I have no OS.window_size when I run the Game in the Browser! :slight_smile:

Hope you have an idea? :)) And thanks.

Olaf007 | 2020-01-23 08:36

Oh you speak german as well? :slight_smile:
Einen ähnliche Viewporteffekt erziehlst Du, indem einfach statt der “Gameport”-Node eine Controlnode verwendest und dann bei “Clip to Content” ein Häckchen setzt. Siehe hier
Dann wird nur innerhalb der Contronode ein Bild gerendert und die Auflösung verschlechtert sich auch bei einem größeren Bildschirm nicht. Wenn Du “Mouse Filter” von “Stop” auf “Pass” oder “Ignore” stellst, sind weiterhin Interaktionen inerhalb der Controlnodes (z.B Klicks auf Buttons) möglich.Weiteres findest Du hier. Falls Du nur eine Kamera nutzt, ist das der einfachste Weg.

MrMrBlackDragon | 2020-01-27 17:32

Yup ^^
Okay, das ist ne nette Funktion, die ich noch nicht kannte. :slight_smile:
Aber das Problem löst es nicht - die Kamera lässt immernoch das gesamte Bild erzittern, obwohl die GUI nicht in diesem Controlnode enthalten sind.

Olaf007 | 2020-01-27 19:58

Du kannst auch die ganze GUI an ein “Canvas Layer” hängen und dann den “Layer”-Wert auf 1 stellen. Dann ist die GUI über dem Spiel und verändert sich nicht, falls sich die Kamera bewegt. Vielleicht hilft Dir das weiter? :slight_smile:

MrMrBlackDragon | 2020-01-28 21:02

Danke, das hat jetzt tatsächlich das Problem gelöst! :slight_smile:
Ich formuliere es nochmal auf Englisch, falls jemand anderes das Problem hat.
Vielen lieben dankööö! :))

Olaf007 | 2020-01-28 21:21

:bust_in_silhouette: Reply From: Olaf007

Yay, MrMrBlackDragon finally solved the problem:
I had to make the GUI a child of a different canvas layer - in this way the GUI is not shaken and I do not have to use the Viewport.
Thanks!

Errr… This should have been posted as a comment to the single answer to your question (the one from MrMrBlackDragon). Additionally, you should have selected his answer as Best Answer. Doing so will provide him with points for his volunteer efforts…

jgodfrey | 2020-01-28 21:39

Oh, I did not know that.
I wanted to sum up the solution because we evalutated the problem in German.

Olaf007 | 2020-01-28 21:45

Sure, understood. And, honestly, I’m not sure what’s the best way of handling a case like this one. I just wanted to point it out for future.

jgodfrey | 2020-01-28 22:09