flowLightEffect.effect 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //波纹流光
  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:
  14. value: white
  15. u_time:
  16. value: 0.5
  17. }%
  18. CCProgram vs %{ // 顶点Shader模块开始
  19. #include <cc-global>
  20. precision highp float; //定义float高精度
  21. in vec3 a_position; // 顶点Shader 从渲染管道里面获取的顶点信息,使用attribute来修饰;
  22. in vec2 a_uv0; // 纹理坐标;
  23. out vec2 uv0; // 传递给着色Shader,varying 来修饰,进行插值
  24. void main () {
  25. gl_Position = cc_matViewProj * vec4(a_position, 1);
  26. uv0 = a_uv0;
  27. }
  28. }%
  29. CCProgram fs %{
  30. #define TAU 6.12
  31. #define MAX_ITER 5 //最大迭代次数
  32. #include <alpha-test>
  33. #include <texture>
  34. precision highp float;
  35. in vec2 uv0;
  36. uniform sampler2D texture;
  37. uniform ARGS {
  38. vec4 UVoffset;
  39. float u_time;
  40. float rotated;
  41. };
  42. void main()
  43. {
  44. float u_time = u_time * .5+5.;
  45. vec2 UVnormalize;
  46. UVnormalize.x = (uv0.x-UVoffset.x)/(UVoffset.z-UVoffset.x);
  47. UVnormalize.y = (uv0.y-UVoffset.y)/(UVoffset.w-UVoffset.y);
  48. if(rotated > 0.5)
  49. {
  50. float temp = UVnormalize.x;
  51. UVnormalize.x = UVnormalize.y;
  52. UVnormalize.y = 1.0 - temp;
  53. }
  54. #if USE_TEXTURE
  55. #endif
  56. vec2 uv = uv0.xy;//fragCoord.xy / iResolution.xy;
  57. vec2 p = mod(uv*TAU, TAU)-250.0;
  58. vec2 i = vec2(p);
  59. float c = 1.0;
  60. float inten = .0065;
  61. for (int n = 0; n < MAX_ITER; n++)
  62. {
  63. float t = u_time * (1.0 - (3.5 / float(n+1)));
  64. i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(1.5*t + i.x));
  65. c += 1.0/length(vec2(p.x / (cos(i.x+t)/inten),p.y / (cos(i.y+t)/inten)));
  66. }
  67. c /= float(MAX_ITER);
  68. c = 1.17-pow(c, 1.4);
  69. vec4 tex = texture2D(texture,uv0);
  70. vec3 colour = vec3(pow(abs(c), 20.0));
  71. colour = clamp(colour + vec3(0.0, 0.0, .0), 0.0, tex.a);
  72. // 混合波光
  73. float alpha = c*tex[3];
  74. tex[0] = tex[0] + colour[0]*alpha;
  75. tex[1] = tex[1] + colour[1]*alpha;
  76. tex[2] = tex[2] + colour[2]*alpha;
  77. gl_FragColor = vec4(1,1,1,1) * tex;
  78. }
  79. }%