gray-spine.effect 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. CCEffect %{
  2. techniques:
  3. - passes:
  4. - vert: vs
  5. frag: fs
  6. blendState:
  7. targets:
  8. - blend: true
  9. rasterizerState:
  10. cullMode: none
  11. properties:
  12. texture: { value: white }
  13. alphaThreshold: { value: 0.5 }
  14. }%
  15. CCProgram vs %{
  16. precision highp float;
  17. #include <cc-global>
  18. #include <cc-local>
  19. in vec3 a_position;
  20. in vec4 a_color;
  21. #if USE_TINT
  22. in vec4 a_color0;
  23. #endif
  24. in vec2 a_uv0;
  25. out vec2 v_uv0;
  26. out vec4 v_light;
  27. #if USE_TINT
  28. out vec4 v_dark;
  29. #endif
  30. void main () {
  31. mat4 mvp;
  32. #if CC_USE_MODEL
  33. mvp = cc_matViewProj * cc_matWorld;
  34. #else
  35. mvp = cc_matViewProj;
  36. #endif
  37. v_uv0 = a_uv0;
  38. v_light = a_color;
  39. #if USE_TINT
  40. v_dark = a_color0;
  41. #endif
  42. gl_Position = mvp * vec4(a_position, 1);
  43. }
  44. }%
  45. CCProgram fs %{
  46. precision highp float;
  47. uniform sampler2D texture;
  48. in vec2 v_uv0;
  49. in vec4 v_light;
  50. #if USE_TINT
  51. in vec4 v_dark;
  52. #endif
  53. #include <alpha-test>
  54. void main () {
  55. vec4 texColor = texture2D(texture, v_uv0);
  56. #if CC_USE_ALPHA_ATLAS_TEXTURE
  57. texColor.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;
  58. #endif
  59. vec4 finalColor;
  60. #if USE_TINT
  61. finalColor.a = v_light.a * texColor.a;
  62. finalColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;
  63. #else
  64. finalColor = texColor * v_light;
  65. #endif
  66. ALPHA_TEST(finalColor);
  67. float gray = 0.2126 * finalColor.r + 0.7152 * finalColor.g + 0.0722 * finalColor.b;
  68. gl_FragColor = vec4(gray, gray, gray, finalColor.a);
  69. }
  70. }%