Author Topic: UIPanel soft clip with stencil shader not work  (Read 1871 times)

visperc

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
UIPanel soft clip with stencil shader not work
« on: July 29, 2015, 05:53:16 AM »
I use UIPanel and under this panel , I use a sprite with a simple custom stencil shader
 
  1. Shader "Custom/HIdden" {
  2.         Properties {
  3.                 _MainTex ("Base (RGB)", 2D) = "white" {}
  4.         }
  5.         SubShader {
  6.                 Tags { "RenderType"="Opaque" }
  7.                 LOD 200
  8.                
  9.                 Stencil
  10.                 {
  11.                          Ref 1
  12.                          Comp Equal
  13.                 }
  14.                 CGPROGRAM
  15.                 #pragma surface surf Lambert
  16.  
  17.                 sampler2D _MainTex;
  18.  
  19.                 struct Input {
  20.                         float2 uv_MainTex;
  21.                 };
  22.  
  23.                 void surf (Input IN, inout SurfaceOutput o) {
  24.                         half4 c = tex2D (_MainTex, IN.uv_MainTex);
  25.                         o.Albedo = c.rgb;
  26.                         o.Alpha = c.a;
  27.                 }
  28.                 ENDCG
  29.         }
  30.         FallBack "Diffuse"
  31. }
as the code , the sprite will hidden unless set the stencil buffer , but if i set the panel to soft clip , The sprite shows all the time .Is anyone can point out why the stencil shader not work ? thanks !!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel soft clip with stencil shader not work
« Reply #1 on: July 31, 2015, 09:28:22 PM »
NGUI's clipping works by replacing existing shaders with their clipped version. Clipping won't work if you don't actually specify a version of the shader that doesn't do clipping.

Look at existing shaders that come with NGUI: Unlit - Transparent Colored series for example.