Advertisement
Guest User

shader

a guest
Jan 25th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. //
  2. // Simple passthrough fragment shader
  3. //
  4.  
  5. varying vec2 v_vTexcoord;
  6. varying vec4 v_vColour;
  7.  
  8. uniform float iTime;
  9. varying vec2 v_vPosition_R;
  10.  
  11.  
  12. /* discontinuous pseudorandom uniformly distributed in [-0.5, +0.5]^3 */
  13. vec3 random3(vec3 c) {
  14. float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
  15. vec3 r;
  16. r.z = fract(512.0*j);
  17. j *= .125;
  18. r.x = fract(512.0*j);
  19. j *= .125;
  20. r.y = fract(512.0*j);
  21. return r-0.5;
  22. }
  23.  
  24. /* skew constants for 3d simplex functions */
  25. const float F3 = 0.3333333;
  26. const float G3 = 0.1666667;
  27.  
  28. /* 3d simplex noise */
  29. float simplex3d(vec3 p) {
  30. /* 1. find current tetrahedron T and it's four vertices */
  31. /* s, s+i1, s+i2, s+1.0 - absolute skewed (integer) coordinates of T vertices */
  32. /* x, x1, x2, x3 - unskewed coordinates of p relative to each of T vertices*/
  33.  
  34. /* calculate s and x */
  35. vec3 s = floor(p + dot(p, vec3(F3)));
  36. vec3 x = p - s + dot(s, vec3(G3));
  37.  
  38. /* calculate i1 and i2 */
  39. vec3 e = step(vec3(0.0), x - x.yzx);
  40. vec3 i1 = e*(1.0 - e.zxy);
  41. vec3 i2 = 1.0 - e.zxy*(1.0 - e);
  42.  
  43. /* x1, x2, x3 */
  44. vec3 x1 = x - i1 + G3;
  45. vec3 x2 = x - i2 + 2.0*G3;
  46. vec3 x3 = x - 1.0 + 3.0*G3;
  47.  
  48. /* 2. find four surflets and store them in d */
  49. vec4 w, d;
  50.  
  51. /* calculate surflet weights */
  52. w.x = dot(x, x);
  53. w.y = dot(x1, x1);
  54. w.z = dot(x2, x2);
  55. w.w = dot(x3, x3);
  56.  
  57. /* w fades from 0.6 at the center of the surflet to 0.0 at the margin */
  58. w = max(0.6 - w, 0.0);
  59.  
  60. /* calculate surflet components */
  61. d.x = dot(random3(s), x);
  62. d.y = dot(random3(s + i1), x1);
  63. d.z = dot(random3(s + i2), x2);
  64. d.w = dot(random3(s + 1.0), x3);
  65.  
  66. /* multiply d by w^4 */
  67. w *= w;
  68. w *= w;
  69. d *= w;
  70.  
  71. /* 3. return the sum of the four surflets */
  72. return dot(d, vec4(52.0));
  73. }
  74.  
  75. /* const matrices for 3d rotation */
  76. const mat3 rot1 = mat3(-0.37, 0.36, 0.85,-0.14,-0.93, 0.34,0.92, 0.01,0.4);
  77. const mat3 rot2 = mat3(-0.55,-0.39, 0.74, 0.33,-0.91,-0.24,0.77, 0.12,0.63);
  78. const mat3 rot3 = mat3(-0.71, 0.52,-0.47,-0.08,-0.72,-0.68,-0.7,-0.45,0.56);
  79.  
  80. /* directional artifacts can be reduced by rotating each octave */
  81. float simplex3d_fractal(vec3 m) {
  82. return 0.5333333*simplex3d(m*rot1)
  83. +0.2666667*simplex3d(2.0*m*rot2)
  84. +0.1333333*simplex3d(4.0*m*rot3)
  85. +0.0666667*simplex3d(8.0*m);
  86. }
  87.  
  88. void main()
  89. {
  90. vec2 p = v_vPosition_R.xy;
  91. vec3 p3 = vec3(p, iTime*0.025);
  92.  
  93. float value;
  94.  
  95. value = simplex3d_fractal(p3*16.0+32.0);
  96. value = 0.5 + 1.0*value;
  97.  
  98. vec4 originalColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord);
  99.  
  100. if(originalColor.a != 0.0)
  101. {
  102.  
  103. if (value > 0.2 && value <= 0.3)
  104. {
  105. gl_FragColor = vec4(0, 255, 255, 0.05);
  106. }
  107.  
  108. if (value > 0.88 && value < 0.92)
  109. {
  110. gl_FragColor = vec4(128, 219, 165, 0.8);
  111. }
  112.  
  113. if (value >= 0.92)
  114. {
  115. gl_FragColor = vec4(255, 255, 255, 1);
  116. }
  117. return;
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement