Author Topic: Spine clipping in scroll list  (Read 3276 times)

TwisterK

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Spine clipping in scroll list
« on: June 06, 2017, 09:40:17 PM »
Hi, I'm trying to create a scroll list that able to do the spine clipping. From this link http://www.tasharen.com/forum/index.php?topic=9286.msg43755#msg43755, ArenMook said use a custom shader to do  the clipping. So, what I do now is modify the Spine/Skeleton shader by referring to Unlit - Transparent Colored 1 shader code and here is the code for it.

  1. Shader "Spine/Skeleton clip" {
  2.  
  3.         Properties {
  4.  
  5.                 _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
  6.  
  7.                 _MainTex ("Texture to blend", 2D) = "black" {}
  8.  
  9.         }
  10.  
  11.         // 2 texture stage GPUs
  12.  
  13.         SubShader {
  14.  
  15.                 Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  16.  
  17.                 LOD 100
  18.  
  19.  
  20.  
  21.                 Cull Off
  22.  
  23.                 ZWrite Off
  24.  
  25.                 Blend One OneMinusSrcAlpha
  26.  
  27.                 Lighting Off
  28.  
  29.  
  30.  
  31.                 Pass {
  32.  
  33.                         ColorMaterial AmbientAndDiffuse
  34.  
  35.                         SetTexture [_MainTex] {
  36.  
  37.                                 Combine texture * primary
  38.  
  39.                         }
  40.  
  41.                 }
  42.  
  43.  
  44.  
  45.                 Pass {
  46.  
  47.                         Name "Caster"
  48.  
  49.                         Tags { "LightMode"="ShadowCaster" }
  50.  
  51.                         Offset 1, 1
  52.  
  53.                        
  54.  
  55.                         Fog { Mode Off }
  56.  
  57.                         ZWrite On
  58.  
  59.                         ZTest LEqual
  60.  
  61.                         Cull Off
  62.  
  63.                         Lighting Off
  64.  
  65.  
  66.  
  67.                         CGPROGRAM
  68.  
  69.                         #pragma vertex vert
  70.  
  71.                         #pragma fragment frag
  72.  
  73.                         #pragma multi_compile_shadowcaster
  74.  
  75.                         #pragma fragmentoption ARB_precision_hint_fastest
  76.  
  77.                         #include "UnityCG.cginc"
  78.  
  79.                         struct v2f {
  80.  
  81.                                 V2F_SHADOW_CASTER;
  82.  
  83.                                 float2  uv : TEXCOORD0;
  84.  
  85.                                 float2 worldPos : TEXCOORD1;
  86.  
  87.                         };
  88.  
  89.  
  90.  
  91.                         uniform float4 _MainTex_ST;
  92.  
  93.                         float4 _ClipRange0 = float4(0.0, 0.0, 1.0, 1.0);
  94.                         float2 _ClipArgs0 = float2(1000.0, 1000.0);
  95.  
  96.  
  97.  
  98.                         v2f vert (appdata_base v) {
  99.  
  100.                                 v2f o;
  101.  
  102.                                 TRANSFER_SHADOW_CASTER(o)
  103.  
  104.                                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  105.  
  106.                                 o.worldPos = v.vertex.xy * _ClipRange0.zw + _ClipRange0.xy;
  107.  
  108.                                 return o;
  109.  
  110.                         }
  111.  
  112.  
  113.  
  114.                         uniform sampler2D _MainTex;
  115.  
  116.                         uniform fixed _Cutoff;
  117.  
  118.  
  119.  
  120.                         float4 frag (v2f i) : COLOR {
  121.                                 // Softness factor
  122.                                 float2 factor = (float2(1.0, 1.0) - abs(i.worldPos)) * _ClipArgs0;
  123.  
  124.                                 fixed4 texcol = tex2D(_MainTex, i.uv);
  125.  
  126.                                 clip(texcol.a - _Cutoff);
  127.  
  128.                                 texcol.a *= clamp(min(factor.x, factor.y), 0.0, 1.0);
  129.  
  130.                                 SHADOW_CASTER_FRAGMENT(i)
  131.  
  132.                         }
  133.  
  134.                         ENDCG
  135.  
  136.                 }
  137.  
  138.         }
  139.  
  140.         // 1 texture stage GPUs
  141.  
  142.         SubShader {
  143.  
  144.                 Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  145.  
  146.                 LOD 100
  147.  
  148.  
  149.  
  150.                 Cull Off
  151.  
  152.                 ZWrite Off
  153.  
  154.                 Blend One OneMinusSrcAlpha
  155.  
  156.                 Lighting Off
  157.  
  158.  
  159.  
  160.                 Pass {
  161.  
  162.                         ColorMaterial AmbientAndDiffuse
  163.  
  164.                         SetTexture [_MainTex] {
  165.  
  166.                                 Combine texture * primary DOUBLE, texture * primary
  167.  
  168.                         }
  169.  
  170.                 }
  171.  
  172.         }
  173.  
  174. }

After I attached the SkeletonAnimation to one of the child in the scroll list and hope it would work but it didn't. Here is the picture for the setup.


Is it something I do wrong? Please help me on this as I've spent hours just to make this works, thanks in advance.



TwisterK

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Spine clipping in scroll list
« Reply #1 on: June 06, 2017, 09:44:01 PM »


Sorry for double posting, here is the actual screenshot mentioned above.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Spine clipping in scroll list
« Reply #2 on: June 10, 2017, 06:21:32 AM »
What's "spine clipping"? I don't understand your shader... shadow casting for a UI object? There's nothing in that shader that would do any kind of clipping.