源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
4.9 KiB

пре 1 месец
  1. // - Vertex Lit + ShadowCaster
  2. // - Premultiplied Alpha Blending (One OneMinusSrcAlpha)
  3. // - Double-sided, no depth
  4. Shader "Spine/Skeleton Lit" {
  5. Properties {
  6. _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
  7. [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
  8. }
  9. SubShader {
  10. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  11. LOD 100
  12. Cull Off
  13. ZWrite Off
  14. Blend One OneMinusSrcAlpha
  15. // Pass {
  16. // Tags { "LightMode"="Vertex" }
  17. // ColorMaterial AmbientAndDiffuse
  18. // Lighting On
  19. // SetTexture [_MainTex] {
  20. // Combine texture * primary DOUBLE, texture * primary
  21. // }
  22. // }
  23. Pass {
  24. Tags {
  25. "LIGHTMODE"="Vertex"
  26. "QUEUE"="Transparent"
  27. "IGNOREPROJECTOR"="true"
  28. "RenderType"="Transparent"
  29. }
  30. ZWrite Off
  31. Cull Off
  32. Blend One OneMinusSrcAlpha
  33. CGPROGRAM
  34. #pragma vertex vert
  35. #pragma fragment frag
  36. #pragma target 2.0
  37. #include "UnityCG.cginc"
  38. // ES2.0/WebGL/3DS can not do loops with non-constant-expression iteration counts :(
  39. #if defined(SHADER_API_GLES)
  40. #define LIGHT_LOOP_LIMIT 8
  41. #elif defined(SHADER_API_N3DS)
  42. #define LIGHT_LOOP_LIMIT 4
  43. #else
  44. #define LIGHT_LOOP_LIMIT unity_VertexLightParams.x
  45. #endif
  46. #pragma multi_compile __ POINT SPOT
  47. half3 computeLighting (int idx, half3 dirToLight, half3 eyeNormal, half3 viewDir, half4 diffuseColor, half atten) {
  48. half NdotL = max(dot(eyeNormal, dirToLight), 0.0);
  49. // diffuse
  50. half3 color = NdotL * diffuseColor.rgb * unity_LightColor[idx].rgb;
  51. return color * atten;
  52. }
  53. half3 computeOneLight (int idx, float3 eyePosition, half3 eyeNormal, half3 viewDir, half4 diffuseColor) {
  54. float3 dirToLight = unity_LightPosition[idx].xyz;
  55. half att = 1.0;
  56. #if defined(POINT) || defined(SPOT)
  57. dirToLight -= eyePosition * unity_LightPosition[idx].w;
  58. // distance attenuation
  59. float distSqr = dot(dirToLight, dirToLight);
  60. att /= (1.0 + unity_LightAtten[idx].z * distSqr);
  61. if (unity_LightPosition[idx].w != 0 && distSqr > unity_LightAtten[idx].w) att = 0.0; // set to 0 if outside of range
  62. distSqr = max(distSqr, 0.000001); // don't produce NaNs if some vertex position overlaps with the light
  63. dirToLight *= rsqrt(distSqr);
  64. #if defined(SPOT)
  65. // spot angle attenuation
  66. half rho = max(dot(dirToLight, unity_SpotDirection[idx].xyz), 0.0);
  67. half spotAtt = (rho - unity_LightAtten[idx].x) * unity_LightAtten[idx].y;
  68. att *= saturate(spotAtt);
  69. #endif
  70. #endif
  71. att *= 0.5; // passed in light colors are 2x brighter than what used to be in FFP
  72. return min (computeLighting (idx, dirToLight, eyeNormal, viewDir, diffuseColor, att), 1.0);
  73. }
  74. int4 unity_VertexLightParams; // x: light count, y: zero, z: one (y/z needed by d3d9 vs loop instruction)
  75. struct appdata {
  76. float3 pos : POSITION;
  77. float3 normal : NORMAL;
  78. half4 color : COLOR;
  79. float3 uv0 : TEXCOORD0;
  80. UNITY_VERTEX_INPUT_INSTANCE_ID
  81. };
  82. struct VertexOutput {
  83. fixed4 color : COLOR0;
  84. float2 uv0 : TEXCOORD0;
  85. float4 pos : SV_POSITION;
  86. UNITY_VERTEX_OUTPUT_STEREO
  87. };
  88. VertexOutput vert (appdata v) {
  89. VertexOutput o;
  90. UNITY_SETUP_INSTANCE_ID(v);
  91. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  92. half4 color = v.color;
  93. float3 eyePos = UnityObjectToViewPos(float4(v.pos, 1)).xyz; //mul(UNITY_MATRIX_MV, float4(v.pos,1)).xyz;
  94. half3 fixedNormal = half3(0,0,-1);
  95. half3 eyeNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, fixedNormal));
  96. //half3 eyeNormal = half3(0,0,1);
  97. half3 viewDir = 0.0;
  98. // Lights
  99. half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb;
  100. for (int il = 0; il < LIGHT_LOOP_LIMIT; ++il) {
  101. lcolor += computeOneLight(il, eyePos, eyeNormal, viewDir, color);
  102. }
  103. color.rgb = lcolor.rgb;
  104. o.color = saturate(color);
  105. o.uv0 = v.uv0;
  106. o.pos = UnityObjectToClipPos(v.pos);
  107. return o;
  108. }
  109. sampler2D _MainTex;
  110. fixed4 frag (VertexOutput i) : SV_Target {
  111. fixed4 tex = tex2D(_MainTex, i.uv0);
  112. fixed4 col;
  113. col.rgb = tex * i.color;
  114. col *= 2;
  115. col.a = tex.a * i.color.a;
  116. return col;
  117. }
  118. ENDCG
  119. }
  120. Pass {
  121. Name "Caster"
  122. Tags { "LightMode"="ShadowCaster" }
  123. Offset 1, 1
  124. Fog { Mode Off }
  125. ZWrite On
  126. ZTest LEqual
  127. Cull Off
  128. Lighting Off
  129. CGPROGRAM
  130. #pragma vertex vert
  131. #pragma fragment frag
  132. #pragma multi_compile_shadowcaster
  133. #pragma fragmentoption ARB_precision_hint_fastest
  134. #include "UnityCG.cginc"
  135. struct v2f {
  136. V2F_SHADOW_CASTER;
  137. float2 uv : TEXCOORD1;
  138. };
  139. uniform float4 _MainTex_ST;
  140. v2f vert (appdata_base v) {
  141. v2f o;
  142. TRANSFER_SHADOW_CASTER(o)
  143. o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  144. return o;
  145. }
  146. uniform sampler2D _MainTex;
  147. uniform fixed _Cutoff;
  148. float4 frag (v2f i) : COLOR {
  149. fixed4 texcol = tex2D(_MainTex, i.uv);
  150. clip(texcol.a - _Cutoff);
  151. SHADOW_CASTER_FRAGMENT(i)
  152. }
  153. ENDCG
  154. }
  155. }
  156. }