Task 3 of 6
On the CPU you'd loop over 262,144 pixels one by one. On the GPU, every pixel gets its own thread — the kernel body runs once per pixel, all at the same time.
Image data comes in row-major: image[y][x] is the pixel in row y,
column x, and each pixel is an [r, g, b, a] array with channels from
0 to 1. Mind the inversion that catches everyone — sizes are given width-first
(output: [width, height]), but indexing runs row-first, so this thread's own
pixel is image[this.thread.y][this.thread.x]. Swap those two and you read the
transpose of your image. Three-dimensional data follows the same rule:
output: [w, h, d] is indexed [z][y][x].
image to
grayscale using perceptual luminance.graphical: true and output: [512, 512]image0.299 R + 0.587 G + 0.114 Bthis.color()Inside a kernel, this.thread.x and this.thread.y tell you which
output cell this thread owns. Use them to index into image.
image[this.thread.y][this.thread.x] gives you an [r, g, b, a]
array with channels in the 0–1 range.
This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.