## 原理解析

• 圆内放大
• 圆内缩小
• 向某一点拉伸

``````float dis=distance(vec2(gPosition.x,gPosition.y/uXY),vec2(centerPoint.x,centerPoint.y));
gl_FragColor=texture2D(vTexture,vec2(aCoordinate.x/2.0+0.25,aCoordinate.y/2.0+0.25));
}
gl_FragColor=orignalColor;

## 圆内放大

``````vec2 enlargeFun(vec2 curCoord,vec2 circleCenter,float radius,float intensity,float curve)
{
float currentDistance = distance(curCoord,circleCenter);

{

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;
}

curve是我们的pow函数的次方值,由于我们考虑的都是[0,1]区间的,所以该值越大,离中心点向外扩散也越厉害,放大效果越大.
intensity的取值是[0,1]当它取1时就是我们上面分析的情况,会最大化的利用pow次方产生的座标偏移来取像素,若它为0,则不会产生任何缩放效果,intensity是一个影响因子,一个对pow函数产生的座标偏移的采用度,intensity越大则会更大化利用pow函数产生座标便宜作为最后的座标偏移.

## 圆内缩小

``````vec2 narrowFun(vec2 curCoord,vec2 circleCenter,float radius,float intensity,float curve)
{
float currentDistance = distance(curCoord,circleCenter);

{
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;
}

## 向某一点拉伸

``````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;

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;
}

• Cang_Wang
11天前
• sumsmile
20天前
• handyTool
1年前
• sumsmile
20天前
• sumsmile
21天前