|
| 1 | +#version 460 core |
| 2 | + |
| 3 | +#include <flutter/runtime_effect.glsl> |
| 4 | + |
| 5 | +precision mediump float; |
| 6 | + |
| 7 | +uniform vec2 resolution; |
| 8 | +out vec4 fragColor; |
| 9 | + |
| 10 | +vec3 pink = vec3(255, 105, 180) / 255; |
| 11 | + |
| 12 | +// dot2 and sdHeart from https://iquilezles.org/articles/distfunctions2d/ |
| 13 | +// |
| 14 | +// The MIT License |
| 15 | +// Copyright © 2015 Inigo Quilez |
| 16 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 17 | +// of this software and associated documentation files (the "Software"), to deal |
| 18 | +// in the Software without restriction, including without limitation the rights |
| 19 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 20 | +// copies of the Software, and to permit persons to whom the Software is |
| 21 | +// furnished to do so, subject to the following conditions: The above copyright |
| 22 | +// notice and this permission notice shall be included in all copies or |
| 23 | +// substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", |
| 24 | +// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 25 | +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
| 27 | +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 28 | +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR |
| 29 | +// THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 30 | +// https://www.youtube.com/c/InigoQuilez |
| 31 | +// https://iquilezles.org |
| 32 | + |
| 33 | +float dot2(vec2 v) { return dot(v, v); } |
| 34 | +float sdHeart(in vec2 p) { |
| 35 | + p.x = abs(p.x); |
| 36 | + |
| 37 | + if (p.y + p.x > 1.0) |
| 38 | + return sqrt(dot2(p - vec2(0.25, 0.75))) - sqrt(2.0) / 4.0; |
| 39 | + return sqrt(min(dot2(p - vec2(0.00, 1.00)), |
| 40 | + dot2(p - 0.5 * max(p.x + p.y, 0.0)))) * |
| 41 | + sign(p.x - p.y); |
| 42 | +} |
| 43 | + |
| 44 | +void main() { |
| 45 | + vec2 st = FlutterFragCoord().xy / resolution.xy; |
| 46 | + // Remap coordinates. |
| 47 | + // Flutter normalized coordinates have range [0,1] but sdHeart expects [-1,1]. |
| 48 | + st = (st - vec2(0.5)) * vec2(2.0); |
| 49 | + // Center the heart. |
| 50 | + // sdHeart is written such that the bottom point is at (0,0) and it's about 1 |
| 51 | + // unit tall. |
| 52 | + st.y -= 0.5; |
| 53 | + // Invert Y coordinate. |
| 54 | + st.y *= -1; |
| 55 | + |
| 56 | + // Calculate the color of this pixel according to the heart SDF, using |
| 57 | + // smoothstep to anti-alias the edges. |
| 58 | + vec3 color = vec3(0.0); |
| 59 | + color = mix(pink, color, smoothstep(0.01, 0.02, sdHeart(st))); |
| 60 | + |
| 61 | + fragColor = vec4(color, 1); |
| 62 | +} |
0 commit comments