builtin-2d-sprite.effect 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_TEXTURE
  40. attribute mediump vec2 a_uv0;
  41. varying mediump vec2 v_uv0;
  42. #endif
  43. varying lowp vec4 v_color;
  44. void main () {
  45. mat4 mvp;
  46. #if _USE_MODEL
  47. mvp = cc_matViewProj * cc_matWorld;
  48. #else
  49. mvp = cc_matViewProj;
  50. #endif
  51. #if USE_TEXTURE
  52. v_uv0 = a_uv0;
  53. #endif
  54. v_color = a_color;
  55. gl_Position = mvp * vec4(a_position, 1);
  56. }
  57. }
  58. %% fs {
  59. precision highp float;
  60. #if USE_TEXTURE
  61. uniform sampler2D texture;
  62. varying mediump vec2 v_uv0;
  63. #endif
  64. #include <alpha-test>
  65. varying lowp vec4 v_color;
  66. void main () {
  67. vec4 color = v_color;
  68. #if USE_TEXTURE
  69. color *= texture2D(texture, v_uv0);
  70. #if _USE_ETC1_TEXTURE
  71. color.a *= texture2D(texture, v_uv0 + vec2(0, 0.5)).r;
  72. #endif
  73. #endif
  74. ALPHA_TEST(color);
  75. gl_FragColor = color;
  76. }
  77. }