Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

[SOLVED] Portal Shader Not Masking on iOS

Discussion in 'Shaders' started by unitynoob24, Jun 8, 2021.

  1. unitynoob24

    unitynoob24

    Joined:
    Dec 27, 2014
    Posts:
    398
    Hey guys!

    I am currently working on a portal driven AR experience. Basically doorways appear and reveal a world from within. Outside of the door you can see into the door way and the stuff in the world. And once you enter the door everything in the world appears.

    I am doing this using two shaders. One is a shader for all of the objects inside of the portal, and the other is a mask shader which I apply to the actual doorway itself.

    I have everything working in the editor on Windows and Mac. I also have it running as expected on Android! But when I take it over to iOS it appears as though my portal shader is no longer masking. The objects still hide/show based on if I walk into the door way, but I can no longer view objects through the doorway if I am outside of it on iOS only.

    Here is the shader that I am using on the doorway
    Code (csharp):
    1.  
    2. Shader "Custom/Portals/Portal"
    3. {
    4.    SubShader
    5.    {
    6.        Tags { "RenderType"="Opaque" }
    7.        LOD 100
    8.        Zwrite Off
    9.        ColorMask 0
    10.        Cull off
    11.  
    12.        Pass
    13.        {
    14.            Stencil{
    15.                Ref 1
    16.                Comp always
    17.                Pass replace
    18.            }
    19.  
    20.            CGPROGRAM
    21.            #pragma vertex vert
    22.            #pragma fragment frag
    23.          
    24.            #include "UnityCG.cginc"
    25.                    struct appdata
    26.            {
    27.                float4 vertex : POSITION;
    28.            };
    29.  
    30.            struct v2f
    31.            {
    32.                float4 vertex : SV_POSITION;
    33.            };
    34.  
    35.            v2f vert(appdata v)
    36.            {
    37.                v2f o;
    38.                o.vertex = UnityObjectToClipPos(v.vertex);
    39.                return o;
    40.            }
    41.  
    42.            fixed4 frag(v2f i) : SV_Target
    43.            {
    44.                return fixed4(0.0, 0.0, 0.0, 0.0);
    45.            }
    46.            ENDCG
    47.        }
    48.    }
    49. }
    50.  
    Appreciate you taking the time to read this! Please let me know if anything stands out to you! :) Thanks again!

    EDIT: I solved this by changing the Render Queue of this to 1999. The stuff inside of the portal uses a Render Queue of 2000. For some reason iOS was having an issue with them both being 2000, but Android wasn't. Working great on all platforms now!
     
    Last edited: Jun 9, 2021