cuopaiAuto.effect 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  2. // Note: Current format version is experiment, the format may be changed.
  3. // The future format may not be compatible, you may need to update the script manually.
  4. // 注意:当前版本的格式是实验性的,之后还会进行修改。
  5. // 后续版本的格式不保证兼容当前格式,可能需要手动升级到最新版本。,
  6. CCEffect %{
  7. techniques:
  8. - passes:
  9. - vert: vs
  10. frag: fsFront
  11. blendState:
  12. targets:
  13. - blend: true
  14. rasterizerState:
  15. cullMode: back
  16. properties:
  17. textureBack: { value: white }
  18. textureFront: { value: white }
  19. ratio: { value: 0 }
  20. radius: { value: 0 }
  21. width: { value: 0 }
  22. height: { value: 0 }
  23. offx: { value: 0 }
  24. offy: { value: 0 }
  25. rotation: { value: 0 }
  26. }%
  27. CCProgram vs %{
  28. precision highp float;
  29. #include <cc-global>
  30. #include <cc-local>
  31. in vec3 a_position;
  32. in mediump vec2 a_uv0;
  33. out mediump vec2 v_uv0;
  34. uniform RATIO {
  35. float ratio;
  36. float radius;
  37. float width;
  38. float height;
  39. float offx;
  40. float offy;
  41. float rotation;
  42. };
  43. void main () {
  44. mat4 mvp;
  45. mvp = cc_matViewProj;
  46. v_uv0 = vec2(1.0 - a_uv0.x,a_uv0.y);
  47. vec4 tmp_pos = vec4(0.0, 0.0, 0.0, 0.0);
  48. tmp_pos = vec4(a_position.x, a_position.y, 0.0, 1.0);
  49. if(tmp_pos.x < 0.0 || tmp_pos.x > width || tmp_pos.y < 0.0 || tmp_pos.y > height){
  50. tmp_pos.x = 0.0;tmp_pos.y = 0.0;}
  51. float cl = height/5.0;
  52. float sl = (height - cl)/2.0;
  53. float radii = (cl/rotation)/2.0;
  54. float sinRot = sin(rotation);
  55. float cosRot = cos(rotation);
  56. float distance = radii*sinRot;
  57. float centerY = height/2.0;
  58. float poxY1 = centerY - distance;
  59. float poxY2 = centerY + distance;
  60. float posZ = sl*sinRot;
  61. if(tmp_pos.y <= sl){
  62. float length = sl - tmp_pos.y;
  63. tmp_pos.y = poxY1 - length*cosRot;
  64. tmp_pos.z = posZ - length*sinRot;
  65. }
  66. else if(tmp_pos.y < (sl+cl)){
  67. float el = tmp_pos.y - sl;
  68. float rotation2 = -el/radii;
  69. float x1 = poxY1;
  70. float y1 = posZ;
  71. float x2 = centerY;
  72. float y2 = posZ - radii*cosRot;
  73. float sinRot2 = sin(rotation2);
  74. float cosRot2 = cos(rotation2);
  75. tmp_pos.y=(x1-x2)*cosRot2-(y1-y2)*sinRot2+x2;
  76. tmp_pos.z=(y1-y2)*cosRot2+(x1-x2)*sinRot2+y2;
  77. }
  78. else if(tmp_pos.y <= height){
  79. float length = tmp_pos.y - cl - sl;
  80. tmp_pos.y = poxY2 + length*cosRot;
  81. tmp_pos.z = posZ - length*sinRot;
  82. }
  83. if(rotation <= 0.1){
  84. tmp_pos = vec4(a_position.x, a_position.y, 0.0, 1.0);
  85. }
  86. tmp_pos += vec4(offx, offy, 0.0, 0.0);
  87. gl_Position = mvp * tmp_pos;
  88. }
  89. }%
  90. CCProgram fsFront %{
  91. precision highp float;
  92. uniform sampler2D textureBack;
  93. uniform sampler2D textureFront;
  94. varying mediump vec2 v_uv0;
  95. #include <alpha-test>
  96. void main () {
  97. vec4 color = vec4(1.);
  98. color *= texture2D(textureFront, v_uv0);
  99. gl_FragColor = color;
  100. }
  101. }%