forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Double check newest changes work for gpujs#443
And added it as an example, it is pretty.
- Loading branch information
1 parent
4aa08ca
commit d9bee09
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<html> | ||
<title>Slow Fade</title> | ||
<body> | ||
<h1>Slow Fade</h1> | ||
<div> | ||
<canvas id="c" /> | ||
</div> | ||
</body> | ||
<script src="../bin/gpu-browser.js"></script> | ||
<script> | ||
const canvas = document.getElementById("c"); | ||
const gpu = new GPU({ | ||
canvas: canvas, | ||
mode: "gpu" | ||
}); | ||
const dim = 512; | ||
const kernel = gpu.createKernel( | ||
function(x) { | ||
this.color( | ||
(x * (this.thread.y + this.thread.x)) / 1024.0, | ||
(x * (this.thread.y * this.thread.x)) / (1024.0 * 1024.0), | ||
(x * (this.thread.y * 2 * this.thread.x)) / (1024.0 * 2), | ||
1 | ||
); | ||
}, | ||
{ | ||
output: [dim, dim], | ||
graphical: true | ||
} | ||
); | ||
|
||
let param = 0.0; | ||
const doDraw = () => { | ||
kernel(param); | ||
param += 0.001; | ||
window.requestAnimationFrame(doDraw); | ||
}; | ||
|
||
window.requestAnimationFrame(doDraw); | ||
</script> | ||
</html> |