mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
1.97k stars 261 forks source link

Masked image disapear on resolution change #106

Closed plyoung closed 3 years ago

plyoung commented 3 years ago

The masked image disappears when you change the resolution in-game. Tested a Windows build.

Create a build of the attached project. You will see a green rectangle masked by a white circle. Change resolution and observe the green image is gone.

TEST.zip

mob-sakai commented 3 years ago

@plyoung The issue is reproduced in my environment.

In window mode: Working fine. In full-screen mode: Green rectangle is disappeared.

In full screen, I noticed that SoftMaskable was not refreshing on changed the screen resolution.

mob-sakai commented 3 years ago

@plyoung Workaround: It worked correctly when Desampling Rate (downsampling rate) was set to None.

image

mob-sakai commented 3 years ago

@plyoung Try to use 1.0.0-preview.13

ghost commented 1 year ago

Not fixed in latest version, even if Desampling Rate set to None

Luanrobs commented 1 year ago

@mob-sakai

Hello, after spending some time examining the code, I was able to devise a solution. Please make the following modification to the GetDownSamplingSize function within SoftMask.cs.

private static void GetDownSamplingSize(DownSamplingRate rate, out int w, out int h)
        {
            w = Screen.currentResolution.width;
            h = Screen.currentResolution.height;

            if (rate == DownSamplingRate.None)
                return;

            var aspect = (float) w / h;
            if (w < h)
            {
                h = Mathf.ClosestPowerOfTwo(h / (int) rate);
                w = Mathf.CeilToInt(h * aspect);
            }
            else
            {
                w = Mathf.ClosestPowerOfTwo(w / (int) rate);
                h = Mathf.CeilToInt(w / aspect);
            }
        }
mob-sakai commented 1 year ago

Thanks a lot!

mob-sakai commented 1 year ago

@Luanrobs Are the differences you expect to see as follows?

@@ -663,12 +663,6 @@ namespace Coffee.UISoftMask
             }
             else
 #endif
-            if (Screen.fullScreenMode == FullScreenMode.Windowed)
-            {
-                w = Screen.width;
-                h = Screen.height;
-            }
-            else
             {
                 w = Screen.currentResolution.width;
                 h = Screen.currentResolution.height;
Luanrobs commented 1 year ago

That's it, by removing those checks I was able to solve the problem I was having here. I'm not sure if this could end up affecting something else, I would have to test it.

vgabler commented 1 year ago

This issue is still occurring today. I'm using Unity 2020.3.18f1, softmask v1.0.2

This code did solve the issue for me! Thanks, @Luanrobs !

@mob-sakai

Hello, after spending some time examining the code, I was able to devise a solution. Please make the following modification to the GetDownSamplingSize function within SoftMask.cs.

private static void GetDownSamplingSize(DownSamplingRate rate, out int w, out int h)
        {
            w = Screen.currentResolution.width;
            h = Screen.currentResolution.height;

            if (rate == DownSamplingRate.None)
                return;

            var aspect = (float) w / h;
            if (w < h)
            {
                h = Mathf.ClosestPowerOfTwo(h / (int) rate);
                w = Mathf.CeilToInt(h * aspect);
            }
            else
            {
                w = Mathf.ClosestPowerOfTwo(w / (int) rate);
                h = Mathf.CeilToInt(w / aspect);
            }
        }