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