gray.effect 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (c) 2017-2018 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_color;
  31. out vec2 v_uv0;
  32. #if USE_TEXTURE
  33. in vec2 a_uv0;
  34. #endif
  35. vec4 vert () {
  36. vec4 pos = vec4(a_position, 1);
  37. #if USE_LOCAL
  38. pos = cc_matWorld * pos;
  39. #endif
  40. #if USE_PIXEL_ALIGNMENT
  41. pos = cc_matView * pos;
  42. pos.xyz = floor(pos.xyz);
  43. pos = cc_matProj * pos;
  44. #else
  45. pos = cc_matViewProj * pos;
  46. #endif
  47. #if USE_TEXTURE
  48. v_uv0 = a_uv0;
  49. #endif
  50. v_color = a_color;
  51. v_uv0 = a_texCoord;
  52. return pos;
  53. }
  54. }%
  55. CCProgram sprite-fs %{
  56. precision highp float;
  57. #include <builtin/internal/embedded-alpha>
  58. #include <builtin/internal/alpha-test>
  59. in vec4 v_color;
  60. #if USE_TEXTURE
  61. in vec2 v_uv0;
  62. #pragma builtin(local)
  63. layout(set = 2, binding = 11) uniform sampler2D cc_spriteTexture;
  64. #endif
  65. vec4 frag () {
  66. // 灰度:将颜色的RGB设置为相同的值即可使得图片为灰色,一般处理方法有:
  67. // 1、取三种颜色的平均值
  68. // 2、取三种颜色的最大值(最小值)
  69. // 3、加权平均值:0.3R + 0.59G + 0.11*B
  70. vec4 o = vec4(1, 1, 1, 1);
  71. o *= CCSampleWithAlphaSeparated(cc_spriteTexture, v_uv0);
  72. float gray = (o.r + o.g + o.b)/3.0;
  73. o = vec4(gray, gray, gray, o.a);
  74. return o;
  75. }
  76. }%