片段代码:
export const fragment = `varying vec2 vUv;
uniform vec2 viewport;
uniform vec2 uMouse;
float createCircle() {
vec2 viewportUv = gl_FragCoord.xy / viewport;
float viewportAspect = viewport.x / viewport.y;
vec2 mousePoint = vec2(uMouse.x, 1.0 - uMouse.y);
float circleRadius = max(0.0, 100.0 / viewport.x);
vec2 shapeUv = viewportUv - mousePoint;
shapeUv /= vec2(1.0, viewportAspect);
shapeUv += mousePoint;
// Debug: Output mouse position
if (length(viewportUv - mousePoint) < 0.01) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // Red for mouse position
}
// Debug: Output shape UV
if (length(shapeUv - mousePoint) < 0.01) {
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); // Blue for shape UV
}
float dist = distance(shapeUv, mousePoint);
dist = smoothstep(circleRadius, circleRadius + 0.001, dist);
return dist;
}
void main() {
float circle = createCircle();
float dist = length(gl_PointCoord - vec2(0.5));
float disc = smoothstep(0.5, 0.45, dist);
gl_FragColor = vec4(disc * circle); // Final color based on circle distance
if (disc < 0.01) discard;
}`;
我的电脑视口(1920,932)和笔记本电脑(1280,593)现在当我 vec2 viewportUv = gl_FragCoord.xy / vec2(1920,932) 那样使用时,它在我的笔记本电脑中完美显示圆圈,但在再次调整大小时圆圈不显示事实上,即使当我调整大小时它在电脑上也能正常工作,然后还围绕指针创建圆圈;
我只想完美地围绕鼠标指针创建圆圈,即使我们改变屏幕尺寸或其他设备屏幕