1.圆内放大
//圆内放大
vec2 enlargeFun(vec2 curCoord,vec2 circleCenter,float radius,float intensity,float curve)
{
float currentDistance = distance(curCoord,circleCenter);
{
float weight = currentDistance/radius;
weight = 1.0-intensity*(1.0-pow(weight,curve));//默认curve 为2 ,当 curve 越大时, 会放大得越大的,
weight = clamp(weight,0.0,1.0);
curCoord = circleCenter+(curCoord-circleCenter)*weight;
}
return curCoord;
}
这是圆内放大算法,
输入:坐标,放大中心坐标,放大半径,放大比例系数,放大算法参数.
返回:放大之后应该取的像素的位置.
通常 intensity = 1.0,curve = 2.0
2.圆内缩小
vec2 narrowFun(vec2 curCoord,vec2 circleCenter,float radius,float intensity,float curve)
{
float currentDistance = distance(curCoord,circleCenter);
{
float weight = currentDistance/radius;
weight = 1.0-intensity*(1.0-pow(weight,curve));//默认curve 为2 ,当curve 越大时, 会缩小得越小的,
weight = clamp(weight,0.0001,1.0);
curCoord = circleCenter+(curCoord-circleCenter)/weight;
}
return curCoord;
}
参数含义
输入:坐标,放大中心坐标,放大半径,放大比例系数,放大算法参数.
返回:放大之后应该取的像素的位置.
通常 intensity = 1.0,curve = 2.0
3.向某一点拉伸
// 拉伸
vec2 stretchFun(vec2 textureCoord, vec2 originPosition, vec2 targetPosition, float radius,float curve)
{
vec2 offset = vec2(0.0);
vec2 result = vec2(0.0);
vec2 direction = targetPosition - originPosition;
float infect = distance(textureCoord, originPosition)/radius;
infect = pow(infect,curve);// 默认 curve 为1,这个值越大,拉伸到指定点越圆润,越小越尖
infect = 1.0-infect;
infect = clamp(infect,0.0,1.0);
offset = direction * infect;
result = textureCoord - offset;
return result;
}
参数含义
输入:坐标,拉伸中心坐标,拉伸目标坐标,拉伸半径,拉伸算法参数.
返回:放大之后应该取的像素的位置.
通常 curve = 2
具体原理分析和参数对效果的影响请参考 大神 zfgrinm
的博客 https://blog.csdn.net/zfgrinm/article/details/79291693
网友评论