如何解决gpu.js“错误:内核参数不足”
我正在制作的 React 应用程序中有一些计算量很大的画布效果。我一直试图弄清楚如何去做大约 2 天,它几乎可以工作,但我有一个我似乎无法弄清楚的错误。
这是运行其中一种效果计算的代码:
drawBubbles = () => {
const ctx = this.Canvas.getContext("2d");
ctx.strokeStyle = "white";
ctx.globalAlpha = 0.6;
if (this.bubbles.length) {
const gpu = new GPU();
const kernel = gpu
.createKernel(function ([
bubbles,canvasWidth,canvasHeight,beginPath,arc,stroke,]) {
const bubble = bubbles[this.thread.x];
bubble[1] -= bubble[2];
if (bubble[1] + bubble[2] * 2 < 0) {
bubble[1] = canvasHeight + bubble[2] * 2;
bubble[0] = Math.random() * canvasWidth;
}
if (Math.floor(Math.random() * 2) === 0) {
bubble[0] += Math.random() * 6 - 2.5;
}
ctx.lineWidth = bubble[2] / 2.5;
beginPath();
arc(bubble[0],bubble[1],bubble[2] * 2,2 * Math.PI);
stroke();
return bubble;
})
.setOutput([this.bubbles.length]);
this.bubbles = kernel([
this.bubbles,this.Canvas.width,this.Canvas.height,ctx.beginPath,ctx.arc,ctx.stroke,]);
} else {
for (let i = 0; i < 15; i++) {
this.bubbles.push([
// 0 = X
Math.random() * this.Canvas.width,// 1 = Y
Math.random() * this.Canvas.height,// 2 = Size/Speed
Math.random() * 3 + 1,]);
}
}
};
当我查看它时我一无所知,如果我不实现它,那么我的应用程序将以 10-20 fps(或在较慢的计算机上更低)运行
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。