-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WebGL shim in CLI/Node context to allow GL-based modules to run in Node #216
Comments
Sorry for being late on the fisheyeGl issue but I was facing some issues which I am going through. |
Okay I brainstormed this a lot and I came up with 2-3 solutions
document.querySelector("#image-node") || new Image();
|
@tech4GT @jywarren I have done some research and here are some points on this: |
@jywarren request your help here. |
Hmm, to @tech4GT I think it's ok to have different code in browser or node if that code split exists only inside the module context. Although we could eventually try to generalize parts to make it easier to write webgl modules. |
For jsgl I wonder if we could use this:
https://github.com/Overv/JSGL/blob/master/README.md#glperspectivefovy-aspect-near-far
And it has texImage it looks like. It might require a rewrite of fisheyegl
though. Looks like it's OpenGL, not webgl?
Would puppeteer work? Gotta look into it.
… |
… On Sun, Feb 17, 2019, 4:33 PM Jeffrey Warren ***@***.*** wrote:
For jsgl I wonder if we could use this:
https://github.com/Overv/JSGL/blob/master/README.md#glperspectivefovy-aspect-near-far
And it has texImage it looks like. It might require a rewrite of fisheyegl
though. Looks like it's OpenGL, not webgl?
Would puppeteer work? Gotta look into it.
>
|
Although we could likely generate a dataurl from puppeteer instead of
screenshot
…On Sun, Feb 17, 2019, 4:36 PM Jeffrey Warren ***@***.*** wrote:
https://stackoverflow.com/questions/50051250/taking-a-screenshot-of-a-page-running-webgl-using-puppeteer
On Sun, Feb 17, 2019, 4:33 PM Jeffrey Warren ***@***.*** wrote:
> For jsgl I wonder if we could use this:
>
>
> https://github.com/Overv/JSGL/blob/master/README.md#glperspectivefovy-aspect-near-far
>
> And it has texImage it looks like. It might require a rewrite of
> fisheyegl though. Looks like it's OpenGL, not webgl?
>
> Would puppeteer work? Gotta look into it.
>
>>
|
It sounds reasonable, and we could try to improve on the loadtime later?
…On Sun, Feb 17, 2019, 4:36 PM Jeffrey Warren ***@***.*** wrote:
Although we could likely generate a dataurl from puppeteer instead of
screenshot
On Sun, Feb 17, 2019, 4:36 PM Jeffrey Warren ***@***.*** wrote:
>
> https://stackoverflow.com/questions/50051250/taking-a-screenshot-of-a-page-running-webgl-using-puppeteer
>
>
>
> On Sun, Feb 17, 2019, 4:33 PM Jeffrey Warren ***@***.*** wrote:
>
>> For jsgl I wonder if we could use this:
>>
>>
>> https://github.com/Overv/JSGL/blob/master/README.md#glperspectivefovy-aspect-near-far
>>
>> And it has texImage it looks like. It might require a rewrite of
>> fisheyegl though. Looks like it's OpenGL, not webgl?
>>
>> Would puppeteer work? Gotta look into it.
>>
>>>
|
… On Sun, Feb 17, 2019, 4:36 PM Jeffrey Warren ***@***.*** wrote:
It sounds reasonable, and we could try to improve on the loadtime later?
On Sun, Feb 17, 2019, 4:36 PM Jeffrey Warren ***@***.*** wrote:
> Although we could likely generate a dataurl from puppeteer instead of
> screenshot
>
> On Sun, Feb 17, 2019, 4:36 PM Jeffrey Warren ***@***.*** wrote:
>
>>
>> https://stackoverflow.com/questions/50051250/taking-a-screenshot-of-a-page-running-webgl-using-puppeteer
>>
>>
>>
>> On Sun, Feb 17, 2019, 4:33 PM Jeffrey Warren ***@***.*** wrote:
>>
>>> For jsgl I wonder if we could use this:
>>>
>>>
>>> https://github.com/Overv/JSGL/blob/master/README.md#glperspectivefovy-aspect-near-far
>>>
>>> And it has texImage it looks like. It might require a rewrite of
>>> fisheyegl though. Looks like it's OpenGL, not webgl?
>>>
>>> Would puppeteer work? Gotta look into it.
>>>
>>>>
|
In that case it can't be. |
Ah but see here:
puppeteer/puppeteer#1260 (comment)
…On Sun, Feb 17, 2019, 4:40 PM Slytherin ***@***.*** wrote:
puppeteer/puppeteer#1260
<puppeteer/puppeteer#1260>
In that case it can't be.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#216 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ5hDYfl-DMWiCuW6zIEBxYZTAxJuks5vOfZ0gaJpZM4TceLs>
.
|
What say on this? |
Hmm, do they say why?
…On Sun, Feb 17, 2019, 5:18 PM Slytherin ***@***.*** wrote:
Use at your own risk though, since @aslushnikov
<https://github.com/aslushnikov> says
Emulation.setDefaultBackgroundColorOverride doesn't work well.
What say on this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#216 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJyMKGhYRvpz5y4v8a_K8SfsP97O3ks5vOf86gaJpZM4TceLs>
.
|
I think potentially we just have to start trying things and see what we can
get to work.
…On Sun, Feb 17, 2019, 5:20 PM Jeffrey Warren ***@***.*** wrote:
Hmm, do they say why?
On Sun, Feb 17, 2019, 5:18 PM Slytherin ***@***.*** wrote:
> Use at your own risk though, since @aslushnikov
> <https://github.com/aslushnikov> says
> Emulation.setDefaultBackgroundColorOverride doesn't work well.
>
> What say on this?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#216 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AABfJyMKGhYRvpz5y4v8a_K8SfsP97O3ks5vOf86gaJpZM4TceLs>
> .
>
|
Sure @jywarren |
@jywarren Are we open to modifying your fisheye-gl coed then? I can make the changes and put in a pr. |
Oh, the approach I tried on this was nothing special as well, I was running the headless browser inside node and the module was running on the sequencer inside the headless browser! |
The issue I posted earlier relates to the fact that by default gl is disabled in puppeteer. You need to explicitly enable it. |
This is not an ideal solution though since we would want to avoid running the headless browser if possible(coz it'll take up a lot of resources) |
Even if it takes a lot of resources (starting up the browser) I still think we should move ahead with this implementation -- it's the closest I've seen to actually working so far. We could refactor and attempt another approach afterwards, but I think we have to try! Thank you all!!! |
Hi @Divy123 could you open a PR with your attempt so far? I'd like to try a few things. For example, https://github.com/stackgl/headless-gl#example says we can access the pixels like: //Create context
var width = 64
var height = 64
var gl = require('gl')(width, height, { preserveDrawingBuffer: true })
//Clear screen to red
gl.clearColor(1, 0, 0, 1)
gl.clear(gl.COLOR_BUFFER_BIT)
//Write output as a PPM formatted image
var pixels = new Uint8Array(width * height * 4)
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
process.stdout.write(['P3\n# gl.ppm\n', width, " ", height, '\n255\n'].join(''))
for(var i=0; i<pixels.length; i+=4) {
for(var j=0; j<3; ++j) {
process.stdout.write(pixels[i+j] + ' ')
}
} |
@jywarren I have an idea, maybe I can create a binding between |
If this works, it would allow for 100% code sharing between browser and node. |
@jywarren @Divy123 I think I have figured this out, what I am doing is using 2 libraries: |
Can you push what code you have and we can see what changes would be best
in which module? Thanks!!!!
…On Sun, Mar 31, 2019, 4:51 AM Varun Gupta ***@***.***> wrote:
@jywarren <https://github.com/jywarren> @Divy123
<https://github.com/Divy123> I think I have figured this out, what I am
doing is using 2 libraries:
node-canvas and gl, and I have overriden the default canvas.getContext to
return an instance of 'node-gl'
Apart from that I needed some more changes in the fisheye-gl code and I
think this might be ready.
Now do you guys think we should modify jywarren/fisheyegl or I should bake
the node-specific code in the module itself?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#216 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ07a33j86jwsMQncyolIYslkh85qks5vcHcJgaJpZM4TceLs>
.
|
@jywarren I have figured out a lot of things, can you explain a little about how this code is important though. |
The current code is outputting a black image and I am unable to figure out why. |
I think we can skip this in node because it seems to be to limit the
refresh of the library to the frame rate of the browser window refresh:
https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
Hmm, maybe try a simpler webgl task to be sure the basic idea works?
…On Sun, Mar 31, 2019, 10:08 AM Varun Gupta ***@***.***> wrote:
The current code is outputting a black image and I am unable to figure out
why.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#216 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ5r3Wmz8WRn8R9zw5nQ92-TCbsbOks5vcME0gaJpZM4TceLs>
.
|
I agree @tech4GT . |
Did you open an issue to ask more about it, and if so could you link there for reference? Thank you! |
I will review ASAP, apologies this has been taking a lot of time this week 😄 thanks for your patience! |
Thanks a lot @jywarren . |
oh awesome. Thanks.
…On Thu, Apr 4, 2019 at 10:16 AM Varun Gupta ***@***.***> wrote:
@jywarren <https://github.com/jywarren> here stackgl/headless-gl#149
<stackgl/headless-gl#149>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#216 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ016CuB23ccHHGx4DiX3hvfjkthXks5vdgk6gaJpZM4TceLs>
.
|
@publiclab/is-reviewers Can someone point me to the link for dist files. |
Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
We are getting help from @robertleeplummerjr in using |
I don't have a ton of time I can offer, already on borrowed, but I can look into getting the fisheye project running on headless-gl, and then we can connect the dots backwards to this project, so it can be loaded in. Does that sound reasonable? |
Wow that is very generous, thank you! We are very interested in this bc our For what it's worth, this is another WebGL module we use that has simpler parameters (four corner coordinate pairs): https://github.com/jywarren/webgl-distort You can see them both running in the browser here with a standard input and output:
Thank you!!! |
If I use headlessgl like this: const gl = require('gl');
const context = gl(1,1);
const getPixels = require('get-pixels');
const fisheyeGL = require('../../src/fisheyegl.js');
getPixels('example/images/grid.png', function(err, pixels) {
if (err) {
console.log(err);
return;
}
fisheyeGL({
image: pixels.data,
getGLContext: () => context,
});
}); And in fisheyegl, if I force the flow to use the pixels lib mentioned above, and I change line 157 from: gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img); to:
I believe it works. Here is the full diff I did: diff --git a/src/fisheyegl.js b/src/fisheyegl.js
index db7369b..0117c63 100644
--- a/src/fisheyegl.js
+++ b/src/fisheyegl.js
@@ -41,7 +41,7 @@ var FisheyeGl = function FisheyeGl(options){
var image = options.image || "images/barrel-distortion.png";
var selector = options.selector || "#canvas";
- var gl = getGLContext(selector);
+ var gl = options.getGLContext ? options.getGLContext() : getGLContext(selector);
var shaders = require('./shaders');
@@ -172,7 +172,7 @@ var FisheyeGl = function FisheyeGl(options){
gl.bindTexture(gl.TEXTURE_2D, texture);
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, img);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); //gl.NEAREST is also allowed, instead of gl.LINEAR, as neither mipmap.
@@ -201,6 +201,13 @@ var FisheyeGl = function FisheyeGl(options){
return texture;
}
+ function loadImageFromPixels(gl, pixels, callback){
+ console.log('pixels', pixels);
+ var texture = gl.createTexture();
+ loadImage(gl, pixels, callback, texture);
+ return texture;
+ }
+
function run(animate, callback){
var f = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
@@ -272,7 +279,11 @@ var FisheyeGl = function FisheyeGl(options){
});
}
- setImage(image);
+ if (typeof image === 'string') {
+ setImage(image);
+ } else {
+ loadImageFromPixels(gl, image);
+ }
// asynchronous!
function getImage(format) { |
You'll notice I only had an image size of 1x1 above, so not a practical solution, but proof you can load in the pixels. |
Wow! Thanks @robertleeplummerjr |
https://www.npmjs.com/package/gl
This would no longer be pure JavaScript, but for some modules this is interesting. For example, the FisheyeGL module #27 can currently only be run in a browser, and webgl-distort #64 also would be this way.
Long-term project!
Hmm, maybe also these resources:
The text was updated successfully, but these errors were encountered: