Skip to content
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

OpenGL / WebGL in IHaskell? #619

Open
conal opened this issue Dec 11, 2015 · 9 comments
Open

OpenGL / WebGL in IHaskell? #619

conal opened this issue Dec 11, 2015 · 9 comments

Comments

@conal
Copy link

conal commented Dec 11, 2015

Has anyone hooked up OpenGL or WebGL with programmable shaders to work in IHaskell notebooks? I have an embedded compiler (i.e., for a "deep DSL embedding") from Haskell to GLSL, which I'd love to dust off and share.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@ghost
Copy link

ghost commented Dec 11, 2015

Great. That would be awesome.

IHaskell provides a mechanism to display custom data types through its IHaskellDisplay typeclass. Any data type with a valid IHaskellDisplay instance is displayed, in a manner similar to how ghci uses show, when evaluated in a cell.

I'll discuss this with the jupyter/IPython folks at https://gitter.im/ipython/ipython. It's possible that some work has been done to this end, and we might be able to use the frontend bits.

I've just begun learning about computer graphics, so your suggestion comes at a very good time for me 😄

@conal
Copy link
Author

conal commented Dec 11, 2015

I'm glad for the interest. My embedded compiler generates insanely fast shader code (assuming a GPU) as well as GUIs for interacting with them. It's essentially a modernized version of Pan and Vertigo. I implemented this newer compiler a few years back, but the sad state of basic GUI & graphics support in Haskell (cross-platform, ghci-friendly, and OpenGL-compatible) has prevented me from using it myself. Meanwhile, something in the low-level OpenGL code has bit rotted. I'd love to get help with setting up up-to-date OpenGL/WebGL mechanics for running shaders with GUIs. Then I can refactor my project to generate the GUIs and shaders from very high-level denotative/functional specifications (as in Pan & Vertigo) to use the updated OpenGL/WebGL layer. I expect the storage requirements for the rendered form to be quite small, while the visual quality will be have very high resolution spatially and temporally (since the representation intrinsically has infinite resolution in space and time). The Haskell representation would get "rendered" (via IHaskellDisplay) into GLSL code (to be rendered on the client's GPU) and a suitable representation of the GUI.

@gibiansky
Copy link
Member

It should be pretty straightforward to do this, if the GLSL code can run with WebGL. Generating JS and having it displayed is pretty easy.

Is that the goal? If so, I can give you a code snippet that will display a WebGL display as an output of a cell.

@conal
Copy link
Author

conal commented Dec 11, 2015

Yes, that's the goal, and the generated shaders do run with WebGL. With the basic WebGL mechanisms in place, I can then generate the shaders and GUI descriptions. The shaders are animated (via time and widgets), with updates communicated through GLSL uniform parameters. If you (or someone else) cooked up a simple example with hand-generated GUI and shader (connected via uniform parameters), I could probably take it from there.

@ghost
Copy link

ghost commented Dec 11, 2015

If so, I can give you a code snippet that will display a WebGL display as an output of a cell.

Yes, I'd like to try it out.

@conal
Copy link
Author

conal commented Jan 1, 2016

Has anyone made progress on using WebGL with IHaskell?

@ysangkok
Copy link

@gibiansky a code snippet that displays a WebGL display as an output of a cell would be swell...

@jamesdbrock
Copy link
Member

I would be very interested to see progress in this. Is your embedded compiler published anywhere @conal ? https://www.google.co.jp/search?q=conal+elliott+haskell+glsl+compiler

@conal
Copy link
Author

conal commented May 31, 2019

More recently, I reworked my Haskell-to-GLSL compiler as an instance of compiling-to-categories, with a few benefits:

  • Much simpler implementation (high performance without a deep DSL embedding).
  • Perfect API, as with a shallow embedding (but still generates optimized GPU code).
  • Easy integration with additional non-standard interpretations of Haskell code ("categories").
    In particular, the automatic differentiation interpretation enables correct and efficient lighting & shading via surface normals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants