flash_color.effect 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. CCEffect %{
  2. techniques:
  3. - passes:
  4. - vert: vs
  5. frag: fs
  6. blendState:
  7. targets:
  8. - blend: true
  9. rasterizerState:
  10. cullMode: none
  11. properties:
  12. texture: { value: white }
  13. alphaThreshold: { value: 0.5 }
  14. u_lerp: { value: 0, editor: { range:[0, 1, 0.01], slide: true, tooltip: '变形' } }
  15. flashColorRed: { value: 0, editor: { range: [0, 1, 0.01], slide: true, tooltip: 'Flash Red Color' } }
  16. flashColorGreen: { value: 0, editor: { range: [0, 1, 0.01], slide: true, tooltip: 'Flash Green Color' } }
  17. flashColorBlue: { value: 0, editor: { range: [0, 1, 0.01], slide: true, tooltip: 'Flash Blue Color' } }
  18. }%
  19. CCProgram vs %{
  20. precision highp float;
  21. #include <cc-global>
  22. #include <cc-local>
  23. in vec3 a_position;
  24. in vec4 a_color;
  25. #if USE_TINT
  26. in vec4 a_color0;
  27. #endif
  28. in vec2 a_uv0;
  29. out vec2 v_uv0;
  30. out vec4 v_light;
  31. #if USE_TINT
  32. out vec4 v_dark;
  33. #endif
  34. void main () {
  35. mat4 mvp;
  36. #if CC_USE_MODEL
  37. mvp = cc_matViewProj * cc_matWorld;
  38. #else
  39. mvp = cc_matViewProj;
  40. #endif
  41. v_uv0 = a_uv0;
  42. v_light = a_color;
  43. #if USE_TINT
  44. v_dark = a_color0;
  45. #endif
  46. gl_Position = mvp * vec4(a_position, 1);
  47. }
  48. }%
  49. CCProgram fs %{
  50. precision highp float;
  51. uniform sampler2D texture;
  52. uniform u_lerp{
  53. float u_lerp;// 变形量[0, 1];
  54. };
  55. uniform flashColorRed{
  56. float flashColorRed;// 变形量[0, 1];
  57. };
  58. uniform flashColorGreen{
  59. float flashColorGreen;// 变形量[0, 1];
  60. };
  61. uniform flashColorBlue{
  62. float flashColorBlue;// 变形量[0, 1];
  63. };
  64. in vec2 v_uv0;
  65. in vec4 v_light;
  66. #if USE_TINT
  67. in vec4 v_dark;
  68. #endif
  69. #include <alpha-test>
  70. #include <texture>
  71. void main () {
  72. vec4 texColor = vec4(1.0);
  73. CCTexture(texture, v_uv0, texColor);
  74. vec4 finalColor;
  75. #if USE_TINT
  76. finalColor.a = v_light.a * texColor.a;
  77. finalColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;
  78. #else
  79. finalColor = texColor * v_light;
  80. #endif
  81. if (finalColor.a <= 0.0) discard;
  82. vec3 flashColor = vec3(flashColorRed, flashColorGreen, flashColorBlue);
  83. vec3 result = mix(finalColor.rgb, flashColor, u_lerp);
  84. finalColor = vec4(result.rgb, finalColor.a);
  85. ALPHA_TEST(finalColor);
  86. gl_FragColor = finalColor;
  87. }
  88. }%