shader_lighting _1.effect 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. texture: { value: white }
  14. alphaThreshold: { value: 0.5 }
  15. }%
  16. CCProgram vs %{
  17. precision highp float;
  18. #include <cc-global>
  19. #include <cc-local>
  20. in vec3 a_position;
  21. in vec4 a_color;
  22. out vec4 v_color;
  23. #if USE_TEXTURE
  24. in vec2 a_uv0;
  25. out vec2 v_uv0;
  26. #endif
  27. void main () {
  28. vec4 pos = vec4(a_position, 1);
  29. #if CC_USE_MODEL
  30. pos = cc_matViewProj * cc_matWorld * pos;
  31. #else
  32. pos = cc_matViewProj * pos;
  33. #endif
  34. #if USE_TEXTURE
  35. v_uv0 = a_uv0;
  36. #endif
  37. v_color = a_color;
  38. gl_Position = pos;
  39. }
  40. }%
  41. CCProgram fs %{
  42. precision highp float;
  43. #include <cc-global>
  44. #include <alpha-test>
  45. #include <texture>
  46. in vec4 v_color;
  47. #if USE_TEXTURE
  48. in vec2 v_uv0;
  49. uniform sampler2D texture;
  50. #endif
  51. const vec2 iResolution = vec2(0.5, 0.5);
  52. float hash21(vec2 x) {
  53. return fract(cos(mod(dot(x, vec2(13.9898, 8.141)), 3.14)) * 43758.5453);
  54. }
  55. vec2 hash22(vec2 uv) {
  56. uv = vec2(dot(uv, vec2(127.1,311.7)),
  57. dot(uv, vec2(269.5,183.3)));
  58. return 2.0 * fract(sin(uv) * 43758.5453123) - 1.0;
  59. }
  60. float perlinNoise(vec2 uv) {
  61. vec2 iuv = floor(uv);
  62. vec2 fuv = fract(uv);
  63. vec2 blur = smoothstep(.0, 1., fuv);
  64. vec2 bl = vec2(.0, .0);
  65. vec2 br = vec2(1., .0);
  66. vec2 tl = vec2(.0, 1.);
  67. vec2 tr = vec2(1., 1.);
  68. vec2 bln = hash22(iuv + bl);
  69. vec2 brn = hash22(iuv + br);
  70. vec2 tln = hash22(iuv + tl);
  71. vec2 trn = hash22(iuv + tr);
  72. float b = mix(dot(bln, fuv - bl), dot(brn, fuv - br), blur.x);
  73. float t = mix(dot(tln, fuv - tl), dot(trn, fuv - tr), blur.x);
  74. float c = mix(b, t, blur.y);
  75. float rs = 2.0 * texture2D(texture, vec2(uv.x,0.75)).r;
  76. return (c * rs);
  77. }
  78. float fbm(vec2 uv, int octaves) {
  79. float value = .0;
  80. float amplitude = .5;
  81. float freq = 2.0;
  82. for(int i = 0; i < 30; i++)
  83. {
  84. value += perlinNoise(uv) * amplitude;
  85. uv *= freq;
  86. amplitude *= .5;
  87. }
  88. return value;
  89. }
  90. mat2 R(float q) {
  91. return mat2(cos(q), sin(q), -sin(q), cos(q));
  92. }
  93. void main () {
  94. vec2 uvv = (v_uv0 - 0.5) / iResolution.y;
  95. vec3 col1, col2;
  96. uvv.xy += fbm(uvv.yx + cc_time.x * 0.5, 30);
  97. float dist1 = abs(uvv.y);
  98. col1 = vec3(1.0) * mix(0.0, 0.05, hash21(vec2(sin(cc_time.x)))) / dist1;
  99. vec4 o = vec4(0.0);
  100. vec2 uv = v_uv0;
  101. float t = cc_time.x, e, s, g, k = 0.01;
  102. for(float i = 0.0; i < 100.0; i++)
  103. {
  104. g += max(k, e * 0.2);
  105. vec3 p = vec3((uv - 0.6) / iResolution.y * g + iResolution / iResolution.y * R(t + g * 0.5) * 0.5, g + t / 0.3);
  106. e = 0.3 - dot(p.xy, p.xy);
  107. for (float s = 2.0; s < 100.0; s ++) {
  108. p.yz *= R(s);
  109. e += abs(dot(sin(p * s + t * s * 0.2) / s, p - p + 1.0));
  110. }
  111. o += o.w * min(e * o + (sin(vec4(1.0, 2.0, 3.0, 1.0) - p.z * 0.3) * 0.6 - 0.4), k) * k;
  112. }
  113. vec3 finalColor = mix(o.rgb, col1, 0.3);
  114. finalColor *= min(1.0, 1.0 + cos(0.15 * t)) + min(1.0, max(0.0, -2.0 - 4.0 * cos(0.15 * t))) * smoothstep(0.85, 1.0, fract(sin(t) * 43758.5453));
  115. gl_FragColor = vec4(finalColor, 1.0);
  116. }
  117. }%