hilight.effect 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: hilight-vs:vert
  6. frag: hilight-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. mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
  21. highlightColor: { value: [1, 1, 1, 1], editor: { type: color } }
  22. highlightIntensity:
  23. { value: 0.0, editor: { type: number, min: 0.0, max: 1.0 } }
  24. }%
  25. CCProgram hilight-vs %{
  26. precision highp float;
  27. #include <builtin/uniforms/cc-global>
  28. #if USE_LOCAL
  29. #include <builtin/uniforms/cc-local>
  30. #endif
  31. #if SAMPLE_FROM_RT
  32. #include <common/common-define>
  33. #endif
  34. in vec3 a_position;
  35. in vec2 a_texCoord;
  36. in vec4 a_color;
  37. out vec4 color;
  38. out vec2 uv0;
  39. vec4 vert () {
  40. vec4 pos = vec4(a_position, 1);
  41. #if USE_LOCAL
  42. pos = cc_matWorld * pos;
  43. #endif
  44. #if USE_PIXEL_ALIGNMENT
  45. pos = cc_matView * pos;
  46. pos.xyz = floor(pos.xyz);
  47. pos = cc_matProj * pos;
  48. #else
  49. pos = cc_matViewProj * pos;
  50. #endif
  51. uv0 = a_texCoord;
  52. #if SAMPLE_FROM_RT
  53. CC_HANDLE_RT_SAMPLE_FLIP(uv0);
  54. #endif
  55. color = a_color;
  56. return pos;
  57. }
  58. }%
  59. CCProgram hilight-fs %{
  60. precision highp float;
  61. #include <builtin/internal/embedded-alpha>
  62. #include <builtin/internal/alpha-test>
  63. in vec4 color;
  64. uniform Constant {
  65. vec4 mainColor;
  66. vec4 highlightColor;
  67. float highlightIntensity;
  68. };
  69. #if USE_TEXTURE
  70. in vec2 uv0;
  71. #pragma builtin(local)
  72. layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
  73. #endif
  74. vec4 frag () {
  75. vec4 o = vec4(1, 1, 1, 1);
  76. #if USE_TEXTURE
  77. o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0);
  78. #if IS_GRAY
  79. float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;
  80. o.r = o.g = o.b = gray;
  81. #endif
  82. #endif
  83. o *= color;
  84. o *= mainColor;
  85. if(o.a > 0.0){
  86. vec4 hilit = highlightColor * highlightIntensity;
  87. o += hilit;
  88. }
  89. ALPHA_TEST(o);
  90. // CC_APPLY_FOG(o);
  91. // return CCFragOutput(o);
  92. return o;
  93. }
  94. }%