Search Unity

Depth Mask Shader Issues with iPhone

Discussion in 'Shaders' started by UVRadiation, Nov 26, 2008.

  1. UVRadiation

    UVRadiation

    Joined:
    Jul 21, 2008
    Posts:
    183
    The depth mask shader from the wiki dosen't work on the iPhone , it has no effect on the output (altough it does work inside the editor even in iPhone graphic emulation).
    can anyone help me fix it?

    Code (csharp):
    1. Shader "DepthMask"
    2. {
    3.     SubShader
    4.     {
    5.         // Turn off lighting, because it's expensive and the thing is supposed to be
    6.         // invisible anyway.
    7.  
    8.         Lighting Off
    9.  
    10.         // Draw into the depth buffer in the usual way.  This is probably the default,
    11.         // but it doesn't hurt to be explicit.
    12.  
    13.         ZTest LEqual
    14.         ZWrite On
    15.  
    16.         // Don't draw the RGB colour channels, just the alpha channel.  This means
    17.         // that nothing visible is drawn.  Ideally, I would have liked to set ColorMask
    18.         // to draw nothing at all, but it doesn't seem to be possible to say anything
    19.         // like ColorMask None.
    20.  
    21.         ColorMask A
    22.  
    23.         // Do nothing specific in the pass:
    24.  
    25.         Pass {}
    26.     }
    27. }
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I want to use this too. Any help?
     
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I think that it's behaving inconsistently because it's queue value equals geometry. Try this shader:


    Code (csharp):
    1. Shader "Depth Mask" {
    2.     SubShader {
    3.         Tags { "Queue" = "Background" }
    4.         ColorMask A
    5.         Pass { }
    6.     }
    7. }
     
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I got it working. :D

    The problem is not with the DepthMask shader, although it can be simplified to this (note the zero instead of A):

    Code (csharp):
    1. Shader "Masked/Mask" {
    2.     SubShader {
    3.         Tags { "Queue" = "Geometry+10" }
    4.         ColorMask 0
    5.         Pass { }
    6.     }
    7. }
    The problem is that the Diffuse shader doesn't work on the iPhone. (It falls back to the VertexLit shader.) So, I just cut and pasted some code from the VertexLit shader, and came up with this, which, when applied to the plane (water), works great!

    Code (csharp):
    1. Shader "Vertexy" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _SpecColor ("Spec Color", Color) = (1,1,1,1)
    5.         _Emission ("Emmisive Color", Color) = (0,0,0,0)
    6.         _Shininess ("Shininess", Range (0.01, 1)) = 0.7
    7.         _MainTex ("Base (RGB)", 2D) = "white" {}
    8.     }
    9.  
    10.     SubShader {
    11.         Tags {"Queue" = "Geometry+20" }
    12.         Pass {
    13.             Material
    14.             {
    15.                 Diffuse [_Color]
    16.                 Ambient [_Color]
    17.                 Shininess [_Shininess]
    18.                 Specular [_SpecColor]
    19.                 Emission [_Emission]
    20.             }
    21.             Lighting On
    22.             SeparateSpecular On
    23.             SetTexture [_MainTex]
    24.                 {Combine texture * primary DOUBLE, texture * primary}
    25.         }
    26.     }
    27. }
    I bet that could be improved upon quite easily by someone who really knows what they're doing. :wink: