slideEffect.effect 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. center: { value: [0.5, 0.5], editor: { tooltip: '中心点 (左上角为原点)' } }
  16. }%
  17. CCProgram vs %{
  18. precision highp float;
  19. #include <cc-global>
  20. #include <cc-local>
  21. in vec3 a_position;
  22. in vec4 a_color;
  23. out vec4 v_color;
  24. #if USE_TEXTURE
  25. in vec2 a_uv0;
  26. out vec2 v_uv0;
  27. #endif
  28. void main () {
  29. vec4 pos = vec4(a_position, 1);
  30. #if CC_USE_MODEL
  31. pos = cc_matViewProj * cc_matWorld * pos;
  32. #else
  33. pos = cc_matViewProj * pos;
  34. #endif
  35. #if USE_TEXTURE
  36. v_uv0 = a_uv0;
  37. #endif
  38. v_color = a_color;
  39. gl_Position = pos;
  40. }
  41. }%
  42. CCProgram fs %{
  43. precision highp float;
  44. #include <alpha-test>
  45. #include <texture>
  46. in vec4 v_color;
  47. #if USE_TEXTURE
  48. in vec2 v_uv0;
  49. uniform sampler2D texture;
  50. #endif
  51. uniform Properties {
  52. vec2 center;
  53. };
  54. void main () {
  55. vec4 o = vec4(1, 1, 1, 1);
  56. #if USE_TEXTURE
  57. CCTexture(texture, fract(v_uv0 + center), o);
  58. #endif
  59. o *= v_color;
  60. ALPHA_TEST(o);
  61. #if USE_BGRA
  62. gl_FragColor = o.bgra;
  63. #else
  64. gl_FragColor = o.rgba;
  65. #endif
  66. }
  67. }%