cuopai.effect 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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: fsBack
  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. - vert: vs
  27. frag: fsFront
  28. blendState:
  29. targets:
  30. - blend: true
  31. rasterizerState:
  32. cullMode: front
  33. properties:
  34. textureBack: { value: white }
  35. textureFront: { value: white }
  36. ratio: { value: 0 }
  37. radius: { value: 0 }
  38. width: { value: 0 }
  39. height: { value: 0 }
  40. offx: { value: 0 }
  41. offy: { value: 0 }
  42. rotation: { value: 0 }
  43. }%
  44. CCProgram vs %{
  45. precision highp float;
  46. #include <cc-global>
  47. #include <cc-local>
  48. in vec3 a_position;
  49. in mediump vec2 a_uv0;
  50. out mediump vec2 v_uv0;
  51. uniform RATIO {
  52. float ratio;
  53. float radius;
  54. float width;
  55. float height;
  56. float offx;
  57. float offy;
  58. float rotation;
  59. };
  60. void main () {
  61. mat4 mvp;
  62. mvp = cc_matViewProj;
  63. v_uv0 = a_uv0;
  64. vec4 tmp_pos = vec4(0.0, 0.0, 0.0, 0.0);
  65. tmp_pos = vec4(a_position.x, a_position.y, 0.0, 1.0);
  66. float halfPeri = radius * 3.14159;
  67. float hr = height * ratio;
  68. if(tmp_pos.x < 0.0 || tmp_pos.x > width || tmp_pos.y < 0.0 || tmp_pos.y > height)
  69. {
  70. tmp_pos.x = 0.0;tmp_pos.y = 0.0;
  71. }
  72. if(hr > 0.0 && hr <= halfPeri){
  73. if(tmp_pos.y < hr){
  74. float rad = hr/ 3.14159;
  75. float arc = (hr-tmp_pos.y)/rad;
  76. tmp_pos.y = hr - sin(arc)*rad;
  77. tmp_pos.z = rad * (1.0-cos(arc));
  78. }
  79. }
  80. if(hr > halfPeri){
  81. float straight = (hr - halfPeri)/2.0;
  82. if(tmp_pos.y < straight){
  83. tmp_pos.y = hr - tmp_pos.y;
  84. tmp_pos.z = radius * 2.0;
  85. }
  86. else if(tmp_pos.y < (straight + halfPeri)) {
  87. float dy = halfPeri - (tmp_pos.y - straight);
  88. float arc = dy/radius;
  89. tmp_pos.y = hr - straight - sin(arc)*radius;
  90. tmp_pos.z = radius * (1.0-cos(arc));
  91. }
  92. }
  93. float y1 = tmp_pos.y;
  94. float z1 = tmp_pos.z;
  95. float y2 = height;
  96. float z2 = 0.0;
  97. float sinRat = sin(rotation);
  98. float cosRat = cos(rotation);
  99. tmp_pos.y=(y1-y2)*cosRat-(z1-z2)*sinRat+y2;
  100. tmp_pos.z=(z1-z2)*cosRat+(y1-y2)*sinRat+z2;
  101. tmp_pos.y = tmp_pos.y - height/2.0*(1.0-cosRat);
  102. tmp_pos += vec4(offx, offy, 0.0, 0.0);
  103. gl_Position = mvp * tmp_pos;
  104. }
  105. }%
  106. CCProgram fsBack %{
  107. precision highp float;
  108. uniform sampler2D textureBack;
  109. uniform sampler2D textureFront;
  110. varying mediump vec2 v_uv0;
  111. void main () {
  112. vec4 color = vec4(1.);
  113. color *= texture2D(textureBack, v_uv0);
  114. gl_FragColor = color;
  115. }
  116. }%
  117. CCProgram fsFront %{
  118. precision highp float;
  119. uniform sampler2D textureBack;
  120. uniform sampler2D textureFront;
  121. varying mediump vec2 v_uv0;
  122. void main () {
  123. vec4 color = vec4(1.);
  124. color *= texture2D(textureFront, v_uv0);
  125. gl_FragColor = color;
  126. }
  127. }%