O

Where is the half-scale?

Orestis Konstantinidis(Orestiskon)
posted to: Optimization

Hi, some wonderful tips here.

After finishing the "Blurring at half scale" part, I'm missing the part where we actually use half-scale. Unless I'm missing something obvious, it doesn't look like we set up any of the TextureRects to use half-scale.

If I'm not seeing it, could you point out where the half-scale takes place?

  • Nathan Lovato replied

    You render at half-scale by setting your blur Viewport nodes' resolution to half that of the project. You can go even lower than half for faster processing, although you may start to get visual artifacts.

    The resolution you need on the Viewport nodes depends on the project's window settings. For instance, if your project is set to render at 1280x720, you want to set your two blur views' viewport to render at a resolution of 640x360.

    I hope this clarifies how it's meant to work.

  • O
    Orestis Konstantinidis(Orestiskon) replied

    Hi Nathan,

    do you mean the Viewport nodes or the Viewport containers? If I resize the Viewport nodes, they reset back to full res after reloading the scene. Resizing the containers does work but I have a question:

    1. This is the full res image
    2. This is when reducing the resolution of Blur2
    3. This is when reducing the res of Blur 1 as well


    As you can see the aspect ratio of the texture becomes distorted. This only happens if I reduce the Y size of Blur1. My Window resolution is the default 1024x600. If I set it to 512x300 it becomes like that. If I set it to 512x600 then it preserves the proper aspect ratio.

    Question: Are we supposed to blur only Blur2? Or both and use (Half Res) x (Full Res) on Blur1? Or am I doing something wrong?

    Furthermore, you can see from the screenshots that the scaled up image is pixelated. I expected it to be blurry as described in the tutorial, but it seems it's using Nearest Neighbour by default. I figured out we can use the "Filter" flag in the ViewportTexture of the Presentation Layer to blur it while scaling it up.

    I think the above clarifications would be useful to be mentioned in the tutorial.

  • Nathan Lovato replied

    I'll pass that to François for the details, and update the lesson based on your discussion.

  • Razoric replied

    You can reduce both phase 1 and phase 2 of the blur.

    If you use a TextureRect to show the result, then you can blur both with half scale viewports - so long as the TextureRect that is showing the image takes up the full screen and is set to expand its image.

    If you are using a ViewportContainer to show the result, the one that does the presentation should be full screen and instead use the Stretch Shrink property to halve (or more) the child viewport without having to manually set the resolution manually.

    However, regarding the aspect ratio: if you reduce the size, you need to reduce it following the aspect ratio. If you want a 50% reduction in size, then both the X and Y need to be reduced by half, or else you will run into distortions like in your third image.

    And finally, some pixelization is to be expected; you are working at half scale. If the effect is too unacceptable, however, you can opt to only blur the first phase. Or, yes, make sure Filter is active.

  • O
    Orestis Konstantinidis(Orestiskon) replied

    Hi, thanks again for the replies!

    use the Stretch Shrink property to halve (or more) the child viewport without having to manually set the resolution manually.

    This is the part I was missing, didn't realize it had a built in parameter for that purpose!

    regarding the aspect ratio: if you reduce the size, you need to reduce it following the aspect ratio. If you want a 50% reduction in size, then both the X and Y need to be reduced by half

    So I'm still a bit unclear about this, perhaps I'm doing something wrong. When I use the Stretch Shrink, both X and Y are reduced appropriately. But I still get aspect ratio distortion. Maybe I'm doing something wrong here....

    I'm attaching my project if you'd like to have a look.

  • Nathan Lovato replied

    I'm updating the course right now. Sorry for the reply delay, I missed your message. Please ping me anytime if we don't get back to you within a few business days.

    Testing your project, I can confirm that Stretch Shrink causes a a distortion in your project. Turning it off and manually downscaling the Viewport node's Size property instead does not produce this artifact. To me, this suggests there is a bug in the ViewportContainer node.

    The bug doesn't happen in our demo project, where the base resolution is 1920 x 1080. I wonder if it's the project resolution that makes the difference there.

  • O
    Orestis Konstantinidis(Orestiskon) replied

    Thanks for the update Nathan!

  • R
    Ruben Hillborg(RubbeHill) replied

    Hi Nathan,

    I get more blur in the direction of Blur2 than Blur1, both when using Stretch Shrink and when manually setting the Size of the Viewports. Did you disable Stretch in the ViewportContainers when you tried to manually downscale the Size? If not then maybe you saw the undistorted, full resolution blur without realising it? (Stretch overrides Size when reloading the scene). 

    Also, which demo project are you referring to? My project uses 1920 x 1080 resolution and the blur still gets distorted. It's a bit harder to see compared to Orestis' project, but it's definitely there. :)


  • Razoric replied

    Hiya,

    I checked your project out and figured out the issue, and that's a mistake on our side.

    When SpriteToBlur's viewport comes out of SceneView, it's at full resolution (1024x600). The image that's inside of TextureRect is 1024x600. So a blur of one calculates the UVs travelled as if it was that size, even though the texture rect is half the size.

    But the texture that comes out of Blur1's viewport is half scale, so 512x300, so a blur of 1 affects twice as many samples. So the aspect ratio distortion you are seeing is not actually a distortion, but your blur being twice as strong. If you set Blur2's blur to 0.5, the error goes away and it looks right.

    To use a regular blur amount, we'd need to pass the texture through another viewport that's at full size and then blur it.

    That makes the actual second blur act on a 1024x600 texture, and so every UV travelled is the same number of pixels as the first time.

    Or just make the second blur half as strong as the first. That'd be easier.

    Sorry for missing that and leading to this confusion. I'll update the article to mention this issue.

    1 love