SpriteUnlit.cginc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef SPRITE_UNLIT_INCLUDED
  2. #define SPRITE_UNLIT_INCLUDED
  3. #include "ShaderShared.cginc"
  4. #if defined(_ALPHAPREMULTIPLY_ON)
  5. #undef _STRAIGHT_ALPHA_INPUT
  6. #else
  7. #define _STRAIGHT_ALPHA_INPUT
  8. #endif
  9. #include "../../CGIncludes/Spine-Skeleton-Tint-Common.cginc"
  10. ////////////////////////////////////////
  11. // Vertex structs
  12. //
  13. struct VertexInput
  14. {
  15. float4 vertex : POSITION;
  16. float4 texcoord : TEXCOORD0;
  17. fixed4 color : COLOR;
  18. #if defined(_TINT_BLACK_ON)
  19. float2 tintBlackRG : TEXCOORD1;
  20. float2 tintBlackB : TEXCOORD2;
  21. #endif
  22. UNITY_VERTEX_INPUT_INSTANCE_ID
  23. };
  24. struct VertexOutput
  25. {
  26. float4 pos : SV_POSITION;
  27. float2 texcoord : TEXCOORD0;
  28. fixed4 color : COLOR;
  29. #if defined(_FOG)
  30. UNITY_FOG_COORDS(1)
  31. #endif // _FOG
  32. #if defined(_TINT_BLACK_ON)
  33. float3 darkColor : TEXCOORD2;
  34. #endif
  35. UNITY_VERTEX_OUTPUT_STEREO
  36. };
  37. ////////////////////////////////////////
  38. // Vertex program
  39. //
  40. VertexOutput vert(VertexInput input)
  41. {
  42. VertexOutput output;
  43. UNITY_SETUP_INSTANCE_ID(input);
  44. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  45. output.pos = calculateLocalPos(input.vertex);
  46. output.texcoord = calculateTextureCoord(input.texcoord);
  47. output.color = calculateVertexColor(input.color);
  48. #if defined(_TINT_BLACK_ON)
  49. output.darkColor = GammaToTargetSpace(half3(input.tintBlackRG.r, input.tintBlackRG.g, input.tintBlackB.r))
  50. + (_Black.rgb * input.color.a);
  51. #endif
  52. #if defined(_FOG)
  53. UNITY_TRANSFER_FOG(output,output.pos);
  54. #endif // _FOG
  55. return output;
  56. }
  57. ////////////////////////////////////////
  58. // Fragment program
  59. //
  60. fixed4 frag(VertexOutput input) : SV_Target
  61. {
  62. fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
  63. RETURN_UNLIT_IF_ADDITIVE_SLOT_TINT(texureColor, input.color, input.darkColor, _Color.a, _Black.a) // shall be called before ALPHA_CLIP
  64. ALPHA_CLIP(texureColor, input.color)
  65. #if defined(_TINT_BLACK_ON)
  66. texureColor = fragTintedColor(texureColor, input.darkColor, input.color, _Color.a, _Black.a);
  67. #endif
  68. fixed4 pixel = calculatePixel(texureColor, input.color);
  69. COLORISE(pixel)
  70. APPLY_FOG(pixel, input)
  71. return pixel;
  72. }
  73. #endif // SPRITE_UNLIT_INCLUDED