1 | -- GLSL.Vert -- |
---|
2 | |
---|
3 | #version 120 |
---|
4 | |
---|
5 | attribute vec2 in_Position; |
---|
6 | |
---|
7 | void main(void) |
---|
8 | { |
---|
9 | gl_Position = vec4(in_Position, 0.0, 1.0); |
---|
10 | } |
---|
11 | |
---|
12 | -- GLSL.Frag -- |
---|
13 | |
---|
14 | #version 120 |
---|
15 | |
---|
16 | uniform float u_Time; |
---|
17 | |
---|
18 | vec4 mod289(vec4 x) |
---|
19 | { |
---|
20 | return x - floor(x * (1.0 / 289.0)) * 289.0; |
---|
21 | } |
---|
22 | |
---|
23 | vec4 perm(vec4 x) |
---|
24 | { |
---|
25 | return mod289(((x * 34.0) + 1.0) * x); |
---|
26 | } |
---|
27 | |
---|
28 | float noise3d(vec3 p) |
---|
29 | { |
---|
30 | mat3 r = mat3(0.36, 0.48, -0.8, -0.8, 0.60, 0.0, 0.48, 0.64, 0.60); |
---|
31 | p = r * p; |
---|
32 | |
---|
33 | vec3 a = floor(p); |
---|
34 | vec3 d = p - a; |
---|
35 | d = d * d * (3.0 - 2.0 * d); |
---|
36 | |
---|
37 | vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0); |
---|
38 | vec4 k1 = perm(b.xyxy); |
---|
39 | vec4 k2 = perm(k1.xyxy + b.zzww); |
---|
40 | |
---|
41 | vec4 c = k2 + a.zzzz; |
---|
42 | vec4 k3 = perm(c); |
---|
43 | vec4 k4 = perm(c + 1.0); |
---|
44 | |
---|
45 | vec4 o1 = fract(k3 * (1.0 / 41.0)); |
---|
46 | vec4 o2 = fract(k4 * (1.0 / 41.0)); |
---|
47 | |
---|
48 | vec4 o3 = o2 * d.z + o1 * (1.0 - d.z); |
---|
49 | vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x); |
---|
50 | |
---|
51 | return o4.y * d.y + o4.x * (1.0 - d.y); |
---|
52 | } |
---|
53 | |
---|
54 | void main(void) |
---|
55 | { |
---|
56 | vec2 xy = gl_FragCoord.xy * 2.0; |
---|
57 | xy.y -= u_Time * 400.0; |
---|
58 | float z = u_Time * 2.0; |
---|
59 | |
---|
60 | float p = noise3d(vec3(xy / 80.0, z)) / 2.0 |
---|
61 | + noise3d(vec3(xy / 40.0, z)) / 4.0 |
---|
62 | + noise3d(vec3(xy / 20.0, z)) / 8.0 |
---|
63 | + noise3d(vec3(xy / 10.0, z)) / 16.0; |
---|
64 | |
---|
65 | /* Scroll by adding [-.5,.5] */ |
---|
66 | p -= gl_FragCoord.y / 720.0 - 0.5; |
---|
67 | p = max(p, 0.0); |
---|
68 | p = min(p, 1.0); |
---|
69 | |
---|
70 | float q = p * p * (3.0 - 2.0 * p); |
---|
71 | float r = q * q * (3.0 - 2.0 * q); |
---|
72 | gl_FragColor = vec4(min(q * 2.0, 1.0), |
---|
73 | max(r * 1.5 - 0.5, 0.0), |
---|
74 | max(q * 8.0 - 7.3, 0.0), |
---|
75 | 1.0); |
---|
76 | } |
---|
77 | |
---|
78 | -- HLSL.Vert -- |
---|
79 | |
---|
80 | void main(float2 in_Position : POSITION, |
---|
81 | uniform float2 u_WinSize, |
---|
82 | out float4 out_Position : POSITION, |
---|
83 | out float2 pass_Position : TEXCOORD0) |
---|
84 | { |
---|
85 | //pass_Position = in_Position * u_WinSize; |
---|
86 | pass_Position = in_Position * float2(1280.0, 720.0); |
---|
87 | out_Position = float4(in_Position, 0.0, 1.0); |
---|
88 | } |
---|
89 | |
---|
90 | -- HLSL.Frag -- |
---|
91 | |
---|
92 | float4 mod289(float4 x) |
---|
93 | { |
---|
94 | return x - floor(x * (1.0 / 289.0)) * 289.0; |
---|
95 | } |
---|
96 | |
---|
97 | float4 perm(float4 x) |
---|
98 | { |
---|
99 | return mod289(((x * 34.0) + 1.0) * x); |
---|
100 | } |
---|
101 | |
---|
102 | float noise3d(float3 p) |
---|
103 | { |
---|
104 | float3x3 r = float3x3(0.36, 0.48, -0.8, -0.8, 0.60, 0.0, 0.48, 0.64, 0.60); |
---|
105 | p = mul(r, p); |
---|
106 | |
---|
107 | float3 a = floor(p); |
---|
108 | float3 d = p - a; |
---|
109 | d = d * d * (3.0 - 2.0 * d); |
---|
110 | |
---|
111 | float4 b = a.xxyy + float4(0.0, 1.0, 0.0, 1.0); |
---|
112 | float4 k1 = perm(b.xyxy); |
---|
113 | float4 k2 = perm(k1.xyxy + b.zzww); |
---|
114 | |
---|
115 | float4 c = k2 + a.zzzz; |
---|
116 | float4 k3 = perm(c); |
---|
117 | float4 k4 = perm(c + 1.0); |
---|
118 | |
---|
119 | float4 o1 = frac(k3 * (1.0 / 41.0)); |
---|
120 | float4 o2 = frac(k4 * (1.0 / 41.0)); |
---|
121 | |
---|
122 | float4 o3 = o2 * d.z + o1 * (1.0 - d.z); |
---|
123 | float2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x); |
---|
124 | |
---|
125 | return o4.y * d.y + o4.x * (1.0 - d.y); |
---|
126 | } |
---|
127 | |
---|
128 | void main(in float2 pass_Position : TEXCOORD0, |
---|
129 | uniform float u_Time, |
---|
130 | out float4 out_FragColor : COLOR) |
---|
131 | { |
---|
132 | float2 xy = pass_Position; |
---|
133 | xy.y -= u_Time * 400.0; |
---|
134 | float z = u_Time * 2.0; |
---|
135 | |
---|
136 | float p = noise3d(float3(xy / 80.0, z)) / 2.0 |
---|
137 | + noise3d(float3(xy / 40.0, z)) / 4.0 |
---|
138 | + noise3d(float3(xy / 20.0, z)) / 8.0 |
---|
139 | + noise3d(float3(xy / 10.0, z)) / 16.0; |
---|
140 | |
---|
141 | /* Scroll by adding [-.5,.5] */ |
---|
142 | p -= pass_Position.y / 1440.0; |
---|
143 | p = max(p, 0.0); |
---|
144 | p = min(p, 1.0); |
---|
145 | |
---|
146 | float q = p * p * (3.0 - 2.0 * p); |
---|
147 | float r = q * q * (3.0 - 2.0 * q); |
---|
148 | out_FragColor = float4(min(q * 2.0, 1.0), |
---|
149 | max(r * 1.5 - 0.5, 0.0), |
---|
150 | max(q * 8.0 - 7.3, 0.0), |
---|
151 | 1.0); |
---|
152 | } |
---|