title: Unity shader warning when not adding _Stencil properties
body: <p>I'm writing a custom shader for Unity 2019.3.13f1 that is just a simple UI gradient. This shader does not (need to) do anything with the stencil buffer, so I set the Stencil to always pass statically:</p>
  <pre><code>Stencil
  {
      Ref 0
      Comp Equal
      Pass Keep
  }
  </code></pre>
  <p>However doing this will throw the warning</p>
  <blockquote>
  <p>Material SomeGradient doesn't have _Stencil property</p>
  </blockquote>
  <p>So I add a _Stencil property (despite it never going to be used, and I don't want others to be able to change the stencil buffer from the editor either)</p>
  <pre><code>[HideInInspector] _Stencil(&quot;Stencil ID&quot;, Float) = 0
  
  Stencil
  {
      Ref [_Stencil]
  }
  </code></pre>
  <p>This gets rid of the warning, but will throw a new warning:</p>
  <blockquote>
  <p>Material SomeGradient doesn't have _StencilOp property</p>
  </blockquote>
  <p>Now repeating the previous step it will keep doing this untill I eventually end up with a bunch of properties I don't want exposed, and never want to change either, just to get rid of some warnings</p>
  <pre><code>[HideInInspector] _Stencil(&quot;Stencil ID&quot;, Float) = 0
  [HideInInspector] _StencilOp(&quot;Stencil Operation&quot;, Float) = 0
  [HideInInspector] _StencilComp(&quot;Stencil Comparison&quot;, Float) = 8
  [HideInInspector] _StencilReadMask(&quot;Stencil Read Mask&quot;, Float) = 255
  [HideInInspector] _StencilWriteMask(&quot;Stencil Write Mask&quot;, Float) = 255
  
  Stencil{
      Ref [_Stencil]
      Pass[_StencilOp]
      Comp[_StencilComp]
      ReadMask[_StencilReadMask]
      WriteMask[_StencilWriteMask]
  }
  </code></pre>
  <p>This bloats my shader code significantly, without adding anything to functionality (over statically setting it without properties). Looking at Unity's <a href="https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/UI/UI-Default.shader" rel="nofollow noreferrer"><code>UI-Default</code></a> shader they have also added these properties properties explicitly (along with <code>_ColorMask</code> which also throws a warning elsewise).</p>
  <p>The code throwing the warning comes from the <code>\2019.3.13f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\UI\Core\StencilMaterial.cs</code> method <code>Material Add</code>, which seems to get called internally by Unity when adding a Material to the Material property of an Image component.</p>
  <pre class="lang-cs prettyprint-override"><code> /// &lt;summary&gt;
   /// Add a new material using the specified base and stencil ID.
   /// &lt;/summary&gt;
   public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction)
   {
       if ((stencilID &lt;= 0 &amp;&amp; colorWriteMask == ColorWriteMask.All) || baseMat == null)
           return baseMat;
  
       if (!baseMat.HasProperty(&quot;_Stencil&quot;))
       {
           Debug.LogWarning(&quot;Material &quot; + baseMat.name + &quot; doesn't have _Stencil property&quot;, baseMat);
           return baseMat;
       }
       if (!baseMat.HasProperty(&quot;_StencilOp&quot;))
       {
           Debug.LogWarning(&quot;Material &quot; + baseMat.name + &quot; doesn't have _StencilOp property&quot;, baseMat);
           return baseMat;
       }
       if (!baseMat.HasProperty(&quot;_StencilComp&quot;))
       {
           Debug.LogWarning(&quot;Material &quot; + baseMat.name + &quot; doesn't have _StencilComp property&quot;, baseMat);
           return baseMat;
       }
       if (!baseMat.HasProperty(&quot;_StencilReadMask&quot;))
       {
           Debug.LogWarning(&quot;Material &quot; + baseMat.name + &quot; doesn't have _StencilReadMask property&quot;, baseMat);
           return baseMat;
       }
       if (!baseMat.HasProperty(&quot;_StencilWriteMask&quot;))
       {
           Debug.LogWarning(&quot;Material &quot; + baseMat.name + &quot; doesn't have _StencilWriteMask property&quot;, baseMat);
           return baseMat;
       }
       if (!baseMat.HasProperty(&quot;_ColorMask&quot;))
       {
           Debug.LogWarning(&quot;Material &quot; + baseMat.name + &quot; doesn't have _ColorMask property&quot;, baseMat);
           return baseMat;
       }
      //Rest of code
  }
  </code></pre>
  <p>Removing the <code>Stencil{}</code> pass in its entirety will also still throw the warning.</p>
  <p>I looked at the <a href="https://docs.unity3d.com/Manual/SL-Stencil.html" rel="nofollow noreferrer">documentation</a> for Stencil, but I can't seem to find a reason why they want this explicitly added, in the docs examples they don't add the properties explicitly either. So <em>is</em> there a good reason for it that I missed?</p>
  <hr />
  <p>What I also find baffling is that when you create a new Unlit shader (Create&gt;Shader&gt;Unlit Shader) it <em>doesn't</em> throw these warnings, despite not having the stencil properties added explicitly either</p>
  <pre><code>Properties
  {
      _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}
  }
  SubShader
  {
      Tags { &quot;RenderType&quot;=&quot;Opaque&quot; }
      LOD 100
  
      Pass
      {
       //Rest of shader code
      }
  }
  </code></pre>
  <p>Why does this seem to be an exception to the rule?</p>