|
| 1 | +uniform vec2 u_resolution; |
| 2 | +uniform float u_redness; |
| 3 | +uniform sampler2D u_tex0; |
| 4 | + |
| 5 | +mat2 rotationMatrix(float angle) { |
| 6 | + float sine = sin(angle), cosine = cos(angle); |
| 7 | + return mat2(cosine, -sine, sine, cosine); |
| 8 | +} |
| 9 | + |
| 10 | +vec3 hash32(vec2 p) { |
| 11 | + vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973)); |
| 12 | + p3 += dot(p3, p3.yxz + 33.33); |
| 13 | + return fract((p3.xxy + p3.yzz) * p3.zyx); |
| 14 | +} |
| 15 | + |
| 16 | +float hash12(vec2 p) { |
| 17 | + vec3 p3 = fract(vec3(p.xyx) * .1031); |
| 18 | + p3 += dot(p3, p3.yzx + 33.33); |
| 19 | + return fract((p3.x + p3.y) * p3.z); |
| 20 | +} |
| 21 | + |
| 22 | +float dist(vec2 uv) { |
| 23 | + uv -= 0.5; |
| 24 | + uv *= rotationMatrix(0.3); |
| 25 | + uv *= 2.; |
| 26 | + uv += vec2(0.2, 0.3); |
| 27 | + uv.x = max(uv.x, -uv.x); |
| 28 | + vec2 p = uv * 20.0; |
| 29 | + float r = length(p); |
| 30 | + float t = atan(p.y, p.x); |
| 31 | + float butterfly = 7. - 0.5 * sin(1. * t) + 2.5 * sin(3. * t) + 2.0 * sin(5. * t) - 1.7 * sin(7. * t) + 3.0 * cos(2. * t) - 2.0 * cos(4. * t) - 0.4 * cos(16. * t) - r; |
| 32 | + return butterfly; |
| 33 | +} |
| 34 | + |
| 35 | +void main() { |
| 36 | + vec2 pixel = 1.0 / u_resolution.xy; |
| 37 | + |
| 38 | + vec2 uv = gl_FragCoord.xy * pixel; |
| 39 | + |
| 40 | + float res = 100.0; |
| 41 | + |
| 42 | + // butterfly text texture is 42 by 7 |
| 43 | + int y = int(floor(uv.y * res)) % 7; |
| 44 | + float rowIndex = floor(uv.y * res / 7.0); |
| 45 | + int x = int(floor(uv.x * res) + 20. * sin(rowIndex * 2.) + 100.0) % 42; |
| 46 | + |
| 47 | + float butterflyText = texelFetch(u_tex0, ivec2(x, y), 0).r; |
| 48 | + |
| 49 | + vec2 uvI = floor(uv * res) / res; |
| 50 | + |
| 51 | + float message = 0.; |
| 52 | + |
| 53 | + // Add the text |
| 54 | + message = mix(message, 0.9, smoothstep(0., pixel.x, 1. - butterflyText)); |
| 55 | + |
| 56 | + // Add outside of butterfly |
| 57 | + message = mix(message, 0.7, smoothstep(0., pixel.x, dist(uvI))); |
| 58 | + |
| 59 | + // Subtract inside of butterfly |
| 60 | + message = mix(0.1, message, smoothstep(0., pixel.x, 2. - dist(uvI))); |
| 61 | + |
| 62 | + // Add noise |
| 63 | + message = mix(message, 0.8, smoothstep(0.0, 1.5, hash12(uvI * u_resolution.xy))); |
| 64 | + |
| 65 | + message = 1. - 0.6 * message; |
| 66 | + |
| 67 | + // Start as noise |
| 68 | + vec3 color = hash32(uvI * u_resolution.xy); |
| 69 | + // combine random color with the message. |
| 70 | + color.r = mix(clamp(color.r, 0.7, 1.0), 0.2 * color.r, message); |
| 71 | + color = mix(color, vec3(1.0, 0, 0) * color, u_redness); |
| 72 | + color.g *= 0.5; // Reduce green. |
| 73 | + |
| 74 | + // color = vec3(message); |
| 75 | + gl_FragColor = vec4(color, 1.0); |
| 76 | + |
| 77 | +} |
0 commit comments