Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

236 Zeilen
5.5 KiB

  1. -- GLSL.Vert --
  2. #version 120
  3. uniform float u_Time;
  4. attribute vec2 in_Position;
  5. varying vec2 pass_Position;
  6. varying mat2 pass_Rotation;
  7. varying vec3 water[4];
  8. varying vec3 fire[4];
  9. float mod289(float x)
  10. {
  11. return x - floor(x * (1.0 / 289.0)) * 289.0;
  12. }
  13. void main(void)
  14. {
  15. mat3 r = mat3(0.36, 0.48, -0.8, -0.8, 0.60, 0.0, 0.48, 0.64, 0.60);
  16. vec3 p_pos = r * vec3(in_Position * vec2(16.0, 9.0), 0.0);
  17. vec3 p_time = r * vec3(0.0, 0.0, u_Time * 2.0);
  18. /* Noise sampling points for water */
  19. water[0] = p_pos / 2.0 + p_time;
  20. water[1] = p_pos / 4.0 + p_time;
  21. water[2] = p_pos / 8.0 + p_time;
  22. water[3] = p_pos / 16.0 + p_time;
  23. /* Noise sampling points for fire */
  24. p_pos = 16.0 * p_pos - r * vec3(0.0, mod289(u_Time) * 128.0, 0.0);
  25. fire[0] = p_pos / 2.0 + p_time;
  26. fire[1] = p_pos / 4.0 + p_time;
  27. fire[2] = p_pos / 8.0 + p_time;
  28. fire[3] = p_pos / 16.0 + p_time;
  29. pass_Position = in_Position;
  30. pass_Rotation = mat2(cos(u_Time), sin(u_Time), -sin(u_Time), cos(u_Time));
  31. gl_Position = vec4(in_Position, 0.0, 1.0);
  32. }
  33. -- GLSL.Frag --
  34. #version 120
  35. uniform float u_Time;
  36. varying vec2 pass_Position;
  37. varying mat2 pass_Rotation;
  38. varying vec3 water[4];
  39. varying vec3 fire[4];
  40. vec4 mod289(vec4 x)
  41. {
  42. return x - floor(x * (1.0 / 289.0)) * 289.0;
  43. }
  44. vec4 perm(vec4 x)
  45. {
  46. return mod289(((x * 34.0) + 1.0) * x);
  47. }
  48. float noise3d(vec3 p)
  49. {
  50. vec3 a = floor(p);
  51. vec3 d = p - a;
  52. d = d * d * (3.0 - 2.0 * d);
  53. vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0);
  54. vec4 k1 = perm(b.xyxy);
  55. vec4 k2 = perm(k1.xyxy + b.zzww);
  56. vec4 c = k2 + a.zzzz;
  57. vec4 k3 = perm(c);
  58. vec4 k4 = perm(c + 1.0);
  59. vec4 o1 = fract(k3 * (1.0 / 41.0));
  60. vec4 o2 = fract(k4 * (1.0 / 41.0));
  61. vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
  62. vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
  63. return o4.y * d.y + o4.x * (1.0 - d.y);
  64. }
  65. void main(void)
  66. {
  67. vec2 tmp = pass_Rotation * pass_Position;
  68. float test = tmp.x * tmp.y + sin(3.0 * u_Time);
  69. /* Add some garbage noise */
  70. test += fract(sin(test * 938.437) * 137.0) / 2.0;
  71. vec3 points[4] = (test > 0.0) ? fire : water;
  72. vec4 n = vec4(noise3d(points[0]),
  73. noise3d(points[1]),
  74. noise3d(points[2]),
  75. noise3d(points[3]));
  76. vec4 color;
  77. if (test > 0.0)
  78. {
  79. float p = dot(n, vec4(0.125, 0.125, 0.25, 0.5));
  80. /* Fade out by adding [-.5,.5] */
  81. p -= pass_Position.y * 0.8 + 0.25;
  82. p = max(p, 0.0);
  83. p = min(p, 1.0);
  84. float q = p * p * (3.0 - 2.0 * p);
  85. float r = q * q * (3.0 - 2.0 * q);
  86. color = vec4(min(q * 2.0, 1.0),
  87. max(r * 1.5 - 0.5, 0.0),
  88. max(q * 8.0 - 7.3, 0.0),
  89. 1.0);
  90. }
  91. else
  92. {
  93. float p = dot(abs(2.0 * n - 1.0),
  94. vec4(0.5, 0.25, 0.125, 0.125));
  95. float q = sqrt(p);
  96. color = vec4(1.0 - q,
  97. 1.0 - 0.5 * q,
  98. 1.0,
  99. 1.0);
  100. }
  101. gl_FragColor = color;
  102. }
  103. -- HLSL.Vert --
  104. void main(float2 in_Position : POSITION,
  105. uniform float2 u_WinSize,
  106. out float4 out_Position : POSITION,
  107. out float2 pass_Position : TEXCOORD0)
  108. {
  109. //pass_Position = in_Position * u_WinSize;
  110. pass_Position = in_Position * float2(1280.0, 720.0);
  111. out_Position = float4(in_Position, 0.0, 1.0);
  112. }
  113. -- HLSL.Frag --
  114. float4 mod289(float4 x)
  115. {
  116. return x - floor(x * (1.0 / 289.0)) * 289.0;
  117. }
  118. float4 perm(float4 x)
  119. {
  120. return mod289(((x * 34.0) + 1.0) * x);
  121. }
  122. float noise3d(float3 p)
  123. {
  124. float3x3 r = float3x3(0.36, 0.48, -0.8, -0.8, 0.60, 0.0, 0.48, 0.64, 0.60);
  125. p = mul(r, p);
  126. float3 a = floor(p);
  127. float3 d = p - a;
  128. d = d * d * (3.0 - 2.0 * d);
  129. float4 b = a.xxyy + float4(0.0, 1.0, 0.0, 1.0);
  130. float4 k1 = perm(b.xyxy);
  131. float4 k2 = perm(k1.xyxy + b.zzww);
  132. float4 c = k2 + a.zzzz;
  133. float4 k3 = perm(c);
  134. float4 k4 = perm(c + 1.0);
  135. float4 o1 = frac(k3 * (1.0 / 41.0));
  136. float4 o2 = frac(k4 * (1.0 / 41.0));
  137. float4 o3 = o2 * d.z + o1 * (1.0 - d.z);
  138. float2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
  139. return o4.y * d.y + o4.x * (1.0 - d.y);
  140. }
  141. void main(in float2 pass_Position : TEXCOORD0,
  142. uniform float u_Time,
  143. out float4 out_FragColor : COLOR)
  144. {
  145. float2 xy = pass_Position;
  146. float z = u_Time * 2.0;
  147. float tx = pass_Position.x * cos(u_Time) - pass_Position.y * sin(u_Time);
  148. float ty = pass_Position.x * sin(u_Time) + pass_Position.y * cos(u_Time);
  149. if (tx * ty > 0.0)
  150. xy.y -= z * 200.0;
  151. float p1 = noise3d(float3(xy / 80.0, z));
  152. float p2 = noise3d(float3(xy / 40.0, z));
  153. float p3 = noise3d(float3(xy / 20.0, z));
  154. float p4 = noise3d(float3(xy / 10.0, z));
  155. float4 color;
  156. if (tx * ty > 0.0)
  157. {
  158. float p = 0.5 * p1 + 0.25 * p2 + 0.125 * (p3 + p4);
  159. /* Scroll by adding [-.5,.5] */
  160. p -= pass_Position.y / 1440.0;
  161. p = max(p, 0.0);
  162. p = min(p, 1.0);
  163. float q = p * p * (3.0 - 2.0 * p);
  164. float r = q * q * (3.0 - 2.0 * q);
  165. color = float4(min(q * 2.0, 1.0),
  166. max(r * 1.5 - 0.5, 0.0),
  167. max(q * 8.0 - 7.3, 0.0),
  168. 1.0);
  169. }
  170. else
  171. {
  172. float p = 0.5 * p1 + 0.25 * p2 + 0.125 * (p3 + p4);
  173. float q = p * p * (3.0 - 2.0 * p);
  174. float r = q * q * (3.0 - 2.0 * q);
  175. color = float4(1.0 - q,
  176. 1.0 - 0.5 * r,
  177. 1.0,
  178. 1.0);
  179. }
  180. out_FragColor = color;
  181. }