Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework content scale to provide more options, add integer scaling #63206

Closed
wants to merge 1 commit into from

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Jul 19, 2022

I need help to finish this feature. If you want to see this for 4.0, please lend a hand 🙂

cc @Yukitty, @starry-abyss

  • Add content stretch modes Fractional (default), Integer and Hybrid.

    • All modes work with any stretch mode and aspect.
    • Fractional behaves as Godot currently does when scaling viewports. Pixel art will only look good when the window is scaled at an integer multiple of the original size.
    • Integer enforces an integer scale for the final display (rounded down from the automatically computed fractional scale). This provides crisp pixel art appearance.
      • Black bars may be displayed on all sides when using the viewport stretch mode. When using the canvas_items stretch mode, no black bars are displayed (unless the stretch aspect requires it), but the game's viewable area will change in 2D.
    • (Not implemented yet): Hybrid enforces an integer scale on the internal rendering resolution (rounding up), but the viewport will be stretched down to the final display with linear filtering. This provides good pixel art appearance, though not as crisp as the Integer mode. This is known as Sharp Bilinear in some other apps, though I think we should go for a shader-less approach.
  • Tweak project setting for stretch scale to allow values as low as 0.5 (values below 1 are valid, and can be useful for UI testing purposes).

Testing project: test_stretch_master.zip

TODO

  • Make UI anchors work properly when using integer scaling mode.
  • Implement hybrid scaling mode.

This closes godotengine/godot-proposals#1666.

- Add content stretch modes Fractional (default), Integer and Hybrid.
  - All modes with with any stretch mode and aspect.
  - Fractional behaves as Godot currently does when scaling viewports.
    Pixel art will only look good when the window is scaled at multiples
    of the original size.
  - Integer enforces an integer scale for the final display (rounded down
    from the automatically computed fractional scale). Black bars may be
    displayed on all sides when using the `viewport` stretch mode.
    This provides crisp pixel art appearance.
  - Hybrid enforces an integer scale on the internal rendering resolution,
    but the viewport will be stretched down to the final display with
    linear filtering. This provides good pixel art appearance, though
    not as crisp as the Integer mode.

- Tweak project setting for stretch scale to allow values as low as 0.5
  (values below 1 are valid, and can be useful for UI testing purposes).

TODO:

- Implement hybrid filtering mode.
@starry-abyss
Copy link
Contributor

I've just attached a minimal hybrid scaling project for Godot 3 implemented in nodes: godotengine/godot-proposals#1666 (comment)

Hope it helps!

@starry-abyss
Copy link
Contributor

starry-abyss commented Aug 25, 2022

Maybe I don't fully understand how to use this, but I don't see what I expect to see with integer scaling. When I resize the window, the new integer scale isn't automatically chosen. Instead, there is a smooth fractional scaling.

Ideally I'd like to have 2 approaches:

  1. the default one with fixed game size, bars on sides and automatic scale calculation to fit all the scene with max possible zoom while staying integer.
    Example 1: if game size is 400x300 and window size is 700x600, then scale is 1, because for a scale of 2 one needs 800 or more window pixels horizontally. So there would be 150 pixels bars on each side around the game scene.
    Example 2: if game size is 400x300 and window size is 1500x1000, then scale is 3, with 150 pixels bars on the left and right, and 50 pixels bars on top and bottom.
  2. a special case for some games: imagine a FPS or RTS style 3D game, where the amount of what you can see depends on the aspect ratio of the window (there are no bars on sides). Then replace graphics with 2D pixel art and add integer scaling on top. So instead of bars you get more area of view. And to balance scale factor depending on resolution and aspect ratio, I expect a way to turn off the stock scale calculator from approach 1, to calculate the desired integer ratio in the script on window resize event and then be able to set it in the engine.

@dkaste
Copy link
Contributor

dkaste commented Oct 27, 2022

Is there a reason why the content scale feature is implemented on Window instead of Viewport?

I have a project that uses viewports to contain multiple game instances in the same window. It would be nice to be able to scale the canvas items (i.e. GUI) in each viewport instead of globally on the window.

@Calinou
Copy link
Member Author

Calinou commented Apr 7, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a project setting to force an integer scale for window stretch
4 participants