Spine-SkeletonGraphic-NormalPass.cginc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef SKELETON_GRAPHIC_NORMALPASS_INCLUDED
  2. #define SKELETON_GRAPHIC_NORMALPASS_INCLUDED
  3. #include "UnityCG.cginc"
  4. #include "UnityUI.cginc"
  5. #include "../../CGIncludes/Spine-Common.cginc"
  6. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  7. struct VertexInput {
  8. float4 vertex : POSITION;
  9. float4 color : COLOR;
  10. float2 texcoord : TEXCOORD0;
  11. UNITY_VERTEX_INPUT_INSTANCE_ID
  12. };
  13. struct VertexOutput {
  14. float4 vertex : SV_POSITION;
  15. fixed4 color : COLOR;
  16. half2 texcoord : TEXCOORD0;
  17. float4 worldPosition : TEXCOORD1;
  18. UNITY_VERTEX_OUTPUT_STEREO
  19. };
  20. fixed4 _Color;
  21. fixed4 _TextureSampleAdd;
  22. float4 _ClipRect;
  23. VertexOutput vert (VertexInput IN) {
  24. VertexOutput OUT;
  25. UNITY_SETUP_INSTANCE_ID(IN);
  26. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  27. OUT.worldPosition = IN.vertex;
  28. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  29. OUT.texcoord = IN.texcoord;
  30. #ifdef UNITY_HALF_TEXEL_OFFSET
  31. OUT.vertex.xy += (_ScreenParams.zw-1.0) * float2(-1,1);
  32. #endif
  33. #ifdef _CANVAS_GROUP_COMPATIBLE
  34. half4 vertexColor = IN.color;
  35. // CanvasGroup alpha sets vertex color alpha, but does not premultiply it to rgb components.
  36. vertexColor.rgb *= vertexColor.a;
  37. // Unfortunately we cannot perform the TargetToGamma and PMAGammaToTarget transformations,
  38. // as these would be wrong with modified alpha.
  39. #else
  40. // Note: CanvasRenderer performs a GammaToTargetSpace conversion on vertex color already,
  41. // however incorrectly assuming straight alpha color.
  42. float4 vertexColor = PMAGammaToTargetSpace(half4(TargetToGammaSpace(IN.color.rgb), IN.color.a));
  43. #endif
  44. OUT.color = vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
  45. return OUT;
  46. }
  47. sampler2D _MainTex;
  48. fixed4 frag (VertexOutput IN) : SV_Target
  49. {
  50. half4 texColor = tex2D(_MainTex, IN.texcoord);
  51. #if defined(_STRAIGHT_ALPHA_INPUT)
  52. texColor.rgb *= texColor.a;
  53. #endif
  54. half4 color = (texColor + _TextureSampleAdd) * IN.color;
  55. color *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  56. #ifdef UNITY_UI_ALPHACLIP
  57. clip (color.a - 0.001);
  58. #endif
  59. return color;
  60. }
  61. #endif