cuopaiRL.effect 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 = vec2(1.0 - a_uv0.x,1.0 - a_uv0.y);
  64. vec4 tmp_pos = vec4(width - a_position.x, a_position.y, 0.0, 1.0);
  65. float halfPeri = radius * 3.14159;
  66. float hr = width * ratio;
  67. if(hr > 0.0 && hr <= halfPeri){
  68. if(tmp_pos.x < hr){
  69. float rad = hr/ 3.14159;
  70. float arc = (hr-tmp_pos.x)/rad;
  71. tmp_pos.x = hr - sin(arc)*rad;
  72. tmp_pos.z = rad * (1.0-cos(arc));
  73. }
  74. }
  75. if(hr > halfPeri){
  76. float straight = (hr - halfPeri)/2.0;
  77. if(tmp_pos.x < straight){
  78. tmp_pos.x = hr - tmp_pos.x;
  79. tmp_pos.z = radius * 2.0;
  80. }
  81. else if(tmp_pos.x < (straight + halfPeri)) {
  82. float dy = halfPeri - (tmp_pos.x - straight);
  83. float arc = dy/radius;
  84. tmp_pos.x = hr - straight - sin(arc)*radius;
  85. tmp_pos.z = radius * (1.0-cos(arc));
  86. }
  87. }
  88. float x1 = tmp_pos.x;
  89. float z1 = tmp_pos.z;
  90. float x2 = width;
  91. float z2 = 0.0;
  92. float sinRat = sin(rotation);
  93. float cosRat = cos(rotation);
  94. tmp_pos.x=(x1-x2)*cosRat-(z1-z2)*sinRat+x2;
  95. tmp_pos.z=(z1-z2)*cosRat+(x1-x2)*sinRat+z2;
  96. tmp_pos.x = tmp_pos.x - width/2.0*(1.0-cosRat);
  97. tmp_pos.x = width - tmp_pos.x;
  98. tmp_pos += vec4(offx, offy, 0.0, 0.0);
  99. gl_Position = mvp * tmp_pos;
  100. }
  101. }%
  102. CCProgram fsBack %{
  103. precision highp float;
  104. uniform sampler2D textureBack;
  105. uniform sampler2D textureFront;
  106. varying mediump vec2 v_uv0;
  107. #include <alpha-test>
  108. void main () {
  109. vec4 color = vec4(1.);
  110. color *= texture2D(textureBack, v_uv0);
  111. gl_FragColor = color;
  112. }
  113. }%
  114. CCProgram fsFront %{
  115. precision highp float;
  116. uniform sampler2D textureBack;
  117. uniform sampler2D textureFront;
  118. varying mediump vec2 v_uv0;
  119. void main () {
  120. vec4 color = vec4(1.);
  121. color *= texture2D(textureFront, v_uv0);
  122. gl_FragColor = color;
  123. }
  124. }%