Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

209 rader
5.9 KiB

  1. -- GLSL.Vert --
  2. #version 120
  3. attribute vec2 in_Position;
  4. void main(void)
  5. {
  6. gl_Position = vec4(in_Position, 0.0, 1.0);
  7. }
  8. -- GLSL.Frag --
  9. #version 120
  10. uniform float u_Time;
  11. vec3 noise2d(vec2 p)
  12. {
  13. return vec3(fract(sin(dot(p, vec2(12.3453, -54.3353432))) * 8433.235443),
  14. fract(sin(dot(p, vec2(34.23232, 98.03537))) * 8294.5345433),
  15. fract(sin(dot(p, vec2(82.91234, -19.243533))) * 2912.454369));
  16. }
  17. vec3 noise3d(vec3 p)
  18. {
  19. return vec3(fract(sin(54.343909 + dot(p, vec3(12.3453, -54.3353432, 34.3490432))) * 8433.235443),
  20. fract(sin(93.329945 - dot(p, vec3(34.23232, 98.0353743, 90.2390984))) * 8294.5345433),
  21. fract(sin(32.039284 + dot(p, vec3(82.91234, -19.243533, 22.3294090))) * 2912.454369));
  22. }
  23. vec3 perlin2d(vec2 p)
  24. {
  25. vec2 a = floor(p);
  26. vec2 d = p - a;
  27. d = d * d * (3.0 - 2.0 * d);
  28. vec3 n1 = noise2d(a);
  29. vec3 n2 = noise2d(a + vec2(1.0, 0.0));
  30. vec3 n3 = noise2d(a + vec2(0.0, 1.0));
  31. vec3 n4 = noise2d(a + vec2(1.0, 1.0));
  32. vec3 q1 = n2 * d.x + n1 * (1.0 - d.x);
  33. vec3 q2 = n4 * d.x + n3 * (1.0 - d.x);
  34. vec3 q3 = q2 * d.y + q1 * (1.0 - d.y);
  35. return q3;
  36. }
  37. vec3 perlin3d(vec3 p)
  38. {
  39. mat3 r = mat3(0.36, 0.48, -0.8, -0.8, 0.60, 0.0, 0.48, 0.64, 0.60);
  40. p = r * p;
  41. vec3 a = floor(p);
  42. vec3 d = p - a;
  43. d = d * d * (3.0 - 2.0 * d);
  44. vec3 o1 = noise3d(a);
  45. vec3 o2 = noise3d(a + vec3(1.0, 0.0, 0.0));
  46. vec3 o3 = noise3d(a + vec3(0.0, 1.0, 0.0));
  47. vec3 o4 = noise3d(a + vec3(1.0, 1.0, 0.0));
  48. vec3 o5 = noise3d(a + vec3(0.0, 0.0, 1.0));
  49. vec3 o6 = noise3d(a + vec3(1.0, 0.0, 1.0));
  50. vec3 o7 = noise3d(a + vec3(0.0, 1.0, 1.0));
  51. vec3 o8 = noise3d(a + vec3(1.0, 1.0, 1.0));
  52. vec3 n1 = o2 * d.x + o1 * (1.0 - d.x);
  53. vec3 n2 = o4 * d.x + o3 * (1.0 - d.x);
  54. vec3 n3 = o6 * d.x + o5 * (1.0 - d.x);
  55. vec3 n4 = o8 * d.x + o7 * (1.0 - d.x);
  56. vec3 q1 = n2 * d.y + n1 * (1.0 - d.y);
  57. vec3 q2 = n4 * d.y + n3 * (1.0 - d.y);
  58. vec3 q3 = q2 * d.z + q1 * (1.0 - d.z);
  59. return q3;
  60. }
  61. void main(void)
  62. {
  63. vec2 xy = gl_FragCoord.xy * 2.0;
  64. xy.y -= u_Time * 400.0;
  65. float z = u_Time * 2.0;
  66. vec3 p = perlin3d(vec3(xy / 160.0, z)) / 2.0
  67. + perlin3d(vec3(xy / 80.0, z + 1.5)) / 4.0
  68. + perlin3d(vec3(xy / 40.0, z + 0.3)) / 8.0
  69. + perlin3d(vec3(xy / 20.0, z + 3.3)) / 16.0
  70. + perlin3d(vec3(xy / 10.0, z + 2.0)) / 32.0
  71. + perlin3d(vec3(xy / 5.0, z + 1.7)) / 64.0
  72. + perlin3d(vec3(xy / 2.5, z + 4.2)) / 128.0;
  73. /* Scroll by adding [-.5,.5] */
  74. p -= gl_FragCoord.y / 720.0 - 0.5;
  75. p = max(p, 0.0);
  76. p = min(p, 1.0);
  77. p = p * p * (3.0 - 2.0 * p);
  78. p = p * p * (3.0 - 2.0 * p);
  79. gl_FragColor = vec4(min(p.x * 2.0, 1.0), max(p.x * 1.5 - 0.5, 0.0), 0.0, 1.0);
  80. }
  81. -- HLSL.Vert --
  82. void main(float2 in_Position : POSITION,
  83. uniform float2 u_WinSize,
  84. out float4 out_Position : POSITION,
  85. out float2 pass_Position : TEXCOORD0)
  86. {
  87. //pass_Position = in_Position * u_WinSize;
  88. pass_Position = in_Position * float2(1280.0, 720.0);
  89. out_Position = float4(in_Position, 0.0, 1.0);
  90. }
  91. -- HLSL.Frag --
  92. float3 noise2d(float2 p)
  93. {
  94. return float3(frac(sin(dot(p, float2(12.3453, -54.3353432))) * 8433.235443),
  95. frac(sin(dot(p, float2(34.23232, 98.03537))) * 8294.5345433),
  96. frac(sin(dot(p, float2(82.91234, -19.243533))) * 2912.454369));
  97. }
  98. float3 noise3d(float3 p)
  99. {
  100. return float3(frac(sin(54.343909 + dot(p, float3(12.3453, -54.3353432, 34.3490432))) * 8433.235443),
  101. frac(sin(93.329945 - dot(p, float3(34.23232, 98.0353743, 90.2390984))) * 8294.5345433),
  102. frac(sin(32.039284 + dot(p, float3(82.91234, -19.243533, 22.3294090))) * 2912.454369));
  103. }
  104. float3 perlin2d(float2 p)
  105. {
  106. float2 a = floor(p);
  107. float2 d = p - a;
  108. d = d * d * (3.0 - 2.0 * d);
  109. float3 n1 = noise2d(a);
  110. float3 n2 = noise2d(a + float2(1.0, 0.0));
  111. float3 n3 = noise2d(a + float2(0.0, 1.0));
  112. float3 n4 = noise2d(a + float2(1.0, 1.0));
  113. float3 q1 = n2 * d.x + n1 * (1.0 - d.x);
  114. float3 q2 = n4 * d.x + n3 * (1.0 - d.x);
  115. float3 q3 = q2 * d.y + q1 * (1.0 - d.y);
  116. return q3;
  117. }
  118. float3 perlin3d(float3 p)
  119. {
  120. float3x3 r = float3x3(0.36, 0.48, -0.8, -0.8, 0.60, 0.0, 0.48, 0.64, 0.60);
  121. p = mul(r, p);
  122. float3 a = floor(p);
  123. float3 d = p - a;
  124. d = d * d * (3.0 - 2.0 * d);
  125. float3 o1 = noise3d(a);
  126. float3 o2 = noise3d(a + float3(1.0, 0.0, 0.0));
  127. float3 o3 = noise3d(a + float3(0.0, 1.0, 0.0));
  128. float3 o4 = noise3d(a + float3(1.0, 1.0, 0.0));
  129. float3 o5 = noise3d(a + float3(0.0, 0.0, 1.0));
  130. float3 o6 = noise3d(a + float3(1.0, 0.0, 1.0));
  131. float3 o7 = noise3d(a + float3(0.0, 1.0, 1.0));
  132. float3 o8 = noise3d(a + float3(1.0, 1.0, 1.0));
  133. float3 n1 = o2 * d.x + o1 * (1.0 - d.x);
  134. float3 n2 = o4 * d.x + o3 * (1.0 - d.x);
  135. float3 n3 = o6 * d.x + o5 * (1.0 - d.x);
  136. float3 n4 = o8 * d.x + o7 * (1.0 - d.x);
  137. float3 q1 = n2 * d.y + n1 * (1.0 - d.y);
  138. float3 q2 = n4 * d.y + n3 * (1.0 - d.y);
  139. float3 q3 = q2 * d.z + q1 * (1.0 - d.z);
  140. return q3;
  141. }
  142. void main(in float2 pass_Position : TEXCOORD0,
  143. uniform float u_Time,
  144. out float4 out_FragColor : COLOR)
  145. {
  146. float2 xy = pass_Position;
  147. xy.y -= u_Time * 400.0;
  148. float z = u_Time * 2.0;
  149. float3 p = perlin3d(float3(xy / 160.0, z)) / 2.0
  150. + perlin3d(float3(xy / 80.0, z + 1.5)) / 4.0
  151. + perlin3d(float3(xy / 40.0, z + 0.3)) / 8.0
  152. + perlin3d(float3(xy / 20.0, z + 3.3)) / 16.0
  153. + perlin3d(float3(xy / 10.0, z + 2.0)) / 32.0
  154. + perlin3d(float3(xy / 5.0, z + 1.7)) / 64.0
  155. + perlin3d(float3(xy / 2.5, z + 4.2)) / 128.0;
  156. /* Scroll by adding [-.5,.5] */
  157. p -= pass_Position.y / 1440.0;
  158. p = max(p, 0.0);
  159. p = min(p, 1.0);
  160. p = p * p * (3.0 - 2.0 * p);
  161. p = p * p * (3.0 - 2.0 * p);
  162. out_FragColor = float4(min(p.x * 2.0, 1.0), max(p.x * 1.5 - 0.5, 0.0), 0.0, 1.0);
  163. }