Unlit.shader 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Copyright(c) Live2D Inc. All rights reserved.
  3. *
  4. * Use of this source code is governed by the Live2D Open Software license
  5. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
  6. */
  7. Shader "Live2D Cubism/Unlit"
  8. {
  9. Properties
  10. {
  11. // Texture and model opacity settings.
  12. [PerRendererData] _MainTex("Main Texture", 2D) = "white" {}
  13. [PerRendererData] cubism_ModelOpacity("Model Opacity", Float) = 1
  14. // Blend settings.
  15. _SrcColor("Source Color", Int) = 0
  16. _DstColor("Destination Color", Int) = 0
  17. _SrcAlpha("Source Alpha", Int) = 0
  18. _DstAlpha("Destination Alpha", Int) = 0
  19. // Culling setting.
  20. _Cull("Culling", Int) = 0
  21. // Mask settings.
  22. [Toggle(CUBISM_MASK_ON)] cubism_MaskOn("Mask?", Int) = 0
  23. [Toggle(CUBISM_INVERT_ON)] cubism_InvertOn("Inverted?", Int) = 0
  24. [PerRendererData] cubism_MaskTexture("cubism_Internal", 2D) = "white" {}
  25. [PerRendererData] cubism_MaskTile("cubism_Internal", Vector) = (0, 0, 0, 0)
  26. [PerRendererData] cubism_MaskTransform("cubism_Internal", Vector) = (0, 0, 0, 0)
  27. //对FairyGUI自定义遮罩生效
  28. _StencilComp("Stencil Comparison", Float) = 8
  29. _Stencil("Stencil ID", Float) = 0
  30. _StencilOp("Stencil Operation", Float) = 0
  31. _StencilWriteMask("Stencil Write Mask", Float) = 255
  32. _StencilReadMask("Stencil Read Mask", Float) = 255
  33. }
  34. SubShader
  35. {
  36. Tags
  37. {
  38. "Queue" = "Transparent"
  39. "IgnoreProjector" = "True"
  40. "RenderType" = "Transparent"
  41. "PreviewType" = "Plane"
  42. "CanUseSpriteAtlas" = "True"
  43. }
  44. //对FairyGUI自定义遮罩生效
  45. Stencil
  46. {
  47. Ref[_Stencil]
  48. Comp[_StencilComp]
  49. Pass[_StencilOp]
  50. ReadMask[_StencilReadMask]
  51. WriteMask[_StencilWriteMask]
  52. }
  53. Cull [_Cull]
  54. Lighting Off
  55. ZWrite Off
  56. Blend [_SrcColor][_DstColor], [_SrcAlpha][_DstAlpha]
  57. Pass
  58. {
  59. CGPROGRAM
  60. #pragma vertex vert
  61. #pragma fragment frag
  62. #pragma multi_compile CUBISM_MASK_ON CUBISM_MASK_OFF CUBISM_INVERT_ON
  63. #include "UnityCG.cginc"
  64. #include "CubismCG.cginc"
  65. struct appdata
  66. {
  67. float4 vertex : POSITION;
  68. float4 color : COLOR;
  69. float2 texcoord : TEXCOORD0;
  70. UNITY_VERTEX_INPUT_INSTANCE_ID
  71. };
  72. struct v2f
  73. {
  74. float4 vertex : SV_POSITION;
  75. fixed4 color : COLOR;
  76. float2 texcoord : TEXCOORD0;
  77. UNITY_VERTEX_OUTPUT_STEREO
  78. // Add Cubism specific vertex output data.
  79. CUBISM_VERTEX_OUTPUT
  80. };
  81. sampler2D _MainTex;
  82. // Include Cubism specific shader variables.
  83. CUBISM_SHADER_VARIABLES
  84. v2f vert (appdata IN)
  85. {
  86. v2f OUT;
  87. UNITY_SETUP_INSTANCE_ID(IN);
  88. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  89. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  90. OUT.texcoord = IN.texcoord;
  91. OUT.color = IN.color;
  92. // Initialize Cubism specific vertex output data.
  93. CUBISM_INITIALIZE_VERTEX_OUTPUT(IN, OUT);
  94. return OUT;
  95. }
  96. fixed4 frag (v2f IN) : SV_Target
  97. {
  98. fixed4 OUT = tex2D(_MainTex, IN.texcoord) * IN.color;
  99. // Apply Cubism alpha to color.
  100. CUBISM_APPLY_ALPHA(IN, OUT);
  101. return OUT;
  102. }
  103. ENDCG
  104. }
  105. }
  106. }