Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Custom shader not working in Android - GLSL link error: The number of vertex shader storage blocks

Discussion in 'Shaders' started by jmgc92, Jul 29, 2022.

  1. jmgc92

    jmgc92

    Joined:
    Apr 3, 2016
    Posts:
    9
    Hello, I am having problems when displaying an image that has a transparency shader applied in android.

    The shader in the editor looks correct and works without any problem, but when we compile the project for android and execute it, the shader stops working and the image cannot be seen on mobile, maybe the shader crash and now the image is fully transparent.

    Error logs from my device:


    Code (CSharp):
    1. 2022-07-28 10:39:55.665 24694-24853/app.dev E/SchedPolicy: set_timerslack_ns write failed: Operation not permitted
    2. 2022-07-28 10:39:56.481 24694-25852/app.dev I/Adjust: Buffered event ‘GameArea’
    3. 2022-07-28 10:39:56.774 24694-24979/app.dev E/Unity: -------- GLSL link error:  The number of vertex shader storage blocks (1) is greater than the maximum number allowed (0).
    4. 2022-07-28 10:39:56.774 24694-24979/app.dev D/Unity: Note: Creation of internal variant of shader ‘Particles/Standard Unlit’ failed.
    After reading many threads on the forum, it seems my bug is related to this issue: https://issuetracker.unity3d.com/issues/android-a-glsl-error-occurs-when-using-the-unity-particle- system

    For which I have updated my version of unity to 2020.3.37f1, however after testing the error persists.

    My suspicion is that the 'Particles/Standard Unlit' shader is failing and failing doesn't allow my custom shader to work properly, but that's just a guess.

    I attach the source code of my shader:


    Code (CSharp):
    1. Shader "Unlit/PillsFadeOutMask"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         _StartEffectPoint ("StartEffectPoint", float) = 0
    7.         _EndEffectPoint ("EndEffectPoint", float) = 0
    8.     }
    9.     SubShader
    10.     {
    11.         Tags {"Queue"="Transparent" "IgnoreProjector"="True"}
    12.         ZWrite Off
    13.         Blend SrcAlpha OneMinusSrcAlpha
    14.         LOD 100
    15.  
    16.         Pass
    17.         {
    18.             CGPROGRAM
    19.             #pragma vertex vert
    20.             #pragma fragment frag
    21.  
    22.             #include "UnityCG.cginc"
    23.          
    24.             uniform float _StartEffectPoint;
    25.             uniform float _EndEffectPoint;
    26.  
    27.             struct appdata
    28.             {
    29.                 float4 vertex : POSITION;
    30.                 float2 uv : TEXCOORD0;
    31.             };
    32.  
    33.             struct v2f
    34.             {
    35.                 float2 uv : TEXCOORD0;
    36.                 float4 vertex : SV_POSITION;
    37.                 float4 worldSpacePos : TEXCOORD1;
    38.             };
    39.  
    40.             sampler2D _MainTex;
    41.             float4 _MainTex_ST;
    42.  
    43.             v2f vert (appdata v)
    44.             {
    45.                 v2f o;
    46.                 o.vertex = UnityObjectToClipPos(v.vertex);
    47.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    48.  
    49.                 o.worldSpacePos = mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1));
    50.                 return o;
    51.             }
    52.  
    53.             float when_lt(float x, float y) {
    54.               return max(sign(y - x), 0.0);
    55.             }
    56.  
    57.             float when_gt(float x, float y) {
    58.               return max(sign(x - y), 0.0);
    59.             }
    60.          
    61.             float when_neq(float x, float y) {
    62.               return abs(sign(x - y));
    63.             }
    64.  
    65.             float when_eq(float x, float y) {
    66.               return 1.0 - abs(sign(x - y));
    67.             }
    68.  
    69.             fixed4 frag (v2f i) : SV_Target
    70.             {
    71.                 fixed4 col = tex2D(_MainTex, i.uv);
    72.                 float inside_range = when_lt(i.worldSpacePos.x,_StartEffectPoint) * when_gt(i.worldSpacePos.x, _EndEffectPoint);
    73.                 float out_range = when_eq(inside_range,0) * when_lt(i.worldSpacePos.x, _EndEffectPoint);
    74.                 float distanceBetweenBase = abs(distance(_EndEffectPoint, _StartEffectPoint));
    75.                 float distanceBetweenEnd = abs(distance(_EndEffectPoint, i.worldSpacePos.x));
    76.                 float realDistance = distanceBetweenEnd / distanceBetweenBase;
    77.                 float new_alpha = lerp(0, 1, realDistance) * inside_range * when_neq(col.a,0);
    78.                 col.a = (col.a * when_eq(new_alpha,0) + new_alpha) * when_eq(out_range,0);
    79.                 return col;
    80.             }
    81.             ENDCG
    82.         }
    83.     }
    84. }
    85.  
    Update: I have tested this in iOS im having the same problem without a warning on the debugger.

    I would appreciate any help you could give me.
     
    Last edited: Jul 29, 2022
  2. jmgc92

    jmgc92

    Joined:
    Apr 3, 2016
    Posts:
    9
    I have also try this shader and is not working:


    Code (CSharp):
    1. Shader "Unlit/PillsFadeOutMask"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         _StartEffectPoint ("StartEffectPoint", float) = 0
    7.         _EndEffectPoint ("EndEffectPoint", float) = 0
    8.     }
    9.     SubShader
    10.     {
    11.         Tags {"Queue"="Transparent" "IgnoreProjector"="True"}
    12.         ZWrite Off
    13.         Blend SrcAlpha OneMinusSrcAlpha
    14.         LOD 100
    15.         Pass
    16.         {
    17.             CGPROGRAM
    18.             #pragma vertex vert
    19.             #pragma fragment frag
    20.             #include "UnityCG.cginc"
    21.        
    22.             uniform float _StartEffectPoint;
    23.             uniform float _EndEffectPoint;
    24.             struct appdata
    25.             {
    26.                 float4 vertex : POSITION;
    27.                 float2 uv : TEXCOORD0;
    28.             };
    29.             struct v2f
    30.             {
    31.                 float2 uv : TEXCOORD0;
    32.                 float4 vertex : SV_POSITION;
    33.                 float4 worldSpacePos : TEXCOORD1;
    34.             };
    35.             sampler2D _MainTex;
    36.             float4 _MainTex_ST;
    37.             v2f vert (appdata v)
    38.             {
    39.                 v2f o;
    40.                 o.vertex = UnityObjectToClipPos(v.vertex);
    41.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    42.                 o.worldSpacePos = mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1));
    43.                 return o;
    44.             }
    45.             float when_lt(float x, float y) {
    46.               return max(sign(y - x), 0.0);
    47.             }
    48.             float when_gt(float x, float y) {
    49.               return max(sign(x - y), 0.0);
    50.             }
    51.        
    52.             float when_neq(float x, float y) {
    53.               return abs(sign(x - y));
    54.             }
    55.             float when_eq(float x, float y) {
    56.               return 1.0 - abs(sign(x - y));
    57.             }
    58.             fixed4 frag (v2f i) : SV_Target
    59.             {
    60.                 fixed4 col = tex2D(_MainTex, i.uv);
    61.                 return col;
    62.             }
    63.             ENDCG
    64.         }
    65.     }
    66. }