builtin-2d-spine.effect 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  2. // Note: Current format version is experiment, the format may be changed.
  3. // The future format may not be compatible, you may need to update the script manually.
  4. // 注意:当前版本的格式是实验性的,之后还会进行修改。
  5. // 后续版本的格式不保证兼容当前格式,可能需要手动升级到最新版本。
  6. %{
  7. techniques: [
  8. {
  9. passes: [
  10. {
  11. vert: vs
  12. frag: fs
  13. cullMode: none
  14. blend: true
  15. }
  16. ]
  17. layer: 0
  18. }
  19. ]
  20. properties: {
  21. texture: {
  22. type: sampler2D
  23. value: null
  24. }
  25. alphaThreshold: {
  26. type: number
  27. value: 0.5
  28. }
  29. }
  30. %}
  31. %% vs {
  32. precision highp float;
  33. uniform mat4 cc_matViewProj;
  34. #if _USE_MODEL
  35. uniform mat4 cc_matWorld;
  36. #endif
  37. attribute vec3 a_position;
  38. attribute lowp vec4 a_color;
  39. #if USE_TINT
  40. attribute lowp vec4 a_color0;
  41. #endif
  42. attribute mediump vec2 a_uv0;
  43. varying mediump vec2 v_uv0;
  44. varying lowp vec4 v_light;
  45. #if USE_TINT
  46. varying lowp vec4 v_dark;
  47. #endif
  48. void main () {
  49. mat4 mvp;
  50. #if _USE_MODEL
  51. mvp = cc_matViewProj * cc_matWorld;
  52. #else
  53. mvp = cc_matViewProj;
  54. #endif
  55. v_uv0 = a_uv0;
  56. v_light = a_color;
  57. #if USE_TINT
  58. v_dark = a_color0;
  59. #endif
  60. gl_Position = mvp * vec4(a_position, 1);
  61. }
  62. }
  63. %% fs {
  64. precision highp float;
  65. uniform sampler2D texture;
  66. varying mediump vec2 v_uv0;
  67. #include <alpha-test>
  68. varying lowp vec4 v_light;
  69. #if USE_TINT
  70. varying lowp vec4 v_dark;
  71. #endif
  72. void main () {
  73. vec4 texColor = texture2D(texture, v_uv0);
  74. #if _USE_ETC1_TEXTURE
  75. texColor.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;
  76. #endif
  77. vec4 finalColor;
  78. #if USE_TINT
  79. finalColor.a = v_light.a * texColor.a;
  80. finalColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;
  81. #else
  82. finalColor = texColor * v_light;
  83. #endif
  84. ALPHA_TEST(finalColor);
  85. gl_FragColor = finalColor;
  86. }
  87. }