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 曲線公式求解與直線的交點
  • 紋理座標是否落在子區域內

模擬紋理座標(肉肉臉)的偏移

緩動函數來模擬阻力

振幅的衰減


分享到:


相關文章: