Spine-SkeletonLit-URP-2DTest.shader 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. Shader "Universal Render Pipeline/2D/Spine/Skeleton LitTest"
  2. {
  3. Properties
  4. {
  5. [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
  6. [NoScaleOffset] _MainColor ("Main Color", Color) = (1,1,1,1)
  7. [NoScaleOffset] _MaskTex("Mask", 2D) = "white" {}
  8. _LiuGuang("LiuGuang", 2D) = "white" {}
  9. _LiuGuangColor ("LiuGuangColor", Color) = (1,1,1,1)
  10. [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
  11. [MaterialToggle(_LIGHT_AFFECTS_ADDITIVE)] _LightAffectsAdditive("Light Affects Additive", Float) = 0
  12. [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
  13. [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default
  14. _LiuGuangTime("LiuGuangTime", Float) = 0
  15. }
  16. HLSLINCLUDE
  17. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  18. ENDHLSL
  19. SubShader
  20. {
  21. // UniversalPipeline tag is required. If Universal render pipeline is not set in the graphics settings
  22. // this Subshader will fail.
  23. Tags
  24. {
  25. "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"
  26. }
  27. Cull Off
  28. ZWrite Off
  29. Stencil
  30. {
  31. Ref[_StencilRef]
  32. Comp[_StencilComp]
  33. Pass Keep
  34. }
  35. Pass
  36. {
  37. Tags
  38. {
  39. "LightMode" = "Universal2D"
  40. }
  41. ZWrite Off
  42. Cull Off
  43. Blend One OneMinusSrcAlpha
  44. HLSLPROGRAM
  45. // Required to compile gles 2.0 with standard srp library
  46. #pragma prefer_hlslcc gles
  47. #pragma exclude_renderers d3d11_9x
  48. #pragma multi_compile USE_SHAPE_LIGHT_TYPE_0 __
  49. #pragma multi_compile USE_SHAPE_LIGHT_TYPE_1 __
  50. #pragma multi_compile USE_SHAPE_LIGHT_TYPE_2 __
  51. #pragma multi_compile USE_SHAPE_LIGHT_TYPE_3 __
  52. #pragma multi_compile _ _LIGHT_AFFECTS_ADDITIVE
  53. #include <HLSLSupport.cginc>
  54. struct Attributes
  55. {
  56. float3 positionOS : POSITION;
  57. half4 color : COLOR;
  58. float2 uv : TEXCOORD0;
  59. };
  60. struct Varyings
  61. {
  62. float4 positionCS : SV_POSITION;
  63. half4 color : COLOR0;
  64. float2 uv : TEXCOORD0;
  65. float2 lightingUV : TEXCOORD1;
  66. float2 scenUV : TEXCOORD2;
  67. };
  68. // Spine related keywords
  69. #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  70. #pragma vertex CombinedShapeLightVertex
  71. #pragma fragment CombinedShapeLightFragment
  72. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
  73. #define USE_URP
  74. #include "../Include/SpineCoreShaders/Spine-Common.cginc"
  75. TEXTURE2D (_MainTex);
  76. SAMPLER (sampler_MainTex);
  77. TEXTURE2D (_MaskTex);
  78. SAMPLER (sampler_MaskTex);
  79. float4 _TextrueRect[3];
  80. fixed _GrayFloat;
  81. float4 _MainColor;
  82. sampler2D _LiuGuang;
  83. float4 _LiuGuang_ST;
  84. float4 _LiuGuangColor;
  85. float4 _vertextPos;
  86. float _LiuGuangTime;
  87. #if USE_SHAPE_LIGHT_TYPE_0
  88. SHAPE_LIGHT (
  89. 0
  90. )
  91. #endif
  92. #if USE_SHAPE_LIGHT_TYPE_1
  93. SHAPE_LIGHT (
  94. 1
  95. )
  96. #endif
  97. #if USE_SHAPE_LIGHT_TYPE_2
  98. SHAPE_LIGHT (
  99. 2
  100. )
  101. #endif
  102. #if USE_SHAPE_LIGHT_TYPE_3
  103. SHAPE_LIGHT (
  104. 3
  105. )
  106. #endif
  107. Varyings CombinedShapeLightVertex(Attributes v)
  108. {
  109. Varyings o = (Varyings)0;
  110. o.positionCS = TransformObjectToHClip(v.positionOS);
  111. o.uv = v.uv;
  112. float4 clipVertex = o.positionCS / o.positionCS.w;
  113. float4 pos = ComputeScreenPos(clipVertex);
  114. o.scenUV = mul(unity_ObjectToWorld, v.positionOS);
  115. o.lightingUV = ComputeScreenPos(clipVertex).xy;
  116. o.color = PMAGammaToTargetSpace(v.color);
  117. return o;
  118. }
  119. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"
  120. half4 CombinedShapeLightFragment(Varyings i) : SV_Target
  121. {
  122. half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv) * _MainColor;
  123. #if defined(_STRAIGHT_ALPHA_INPUT)
  124. tex.rgb *= tex.a;
  125. #endif
  126. half4 main = tex * i.color;
  127. #if !defined(_LIGHT_AFFECTS_ADDITIVE)
  128. if (i.color.a == 0)
  129. return main;
  130. #endif
  131. half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
  132. SurfaceData2D surfaceData;
  133. InputData2D inputData;
  134. surfaceData.albedo = main.rgb;
  135. surfaceData.alpha = 1;
  136. surfaceData.mask = mask;
  137. inputData.uv = i.uv;
  138. inputData.lightingUV = i.lightingUV;
  139. half4 color = half4(CombinedShapeLightShared(surfaceData, inputData).rgb, main.a);
  140. float gray = dot(color.rgb, float3(0.299, 0.587, 0.114));
  141. float3 grayColor = fixed3(gray, gray, gray);
  142. color.rgb = lerp(color.rgb, grayColor, _GrayFloat);
  143. float2 pointUV = _TextrueRect[0].xy;
  144. float2 maxUV = _TextrueRect[0].zw;
  145. if (i.uv.x > pointUV.x && i.uv.x < maxUV.x && i.uv.y > pointUV.y && i.uv.y < maxUV.y)
  146. {
  147. float2 blUV = (i.scenUV - _vertextPos.xy) / (_vertextPos.zw - _vertextPos.xy);
  148. float2 liuGuangUV = blUV - _LiuGuangTime * _LiuGuang_ST.xy + _LiuGuang_ST.zw;
  149. liuGuangUV = float2(liuGuangUV.x, liuGuangUV.y);
  150. color.rgb += tex2D(_LiuGuang, liuGuangUV).rgb * _LiuGuangColor;
  151. }
  152. pointUV = _TextrueRect[1].xy;
  153. maxUV = _TextrueRect[1].zw;
  154. if (i.uv.x > pointUV.x && i.uv.x < maxUV.x && i.uv.y > pointUV.y && i.uv.y < maxUV.y)
  155. {
  156. float2 blUV = (i.scenUV - _vertextPos.xy) / (_vertextPos.zw - _vertextPos.xy);
  157. float2 liuGuangUV = blUV - _LiuGuangTime * _LiuGuang_ST.xy + _LiuGuang_ST.zw;
  158. liuGuangUV = float2(liuGuangUV.x, liuGuangUV.y);
  159. color.rgb += tex2D(_LiuGuang, liuGuangUV).rgb * _LiuGuangColor;
  160. }
  161. return color;
  162. }
  163. ENDHLSL
  164. }
  165. }
  166. FallBack "Universal Render Pipeline/2D/Sprite-Lit-Default"
  167. }