hit.effect 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: vs
  6. frag: fs
  7. blendState:
  8. targets:
  9. - blend: true
  10. rasterizerState:
  11. cullMode: none
  12. properties:
  13. texture: { value: white }
  14. alphaThreshold: { value: 0.5 }
  15. u_color: { value: [1,1,1,1], editor: {type: color} }
  16. u_rate: { value: 1 }
  17. }%
  18. CCProgram vs %{
  19. precision highp float;
  20. #include <cc-global>
  21. #include <cc-local>
  22. in vec3 a_position;
  23. in vec4 a_color;
  24. out vec4 v_light;
  25. #if USE_TINT
  26. in vec4 a_color0;
  27. out vec4 v_dark;
  28. #endif
  29. #if USE_TEXTURE
  30. in vec2 a_uv0;
  31. out vec2 v_uv0;
  32. #endif
  33. void main () {
  34. mat4 mvp;
  35. #if CC_USE_MODEL
  36. mvp = cc_matViewProj * cc_matWorld;
  37. #else
  38. mvp = cc_matViewProj;
  39. #endif
  40. #if USE_TEXTURE
  41. v_uv0 = a_uv0;
  42. #endif
  43. v_light = a_color;
  44. #if USE_TINT
  45. v_dark = a_color0;
  46. #endif
  47. gl_Position = mvp * vec4(a_position, 1);
  48. }
  49. }%
  50. CCProgram fs %{
  51. precision highp float;
  52. #include <alpha-test>
  53. #include <texture>
  54. in vec4 v_light;
  55. #if USE_TINT
  56. in vec4 v_dark;
  57. #endif
  58. #if USE_TEXTURE
  59. in vec2 v_uv0;
  60. uniform sampler2D texture;
  61. #endif
  62. uniform ARGS {
  63. vec4 u_color;
  64. float u_rate;
  65. };
  66. void main () {
  67. vec4 texColor = vec4(1.0);
  68. #if USE_TEXTURE
  69. CCTexture(texture, v_uv0, texColor);
  70. #endif
  71. vec4 finalColor;
  72. #if USE_TINT
  73. finalColor.a = v_light.a * texColor.a;
  74. finalColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;
  75. #else
  76. finalColor = texColor * v_light;
  77. #endif
  78. ALPHA_TEST(finalColor);
  79. vec3 result = mix(u_color.rgb, finalColor.rgb, u_rate);
  80. gl_FragColor = vec4(result.rgb, finalColor.a);
  81. }
  82. }%