Shader特效——“脸红的晃动”的实现 「GLSL」

效果图

Shader特效——“脸红的晃动”的实现 「GLSL」

原图

Shader特效——“脸红的晃动”的实现 「GLSL」

同向晃动

Shader特效——“脸红的晃动”的实现 「GLSL」

​异向晃动

原始算法和代码参考自 Lyman Li 大佬,我对代码进行了修改,并对一些算法细节进行补充,以及对代码增加了详细的注释。

在此,算法的主要步骤可以简要描述为:

通过 Bezier 曲线构建封闭区域

相关代码为:

<code>// P1 是起始点、P2 是控制点、P3 是终止点vec2 point1;vec2 point2;vec2 point3;

if (times == 0)
{
point1 = centerLeft; // 分别构造四条 Bezier 曲线的三个参数点
point2 = pointLT;
point3 = centerTop;
}
else if (times == 1)
{
point1 = centerTop;
point2 = pointRT;
point3 = centerRight;
}
else if (times == 2)
{
point1 = centerRight;
point2 = pointRB;
point3 = centerBottom;
}
else if (times == 3)
{
point1 = centerLeft;
point2 = pointLB;
point3 = centerBottom;
}
// reference from https://panda1234lee.blog.csdn.net/article/details/103998003/<code>

判断纹理坐标是否在区域内

  • 求解直线公式
  • 根据 Bezier 曲线公式求解与直线的交点
  • 纹理坐标是否落在子区域内

模拟纹理坐标(肉肉脸)的偏移

缓动函数来模拟阻力

振幅的衰减


分享到:


相關文章: