Mult-material.effect 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  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. texture0: { value: white }
  14. texture1: { value: white }
  15. texture2: { value: white }
  16. texture3: { value: white }
  17. texture4: { value: white }
  18. texture5: { value: white }
  19. texture6: { value: white }
  20. texture7: { value: white }
  21. alphaThreshold: { value: 0.5 }
  22. }%
  23. CCProgram vs %{
  24. precision highp float;
  25. #include <cc-global>
  26. #include <cc-local>
  27. in vec3 a_position;
  28. in vec4 a_color;
  29. out lowp vec4 v_color;
  30. #if USE_TEXTURE
  31. in vec2 a_uv0;
  32. out mediump vec3 v_uv0;
  33. #endif
  34. void main () {
  35. vec4 pos = vec4(a_position, 1);
  36. #if CC_USE_MODEL
  37. pos = cc_matViewProj * cc_matWorld * pos;
  38. #else
  39. pos = cc_matViewProj * pos;
  40. #endif
  41. #if USE_TEXTURE
  42. v_uv0.y = a_uv0.y;
  43. v_uv0.z = mod(a_uv0.x,10.0);
  44. v_uv0.x = (a_uv0.x-v_uv0.z)*0.000001;
  45. #endif
  46. v_color = a_color;
  47. gl_Position = pos;
  48. }
  49. }%
  50. CCProgram fs %{
  51. precision mediump float;
  52. #include <alpha-test>
  53. #include <texture>
  54. in lowp vec4 v_color;
  55. #if USE_TEXTURE
  56. in mediump vec3 v_uv0;
  57. uniform sampler2D texture0;
  58. uniform sampler2D texture1;
  59. uniform sampler2D texture2;
  60. uniform sampler2D texture3;
  61. uniform sampler2D texture4;
  62. uniform sampler2D texture5;
  63. uniform sampler2D texture6;
  64. uniform sampler2D texture7;
  65. #endif
  66. vec4 Texture(sampler2D texture,vec2 uv, vec4 o){
  67. CCTexture(texture, uv, o);
  68. return o;
  69. }
  70. void main () {
  71. vec4 o = vec4(1, 1, 1, 1);
  72. #if USE_TEXTURE
  73. float index = v_uv0.z;
  74. if(index<0.5) o = Texture(texture0 , v_uv0.xy , o);
  75. else if(index<1.5) o = Texture(texture1 , v_uv0.xy , o);
  76. else if(index<2.5) o = Texture(texture2 , v_uv0.xy , o);
  77. else if(index<3.5) o = Texture(texture3 , v_uv0.xy , o);
  78. else if(index<4.5) o = Texture(texture4 , v_uv0.xy , o);
  79. else if(index<5.5) o = Texture(texture5 , v_uv0.xy , o);
  80. else if(index<6.5) o = Texture(texture6 , v_uv0.xy , o);
  81. else o = Texture(texture7 , v_uv0.xy , o);
  82. #endif
  83. o *= v_color;
  84. ALPHA_TEST(o);
  85. #if USE_BGRA
  86. gl_FragColor = o.bgra;
  87. #else
  88. gl_FragColor = o.rgba;
  89. #endif
  90. }
  91. }%