bgScroll.effect 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. time: {value: 0.0 }
  15. speed: {value: 1.0 } // time 和speed 共同决定采样的偏移量.
  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. in vec4 v_color;
  46. #if USE_TEXTURE
  47. in vec2 v_uv0;
  48. uniform sampler2D texture;
  49. #endif
  50. uniform Param {
  51. float time;
  52. float speed;
  53. };
  54. void main () {
  55. vec4 o = vec4(1, 1, 1, 1);
  56. float offset = fract( time* speed + v_uv0.y);
  57. o *= texture(texture, vec2(v_uv0.x, offset));
  58. o *= v_color;
  59. ALPHA_TEST(o);
  60. gl_FragColor = o;
  61. }
  62. }%