builtin-spine.effect 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: sprite-vs:vert
  6. frag: sprite-fs:frag
  7. depthStencilState:
  8. depthTest: false
  9. depthWrite: false
  10. blendState:
  11. targets:
  12. - blend: true
  13. blendSrc: src_alpha
  14. blendDst: one_minus_src_alpha
  15. blendDstAlpha: one_minus_src_alpha
  16. rasterizerState:
  17. cullMode: none
  18. properties:
  19. alphaThreshold: { value: 0.5 }
  20. }%
  21. CCProgram sprite-vs %{
  22. precision highp float;
  23. #include <builtin/uniforms/cc-global>
  24. #if USE_LOCAL
  25. #include <builtin/uniforms/cc-local>
  26. #endif
  27. in vec3 a_position;
  28. in vec2 a_texCoord;
  29. in vec4 a_color;
  30. out vec4 v_light;
  31. out vec2 uv0;
  32. #if TWO_COLORED
  33. in vec4 a_color2;
  34. out vec4 v_dark;
  35. #endif
  36. vec4 vert () {
  37. vec4 pos = vec4(a_position, 1);
  38. #if USE_LOCAL
  39. pos = cc_matWorld * pos;
  40. #endif
  41. pos = cc_matViewProj * pos;
  42. uv0 = a_texCoord;
  43. v_light = a_color;
  44. #if TWO_COLORED
  45. v_dark = a_color2;
  46. #endif
  47. return pos;
  48. }
  49. }%
  50. CCProgram sprite-fs %{
  51. precision highp float;
  52. #include <builtin/internal/alpha-test>
  53. in vec4 v_light;
  54. #if TWO_COLORED
  55. in vec4 v_dark;
  56. #endif
  57. in vec2 uv0;
  58. #pragma builtin(local)
  59. layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
  60. vec4 frag () {
  61. vec4 o = vec4(1, 1, 1, 1);
  62. #if TWO_COLORED
  63. vec4 texColor = vec4(1, 1, 1, 1);
  64. texColor *= texture(cc_spriteTexture, uv0);
  65. o.a = texColor.a * v_light.a;
  66. o.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;
  67. #else
  68. o *= texture(cc_spriteTexture, uv0);
  69. o *= v_light;
  70. #endif
  71. ALPHA_TEST(o);
  72. return o;
  73. }
  74. }%