Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug Chaotic UI-Default.shader

Discussion in 'UGUI & TextMesh Pro' started by zhuangqin, Mar 31, 2021.

  1. zhuangqin

    zhuangqin

    Joined:
    Sep 9, 2019
    Posts:
    1
    The problems listed below are related to Unity 2019, 2020, 2021. I can't believe such a mess can survive for so long time.

    Problem 1:
    The maskUV variable in vertex shader is calculated but NEVER usued. Do you guys expect to rely on complier optimization?

    Problem 2:
    The pixelSize variable measures pixel size in clip-space which can be calculated on CPU only once. Why bother doing it thousands of times on GPU?

    Problem 3:
    The zw components of the output mask variable in vertex shader has nothing to do with the vertex attributes. What's the reason for calculating it in vertex shader instead of passing it in as a uniform?

    Code (csharp):
    1.            
    2. v2f vert(appdata_t v)
    3. {
    4.     v2f OUT;
    5.  
    6.     // Part of the source code is omitted here.
    7.  
    8.     float4 vPosition = UnityObjectToClipPos(v.vertex);
    9.     // Problem 2
    10.     float2 pixelSize = vPosition.w;
    11.     pixelSize /= float2(1, 1) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy));
    12.  
    13.     float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
    14.  
    15.     // Problem 1
    16.     float2 maskUV = (v.vertex.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy);
    17.  
    18.     OUT.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
    19.  
    20.     // Problem 3
    21.     OUT.mask = half4(v.vertex.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy)));
    22.  
    23.     // Part of the source code is omitted here.
    24. }
    25.  
     
    Last edited: Mar 31, 2021