cuopaiLRAuto.effect 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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(a_position.x, a_position.y, 0.0, 1.0);
  48. float cl = width/5.0;
  49. float sl = (width - cl)/2.0;
  50. float radii = (cl/rotation)/2.0;
  51. float sinRot = sin(rotation);
  52. float cosRot = cos(rotation);
  53. float distance = radii*sinRot;
  54. float centerX = width/2.0;
  55. float posX1 = centerX - distance;
  56. float posX2 = centerX + distance;
  57. float posZ = sl*sinRot;
  58. if(tmp_pos.x <= sl){
  59. float length = sl - tmp_pos.x;
  60. tmp_pos.x = posX1 - length*cosRot;
  61. tmp_pos.z = posZ - length*sinRot;
  62. }
  63. else if(tmp_pos.x < (sl+cl)){
  64. float el = tmp_pos.x - sl;
  65. float rotation2 = -el/radii;
  66. float x1 = posX1;
  67. float y1 = posZ;
  68. float x2 = centerX;
  69. float y2 = posZ - radii*cosRot;
  70. float sinRot2 = sin(rotation2);
  71. float cosRot2 = cos(rotation2);
  72. tmp_pos.x=(x1-x2)*cosRot2-(y1-y2)*sinRot2+x2;
  73. tmp_pos.z=(y1-y2)*cosRot2+(x1-x2)*sinRot2+y2;
  74. }
  75. else if(tmp_pos.x <= width){
  76. float length = tmp_pos.x - cl - sl;
  77. tmp_pos.x = posX2 + length*cosRot;
  78. tmp_pos.z = posZ - length*sinRot;
  79. }
  80. if(rotation <= 0.1){
  81. tmp_pos = vec4(a_position.x, a_position.y, 0.0, 1.0);
  82. }
  83. tmp_pos += vec4(offx, offy, 0.0, 0.0);
  84. gl_Position = mvp * tmp_pos;
  85. }
  86. }%
  87. CCProgram fsFront %{
  88. precision highp float;
  89. uniform sampler2D textureBack;
  90. uniform sampler2D textureFront;
  91. varying mediump vec2 v_uv0;
  92. #include <alpha-test>
  93. void main () {
  94. vec4 color = vec4(1.);
  95. color *= texture2D(textureFront, v_uv0);
  96. gl_FragColor = color;
  97. }
  98. }%