鱼眼扭曲鼠标位置-片段着色器

问题描述

我试图创建鱼眼效果,但只能在鼠标位置周围的小半径范围内。我已经能够修改this code来处理鼠标位置(demo),但是我无法弄清楚缩放的来源。我期望输出与此类似地扭曲图像(出于这个问题,忽略颜色反转):

desired fish-eye effect

相关代码:

// Check if within given radius of the mouse
vec2 diff = myUV - u_mouse - 0.5;
float distance = dot(diff,diff); // square of distance,saves a square-root

// Add fish-eye 
if(distance <= u_radius_squared) {
  vec2 xy = 2.0 * (myUV - u_mouse) - 1.0;
  float d = length(xy * maxFactor);
  float z = sqrt(1.0 - d * d);
  float r = atan(d,z) / PI;
  float phi = atan(xy.y,xy.x);
    
  myUV.x = d * r * cos(phi) + 0.5 + u_mouse.x;
  myUV.y = d * r * sin(phi) + 0.5 + u_mouse.y;
}

vec3 tex = texture2D(tMap,myUV).rgb;

gl_FragColor.rgb = tex;

这是我的第一个着色器,因此除了解决此问题外,还欢迎进行其他改进。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)