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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

isn't the multi pass shader unsupported or turned off on ios platform with opengles 2.0 setting?

Discussion in 'Shaders' started by hoafjj234, Apr 13, 2018.

  1. hoafjj234

    hoafjj234

    Joined:
    Feb 5, 2018
    Posts:
    5
    From IOS player setting,unchecking Auto Graphics API,and selecting opengles 2.0 rendering. Instead, only the first pass gets rendered as usual, the second one was never rendered.,
    but without unchecking Auto Graphics API setting. both passes works
    any comments will be much appreciated. thank you!

    Here's my custom shader:
    Code (CSharp):
    1.  
    2.     SubShader
    3.     {
    4.         Tags
    5.         {
    6.             "Queue"="Transparent"
    7.             "IgnoreProjector"="True"
    8.             "RenderType"="Transparent"
    9.             "PreviewType"="Plane"
    10.             "CanUseSpriteAtlas"="True"
    11.         }
    12.  
    13.         // This is based on the code from the Sprite/Default shader
    14.         Pass
    15.         {
    16.             Name "BASE"
    17.  
    18.             Cull Off
    19.             Lighting Off
    20.             ZWrite Off
    21.             Blend SrcAlpha OneMinusSrcAlpha
    22.  
    23.             //Tags{ "LightMode" = "ForwardBase" }
    24.  
    25.             CGPROGRAM
    26.             #pragma vertex vert
    27.             #pragma fragment frag
    28.             #pragma multi_compile DUMMY PIXELSNAP_ON
    29.             #pragma multi_compile_fwdbase
    30.             #include "UnityCG.cginc"
    31.             #include "Lighting.cginc"
    32.  
    33.             struct appdata_t
    34.             {
    35.                 float4 vertex   : POSITION;
    36.                 half4 color        : COLOR;
    37.                 float2 texcoord : TEXCOORD0;
    38.             };
    39.  
    40.             struct v2f
    41.             {
    42.                 float4 vertex   : SV_POSITION;
    43.                 fixed4 color    : COLOR;
    44.                 half2 texcoord  : TEXCOORD0;
    45.             };
    46.          
    47.             fixed4 _Color;
    48.             float4 _MainTex_ST;
    49.             sampler2D _MainTex;
    50.  
    51.          
    52.             v2f vert (appdata_t v)
    53.             {
    54.                 v2f OUT;
    55.                 OUT.vertex = UnityObjectToClipPos(v.vertex);
    56.                 OUT.texcoord = TRANSFORM_TEX (v.texcoord, _MainTex);
    57.  
    58.             #ifdef PIXELSNAP_ON
    59.                 OUT.vertex = UnityPixelSnap (OUT.vertex);
    60.             #endif
    61.  
    62.                 OUT.color = v.color * _Color;
    63.  
    64.                 return OUT;
    65.             }
    66.  
    67.          
    68.             fixed4 frag(v2f IN) : SV_Target
    69.             {
    70.                 fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
    71.  
    72.                 return c;
    73.             }
    74.         ENDCG
    75.         }
    76.  
    77.  
    78.         Pass
    79.         {
    80.             Name "fakelightpass"
    81.  
    82.             Cull Off
    83.             Lighting Off
    84.             ZWrite Off
    85.             Blend One One
    86.  
    87.             //Tags { "LightMode" = "ForwardAdd" }
    88.  
    89.             CGPROGRAM
    90.             #pragma vertex vert
    91.             #pragma fragment frag
    92.             #pragma multi_compile DUMMY PIXELSNAP_ON
    93.             #include "UnityCG.cginc"
    94.             //#include "Lighting.cginc"
    95.  
    96.             struct v2f
    97.             {
    98.                 float4 vertex   : SV_POSITION;
    99.                 float2 texcoord  : TEXCOORD0;
    100.                 half3 lightColorAttenuated    : COLOR;    // Rim light color attenuated with distance
    101.                 half3 lightDir : TEXCOORD1;                // Light direction
    102.                 float3x3 rotation : TEXCOORD2;            // Rotation matrix
    103.             };
    104.  
    105.             float4 _MainTex_ST;
    106.             sampler2D _MainTex;
    107.             float4 _MainTex_TexelSize;
    108.             half4 _Lightpos1;
    109.          
    110.  
    111.             v2f vert(appdata_full v)
    112.             {
    113.                 float _Radius = 0;
    114.                 v2f OUT;
    115.                 OUT.vertex = UnityObjectToClipPos(v.vertex);
    116.                 OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    117.  
    118.     #ifdef PIXELSNAP_ON
    119.                 OUT.vertex = UnityPixelSnap(OUT.vertex);
    120.     #endif
    121.  
    122.                 // Light direction in that vertex
    123.                 //OUT.lightDir = ObjSpaceLightDir(v.vertex);
    124.              
    125.                 float4 worldpos = mul(unity_ObjectToWorld, v.vertex);
    126.              
    127.                 _Lightpos1.z = worldpos.z;
    128.                 OUT.lightDir = _Lightpos1.xyz  - worldpos.xyz;
    129.  
    130.                 // Calculate the rotation matrix per-vertex instead of per-pixel in fragment shader later on
    131.                 // Should not make a difference for small/mid-sized sprites
    132.                 TANGENT_SPACE_ROTATION;
    133.                 OUT.rotation = rotation;
    134.  
    135.                 half distance = length(OUT.lightDir);
    136.                 OUT.lightDir = normalize(OUT.lightDir);
    137.  
    138.                 _Radius = 200 - clamp(distance,0,200);
    139.                 // Light's linear attenuation
    140.                 half atten = distance;
    141.                 OUT.lightColorAttenuated = half3(200,200,_Radius/200) / atten;
    142.  
    143.                 return OUT;
    144.             }
    145.  
    146.  
    147.             fixed4 frag(v2f IN) : SV_Target
    148.             {
    149.                 fixed4 c = tex2D(_MainTex, IN.texcoord);
    150.  
    151.                 if (c.a == 0)
    152.                 {
    153.                     discard;
    154.                 }
    155.              
    156.                 // We are adding in this pass, so defaults to black
    157.                 c = fixed4(0, 0, 0, 0);
    158.  
    159.                 fixed2 rim = fixed2(0, 0);
    160.                 fixed addedAlpha = 0;
    161.  
    162.                 float2 aux = _MainTex_TexelSize.xy;
    163.                 fixed value = 0;
    164.                 aux.y = 0;
    165.                 value = tex2D(_MainTex, IN.texcoord + aux).a;
    166.                 rim.x -= value;
    167.                 addedAlpha += value;
    168.                 value = tex2D(_MainTex, IN.texcoord - aux).a;
    169.                 rim.x += value;
    170.                 addedAlpha += value;
    171.  
    172.                 aux = _MainTex_TexelSize.xy;
    173.                 aux.x = 0;
    174.                 value = tex2D(_MainTex, IN.texcoord + aux).a;
    175.                 rim.y -= value;
    176.                 addedAlpha += value;
    177.                 value = tex2D(_MainTex, IN.texcoord - aux).a;
    178.                 rim.y += value;
    179.                 addedAlpha += value;
    180.  
    181.              
    182.                 //rim*= 0.8f;
    183.              
    184.                 //rim *= addedAlpha / 4;
    185.                 // Check if any of the neighbours is transparent
    186.                 if (addedAlpha < 4)
    187.                 {
    188.                     // Transform both light's direction and rim's direction to the same space (tangent space)
    189.                     fixed3 light = mul(IN.rotation, IN.lightDir);
    190.                     c.rgb = IN.lightColorAttenuated.rrr * saturate(dot(light.xy, rim.xy)) ;
    191.                  
    192.                 }
    193.              
    194.              
    195.                 //float center = tex2D(_MainTex, IN.texcoord).a;
    196.              
    197.                 c.rgb *= addedAlpha / 4 * IN.lightColorAttenuated.b;
    198.              
    199.          
    200.              
    201.                 //c.a = 1.0f - addedAlpha/4;
    202.  
    203.                 return c;
    204.             }
    205.             ENDCG
    206.         }
    207.  
    208.     }
     
    Last edited: Apr 13, 2018
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,874
  3. hoafjj234

    hoafjj234

    Joined:
    Feb 5, 2018
    Posts:
    5
    thank your reply.but i think the multi-pass is to render something several times, it's related to rendering engine architecture, not about gpu model.maybe new feature of rendering API.
     
  4. hoafjj234

    hoafjj234

    Joined:
    Feb 5, 2018
    Posts:
    5
    I'm really confused right now. To figure it out why.if i would have tested the following shader with only gles 2.0 enabled
    two passes were both rendered on mobile device. i'm in question whether the shaderlab combine two passes into one if it doesn't support?

    Code (CSharp):
    1. SubShader {
    2.     Tags { "RenderType"="Opaque" }
    3.     LOD 100
    4.  
    5.     // Non-lightmapped
    6.     Pass {
    7.         Tags { "LightMode" = "Vertex" }
    8.         Lighting Off
    9.         SetTexture [_MainTex] { combine texture }
    10.     }
    11.  
    12.     // Lightmapped, encoded as dLDR
    13.     Pass {
    14.         //Tags { "LightMode" = "VertexLM" }
    15.  
    16.         Lighting Off
    17.  
    18.         SetTexture [_MainTex] {
    19.             constantColor (1,0,0,1)
    20.             combine texture * constant
    21.         }
    22.     }
    23.  
    24. }
     
    Last edited: Apr 14, 2018