Render loop that uses the results of previous render tend to glitch out.
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript
- Lĩnh vực
- computer-graphics, frontend
Hướng nghiên cứu
Tái hiện ví dụ từ index.html và index.js trong Chrome, bắt đầu với vòng lặp render gọi simulate() và getPixels(). So sánh các giá trị map liên tiếp và đầu ra của canvas để xác định nơi dữ liệu của lần lặp trước không còn được sử dụng hoặc bị hỏng. Hoàn thành khi các lần lặp lặp lại sử dụng các pixel trước đó và dần tạo ra hiệu ứng sáng lên như mong đợi mà không có lỗi hình ảnh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What is wrong?
I am trying to write a continuous simulation loop on canvas, using gpu.js. The idea is to:
- Generate an initial
w * h * 4array (Uint8ClampedArrayto be more specific) - Write a gpu.js kernel, that processes that data and outputs result with
this.color - return the data with
getPixels()and override the initial data - pass the data returned in step 3 to the next simulation
- repeat steps 3-5 in a render loop
However:
- The kernel does not use the data from the previous iteration (even though when I check the
mapvariable from the browser console, it does contain results from the previous iteration). You can see that the pixels are not increasing in lightness over first couple of iterations, but are just replaced. - After a couple of render calls, the entire thing starts to glitch out entirely, drawing almost full lines of the same pixel data.
- The left-side area is not a result of failed recording - it does look like this in the browser.
- In the example code below, RGB pixels are clamped on increasing the value to avoid any overflow possibilities.
Here is the recorded result:

Where does it happen?
In the browser. (chrome 101.0.4951.67)
How do we replicate the issue?
Here is a sample I wrote:
<!-- index.html -->
...
<canvas id="daCanvas" width="512" height="512" >
...
// index.js
const canvas = document.getElementById('daCanvas');
const gl = canvas.getContext('webgl2', { premultipliedAlpha: false });
// 1.
let map = new Uint8ClampedArray(canvas.width * canvas.height * 4);
const gpu = new GPU({
canvas,
context: gl,
});
// 2.
const simulate = gpu.createKernel(function(mapData) {
if(Math.random() > 0.95) {
this.color(
Math.min(1, mapData[this.thread.x][this.thread.y][0] / 255 + 0.3),
Math.min(1, mapData[this.thread.x][this.thread.y][1] / 255 + 0.3),
Math.min(1, mapData[this.thread.x][this.thread.y][2] / 255 + 0.3),
1
);
} else {
this.color(
mapData[this.thread.x][this.thread.y][0] / 255,
mapData[this.thread.x][this.thread.y][1] / 255,
mapData[this.thread.x][this.thread.y][2] / 255,
1
);
}
})
.setOutput([canvas.width, canvas.height])
.setGraphical(true);
const render = () => {
// 3.
simulate(GPU.input(map, [canvas.width, canvas.height, 4]));
// 4.
map = simulate.getPixels();
}
// 5.
// Were using a nice slow interval for gentle simulation. Resutls for reqquestAnimationFrame loop are similar, just faster
setInterval(() => {requestAnimationFrame(render);}, 1000)
How important is this (1-5)?
It's just an experiment a'la the game of life, so let's say 2 (I take my hobby experiments seriously, but let's be honest - I am just playing with the tech).
Expected behaviour (i.e. solution)
I expected, that the image would start black, and then with each iteration, some pixels would become lighter and lighter until the image is entirely white.
Other Comments
I was trying this with several different approaches (separate kernel for processing, separate for rendering, different operations within the kernel etc), but the result was always glitchy. Even If I had just a loop that always draws whatever is in mapData and then would execute something like map[0] - 255 from the browser console, the loop would glitch out after a several loops.
- Ngôn ngữ chính
- JavaScript
- Star
- 15.5k
- Fork
- 663
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của gpujs/gpu.js
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
-
WebGL backend silently returns all zeros for long-running kernels (no GL error, no context loss) Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 42/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
-
Bitwise result not correct Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Issue tương tự
-
area/install-update comp/cli comp/desktop P3 sweeper:risk-compatibility type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
NousResearch/hermes-agent#122386 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
IBM/node-sdk-core#373 ·
-
docs web/
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100