该特效可以分为以下 5 种效果的融合。
结合代码可知,这其实就是二维 sin*cos 的效果。
对纹理坐标增加了点随机性并随着 progress 移动后的效果如下
相应代码和注释如下
/// @note 大 Blob
/// 增加一点随机性,改变每个 blob 的形状
f += .1 +
sin(((p.x * rand(i) * 6.0) + ///< 影响 blob 的大小
(progress * 8.0)) + ///< 影响 blob 的速度
rand(i + 1.43)) *
cos(((p.y * rand(i + 4.4) * 6.0) + ///< 影响 blob 的大小
(progress * 6.0)) + ///< 影响 blob 的速度
rand(i + 2.4));
相应代码和注释如下
/// @note 小粒子
f += 1. - clamps(length(p -
vec2(smoothRandom(vec2(progress * 1.3), i + 1.0), ///< 控制粒子的运动位置和轨迹【通过插值确保产生的随机值是连续的】
smoothRandom(vec2(progress * 0.5), i + 6.25))) *
mix(20., 70., rand(i))); ///< 影响粒子的大小,值越大粒子越小
其实就是在随机的位置【连续变化】画随机大小的圆。
从上图中可以看出该效果是 “从无到有再到无” 的一个过程。
相应代码和注释如下
/// @note 颜色随着 progress 而变化
f = pow3(f * color, ///< 着色
vec3(1., 2. - sin(progress * PI), 1.3)); ///< 1., [2., 1.], 1.3
f *= sin(progress * PI);
纹理坐标的缩放即是对纹理进行缩放的效果
相应代码和注释如下
/// @note 图像周期性缩放
p -= .5; ///< 以屏幕中心为原点
/// 随机对纹理坐标进行缩放
p *= 1. + (smoothRandom(vec2(progress * 5.), 6.3) * sin(progress * PI) * .05);
p += .5; ///< 平移原点回左下角
相应代码和注释如下
float bluramount = sin(progress * PI) * .03;
/// @note repeats 越大,毛玻璃效果越弱
for (float i = 0.; i < repeats; i++)
{
/// 角度转弧度
float rad = radians((i / repeats) * 360.);
vec2 q = vec2(cos(rad), sin(rad)) *
(rand(vec2(i, p.x + p.y)) + bluramount); ///< 生成噪点
vec2 uv2 = p + (q * bluramount); ///< 随机噪点偏移纹理坐标,毛玻璃效果
blurred_image += textureSmoothMix(uv2); ///< 叠加随机偏移的纹理(同时随着 progress 变化)
}
blurred_image /= repeats; ///< 平均,模糊
/// @brief 纹理平滑混合
vec4 textureSmoothMix(vec2 p)
{
return mix(getFromColor(p), getToColor(p), sigmoid(progress, 10.));
}
综合以上所有效果后,完整代码和解释如下
请留言
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有