gpujs / gpujs/gpu.js

Interest in specifying "Offsets" to the library as a conveinence function.

Open
#563 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
15.5k
Forks
663
PR merge metrics
No merged PRs in 30d

Description

I came to Robert with a question about the possibility of adding an offset to the raw input data as a convenience = efficiency function of gpu.js. For example, when using graphical mode, and drawing a image composited out of many other images (my use case) It could be useful to simply offset the input with something like.

`kernel.setOutput({image1:[10, 10], image2:[0, 0]})`

To give an optional x/y offset for each placed image.

My first attempt at this involved trying to offset the data when loading images in webgl (in /backend/web-gl2/kernel-value/html-image-array.js, line 53, there are offsets and widths that can be set.) This worked well, but unfortunately due to a limitation in webgl, It only works with positive offsets, not negative ones. (there was a workaround here, but because it uses a canvas it might be too slow: https://stackoverflow.com/questions/20930466/webgl-is-there-an-efficient-way-to-upload-only-part-of-an-image-canvas-as-a-tex)

In response to this limitation Robert suggested just modifying the kernel function like so: https://gist.github.com/robertleeplummerjr/26796385d415a928a6f060ef5e6e0310

In this case the offset functionality is not provided by the gpu.js library, and required that the user add a modest amount of extra lines to their kernel. The question came up of whether it would make sense to include this type of function wrapper in general in gpu.js, or it user should just write it manually like shown if they need it.

Is there any interest in providing an offsets type of option to gpu.js image (or other) inputs to avoid user having to do manual bound checks and index adjustment like in the example? If so I may look into creating the api...

![A GIF or MEME to give some spice of the internet](https://github.com/davidlyons/threejs-intro/blob/master/images/300.jpg?raw=true)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.