WebGL backend for Sage plot3d

84 views
Skip to first unread message

Carl Witty

unread,
Jul 19, 2010, 5:05:24 PM7/19/10
to sage-n...@googlegroups.com, sage-devel
I've created a proof-of-concept WebGL backend for Sage plot3d in the
notebook; if you have a WebGL-enabled browser, see
http://sagenb.org/home/pub/2263/ . And if you don't have a
WebGL-enabled browser, you should get one; see
http://learningwebgl.com/blog/?p=11 .

WebGL is an emerging standard for doing hardware-accelerated 3D
graphics directly in the browser (no plugins). Firefox 4 beta 1 and
the latest version of Chrome both support it on Linux, OSX, and
Windows, if you have sufficiently good OpenGL support. (People are
working on a Direct3D backend for use in the web browsers; hopefully
in a few months, WebGL will work on Windows without OpenGL.) For both
Firefox and Chrome, you need to explicitly enable WebGL; see the above
link for details.

I'm excited about WebGL; I think it has promise to be the primary Sage
graphics interface in the notebook (although not this year, and maybe
not next year).

My current code is buggy, ugly, and limited. I plan to keep working
on it (well, basically rewrite it from scratch); if people are
interested in collaborating, let me know.

I'm sending this email to both sage-notebook and sage-devel.
Presumably any technical discussion should be on sage-notebook.

Carl

William Stein

unread,
Jul 19, 2010, 5:16:19 PM7/19/10
to sage-n...@googlegroups.com
On Mon, Jul 19, 2010 at 11:05 PM, Carl Witty <carl....@gmail.com> wrote:
> I've created a proof-of-concept WebGL backend for Sage plot3d in the
> notebook; if you have a WebGL-enabled browser, see
> http://sagenb.org/home/pub/2263/ .  And if you don't have a
> WebGL-enabled browser, you should get one; see
> http://learningwebgl.com/blog/?p=11 .
>
> WebGL is an emerging standard for doing hardware-accelerated 3D
> graphics directly in the browser (no plugins).  Firefox 4 beta 1 and
> the latest version of Chrome both support it on Linux, OSX, and

Note -- you need Chromium on OS X, not Chrome: "The way the Chrome
developers currently recommend you get WebGL in Chrome is to use a
nightly build of Chromium, the open source browser on which Chrome is
based."


> Windows, if you have sufficiently good OpenGL support.  (People are
> working on a Direct3D backend for use in the web browsers; hopefully
> in a few months, WebGL will work on Windows without OpenGL.)  For both
> Firefox and Chrome, you need to explicitly enable WebGL; see the above
> link for details.
>
> I'm excited about WebGL; I think it has promise to be the primary Sage
> graphics interface in the notebook (although not this year, and maybe
> not next year).
>
> My current code is buggy, ugly, and limited.  I plan to keep working
> on it (well, basically rewrite it from scratch); if people are
> interested in collaborating, let me know.
>
> I'm sending this email to both sage-notebook and sage-devel.
> Presumably any technical discussion should be on sage-notebook.
>
> Carl
>

--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Jason Grout

unread,
Jul 20, 2010, 1:19:41 AM7/20/10
to sage-n...@googlegroups.com
On 7/19/10 2:05 PM, Carl Witty wrote:
> I've created a proof-of-concept WebGL backend for Sage plot3d in the
> notebook; if you have a WebGL-enabled browser, see
> http://sagenb.org/home/pub/2263/ . And if you don't have a
> WebGL-enabled browser, you should get one; see
> http://learningwebgl.com/blog/?p=11 .
>
> WebGL is an emerging standard for doing hardware-accelerated 3D
> graphics directly in the browser (no plugins). Firefox 4 beta 1 and
> the latest version of Chrome both support it on Linux, OSX, and
> Windows, if you have sufficiently good OpenGL support. (People are
> working on a Direct3D backend for use in the web browsers; hopefully
> in a few months, WebGL will work on Windows without OpenGL.) For both
> Firefox and Chrome, you need to explicitly enable WebGL; see the above
> link for details.
>
> I'm excited about WebGL; I think it has promise to be the primary Sage
> graphics interface in the notebook (although not this year, and maybe
> not next year).

I am extremely excited about WebGL as well. A few months ago, I started
discussing things with the person that developed WebGLot
(http://dan.lecocq.us/wordpress/tag/webglot/), but our discussions are
stalled while he is investigating getting permission from his university
to release the code.

I currently investigate WebGL code using the OSX version of the WebKit
Nightly:

http://nightly.webkit.org/

(see the instructions on http://learningwebgl.com/blog/?p=11 that cwitty
pointed out)

(hmm...except for some reason, I seem to be getting errors

Carl: have you seen the sympy OpenGL plotting code?


>
> My current code is buggy, ugly, and limited. I plan to keep working
> on it (well, basically rewrite it from scratch); if people are
> interested in collaborating, let me know.

Definitely interested in at least keeping tabs on it, and depending on
my time, helping with it. I'd also love to get some students involved
in it too.

I should note that we should also test the practically-finished changes
that Jonathan Gutow has made to the JMOL interface in Sage. The changes
polish a lot of things in the JMOL interface, and we will likely have
the JMOL interface for a long time, especially for browsers/computers
that don't support webgl.

Thanks,

Jason

Jason Grout

unread,
Jul 20, 2010, 1:49:30 AM7/20/10
to sage-n...@googlegroups.com
On 7/19/10 10:19 PM, Jason Grout wrote:

> (hmm...except for some reason, I seem to be getting errors
>


I mentioned the error on IRC, and Carl fixed it in about 2 minutes. It
looks great in the webkit nightly now!

Thanks,

Jason

Carl Witty

unread,
Jul 20, 2010, 1:54:31 AM7/20/10
to sage-n...@googlegroups.com
On Mon, Jul 19, 2010 at 10:19 PM, Jason Grout
<jason...@creativetrax.com> wrote:
> (hmm...except for some reason, I seem to be getting errors)

There was a bug in the GLSL code (that runs on the graphics card). My
nvidia driver is evidently more forgiving than Jason's driver.

> Carl: have you seen the sympy OpenGL plotting code?

I haven't looked at it recently.

I think the first step is to get a solid plot3d backend, so all I need
to do is display triangles (and, ideally, lines, points, and text) --
Sage does all the plotting.

> Definitely interested in at least keeping tabs on it, and depending on my
> time, helping with it.  I'd also love to get some students involved in it
> too.

I spent the day looking at Javascript scene graph libraries.
Hopefully a good library will let us get the plot3d backend done
quickly and move on the the fun stuff, like plotting directly in the
browser (so some interactive things can happen without the server
round-trip).

My current favorite is SceneJS.

(I'm talking to Jason on IRC right now about how to work together.)

Carl

William Stein

unread,
Jul 20, 2010, 5:25:43 AM7/20/10
to sage-n...@googlegroups.com
Hi,

I've posted a little screencast:

http://sage.math.washington.edu/home/wstein/tmp/webgl.mov

--

kcrisman

unread,
Jul 20, 2010, 6:05:57 PM7/20/10
to sage-notebook


On Jul 20, 5:25 am, William Stein <wst...@gmail.com> wrote:
> Hi,
>
> I've posted a little screencast:
>
>    http://sage.math.washington.edu/home/wstein/tmp/webgl.mov
>

This is really nice. There is obviously a lot to add (would axes be
easy?) but having an embarrassment of riches on backends is wonderful.

- kcrisman

Carl Witty

unread,
Jul 20, 2010, 6:31:11 PM7/20/10
to sage-n...@googlegroups.com

My current plan is to rewrite it using SceneJS (scenejs.org), and
support the complete list of plot3d primitives (IndexFaceSet, Point,
Line, Text). Then axes should work.

I don't think this will take very long (days or weeks, not months).

Carl

Ondrej Certik

unread,
Jul 21, 2010, 3:01:12 AM7/21/10
to sage-n...@googlegroups.com
Hi Carl,

this is awesome, what you did! It actually does something for me
(unlike the jmol, that never really worked for me). I use the latest
google chrome in ubuntu karmic. I start it with

google-chrome --enable-webgl

and I can see one triangle. I run William's movie and in there I can
see a nice surface plot. So I can't see that, but just the fact, that
I can see some 3D things is a progress. I have spent a day trying to
get this running on my linux about two months ago and just gave up (I
tried both firefox and chrome and chromium).

More below:

On Mon, Jul 19, 2010 at 10:54 PM, Carl Witty <carl....@gmail.com> wrote:
> On Mon, Jul 19, 2010 at 10:19 PM, Jason Grout
> <jason...@creativetrax.com> wrote:
>> (hmm...except for some reason, I seem to be getting errors)
>
> There was a bug in the GLSL code (that runs on the graphics card).  My
> nvidia driver is evidently more forgiving than Jason's driver.
>
>> Carl: have you seen the sympy OpenGL plotting code?
>
> I haven't looked at it recently.

We use pyglet, so I think that is not so useful for the browser,
unless you mean something else.

I would love to use just some gui in the browser.

>
> I think the first step is to get a solid plot3d backend, so all I need
> to do is display triangles (and, ideally, lines, points, and text) --
> Sage does all the plotting.
>
>> Definitely interested in at least keeping tabs on it, and depending on my
>> time, helping with it.  I'd also love to get some students involved in it
>> too.
>
> I spent the day looking at Javascript scene graph libraries.
> Hopefully a good library will let us get the plot3d backend done
> quickly and move on the the fun stuff, like plotting directly in the
> browser (so some interactive things can happen without the server
> round-trip).
>
> My current favorite is SceneJS.
>
> (I'm talking to Jason on IRC right now about how to work together.)

It'd be cool to have some python library that people could use in
their projects, if it's not so much more work. I guess if it's going
to be part of the notebook, then that should be ok.

SceneJS looks cool.

Ondrej

Carl Witty

unread,
Jul 21, 2010, 4:41:46 PM7/21/10
to sage-n...@googlegroups.com
On Wed, Jul 21, 2010 at 12:01 AM, Ondrej Certik <ond...@certik.cz> wrote:
> Hi Carl,
>
> this is awesome, what you did! It actually does something for me
> (unlike the jmol, that never really worked for me). I use the latest
> google chrome in ubuntu karmic. I start it with
>
> google-chrome --enable-webgl
>
> and I can see one triangle. I run William's movie and in there I can
> see a nice surface plot. So I can't see that, but just the fact, that
> I can see some 3D things is a progress. I have spent a day trying to
> get this running on my linux about two months ago and just gave up (I
> tried both firefox and chrome and chromium).

Have you tried --no-sandbox? Evidently that works around some bugs
for some people. (I haven't needed to try it myself.) You could also
try Firefox 4 beta 1.

> More below:
>
> On Mon, Jul 19, 2010 at 10:54 PM, Carl Witty <carl....@gmail.com> wrote:
>> On Mon, Jul 19, 2010 at 10:19 PM, Jason Grout
>> <jason...@creativetrax.com> wrote:
>>> Carl: have you seen the sympy OpenGL plotting code?
>>
>> I haven't looked at it recently.
>
> We use pyglet, so I think that is not so useful for the browser,
> unless you mean something else.

Well, for the next stage, I'll be using Sage's plotting, so sympy
isn't relevant.

It's possible that in the future, I would try to improve the look of
Sage's plots; and I do like the look of sympy's default plots (pastel
colors, no lighting, axes always visible). I would be looking at
sympy more as a source of inspiration than direct implementation tips.

> I would love to use just some gui in the browser.

I didn't understand this sentence.

> It'd be cool to have some python library that people could use in
> their projects, if it's not so much more work. I guess if it's going
> to be part of the notebook, then that should be ok.

Well, my tentative plan is to write a Javascript library that takes a
JSON encoding of Sage's plot3d primitives (IndexFaceSet, Point, Line,
Text) and displays it. The only Python code I plan to write is a
small addition to sage.plot.plot3d to add an easy-to-process JSON
encoding. If other people wanted to use the library, they would only
need to produce the JSON encoding for their data structures. I don't
think there's much point in a 3D-JSON-encoding library; it would be as
much work to translate into the library's format as it would be to
translate to JSON directly.

Carl

Ondrej Certik

unread,
Jul 21, 2010, 5:21:10 PM7/21/10
to sage-n...@googlegroups.com
On Wed, Jul 21, 2010 at 1:41 PM, Carl Witty <carl....@gmail.com> wrote:
> On Wed, Jul 21, 2010 at 12:01 AM, Ondrej Certik <ond...@certik.cz> wrote:
[...]

>> I would love to use just some gui in the browser.
>
> I didn't understand this sentence.

I wanted to say that I would much prefer to get rid of our custom
pyglet based plotting and just use a 3D plotting based on your library
and just use a browser for interacting with the plot.

>
>> It'd be cool to have some python library that people could use in
>> their projects, if it's not so much more work. I guess if it's going
>> to be part of the notebook, then that should be ok.
>
> Well, my tentative plan is to write a Javascript library that takes a
> JSON encoding of Sage's plot3d primitives (IndexFaceSet, Point, Line,
> Text) and displays it.  The only Python code I plan to write is a
> small addition to sage.plot.plot3d to add an easy-to-process JSON
> encoding.  If other people wanted to use the library, they would only
> need to produce the JSON encoding for their data structures.  I don't
> think there's much point in a 3D-JSON-encoding library; it would be as
> much work to translate into the library's format as it would be to
> translate to JSON directly.

Yes, definitely. That's a good plan.

Ondrej

Jonathan

unread,
Jul 24, 2010, 12:21:46 AM7/24/10
to sage-notebook
As long as your plots do not get too complicated, you may be able to
dispense with Jmol. However, in the Jmol community we have been
trying to see if we could use some of the 3D capabilities within
browsers for molecular graphics and it has been way too lethargic.
Using something that all standards compliant browsers can handle
without a plugin would have some significant advantages if the
response times are fast enough. I encourage people to keep pursuing
this.

In the meantime. If somebody with more extensive knowledge of the
python in the Sage Plotting packages is willing to work with me on
generating more complex data files for Jmol it would not be hard to
implement the following types of plots in Jmol:
1) 3D plots that are time dependent (eg 4d or animations)
2) vector fields (3d position, 3d direction/magnitude)
3) 3d projections out of n-d spaces.
4) We're also working on a slicer.

Jonathan

PS. I get the impression that some people are still having difficulty
getting Jmol to work on some Linux systems. If so please let me know
what is going on. If you can get the Sun/Oracle Java installed it
should work.

On Jul 21, 4:21 pm, Ondrej Certik <ond...@certik.cz> wrote:

Jonathan

unread,
Jul 24, 2010, 12:43:59 AM7/24/10
to sage-notebook
Note on Jmol:
3-D plots in Jmol would also work better with a more recent version of
Jmol than is currently folded into Sage. Follow the instructions in
the trac #9238:
http://trac.sagemath.org/sage_trac/ticket/9238
to get an update to Jmol as well as some interface enhancements and a
fix to Jmol not launching from the command line.

Jonathan

Ondrej Certik

unread,
Jul 24, 2010, 11:01:07 AM7/24/10
to sage-n...@googlegroups.com
On Fri, Jul 23, 2010 at 9:21 PM, Jonathan <gu...@uwosh.edu> wrote:
> As long as your plots do not get too complicated, you may be able to
> dispense with Jmol.  However, in the Jmol community we have been
> trying to see if we could use some of the 3D capabilities within
> browsers for molecular graphics and it has been way too lethargic.
> Using something that all standards compliant browsers can handle
> without a plugin would have some significant advantages if the
> response times are fast enough.  I encourage people to keep pursuing
> this.
>
> In the meantime.  If somebody with more extensive knowledge of the
> python in the Sage Plotting packages is willing to work with me on
> generating more complex data files for Jmol it would not be hard to
> implement the following types of plots in Jmol:
> 1) 3D plots that are time dependent (eg 4d or animations)
> 2) vector fields (3d position, 3d direction/magnitude)
> 3) 3d projections out of n-d spaces.
> 4) We're also working on a slicer.
>
> Jonathan
>
> PS.  I get the impression that some people are still having difficulty
> getting Jmol to work on some Linux systems.  If so please let me know
> what is going on.  If you can get the Sun/Oracle Java installed it
> should work.

I am running Ubuntu Karmic and I am attaching a screenshot what
happens if I use plot3d in Chrome. A new window pops up with some
java, but the applet never loads and in a while the page crashes. Here
are the java packages that I have installed:

waj ondrej@crow:~$ wajig list java
ii ca-certificates-java 20090928
Common CA certificates (JKS
keystore)
ii java-common
0.30ubuntu5 Base of all Java
packages
ii libaccess-bridge-java
1.26.2-1ubuntu1 Java Access Bridge
for GNOME
ii libaccess-bridge-java-jni
1.26.2-1ubuntu1 Java Access Bridge
for GNOME (jni bindings)
ii libecj-java
3.5.1-0ubuntu1 Eclipse Java compiler
(library)
ii libecj-java-gcj
3.5.1-0ubuntu1 Eclipse Java compiler
(native library)
ii libequinox-osgi-java
3.5.1+repack~1-0ubuntu4 Equinox OSGi
framework
ii libjaxp1.3-java
1.3.04-5ubuntu2 Java XML parser and
transformer APIs (DOM, S
ii libjline-java
0.9.94-5~ubuntu1 Java library for
handling console input
ii libswt-gtk-3.5-java
3.5.1+repack~1-0ubuntu4 Standard Widget
Toolkit for Java, GTK+ versi
ii libxerces2-java
2.9.1-4ubuntu1 Validating XML parser
for Java with DOM leve
ii tzdata-java
2010j-0ubuntu0.9.10 time zone and
daylight-saving time data for
rc gjdoc 0.7.9-4.1
documentation generation
framework for java
rc libantlr-java-gcj
2.7.7-11ubuntu2 language tool for
constructing recognizers,
rc libjaxp1.3-java-gcj
1.3.04-5ubuntu2 Java XML parser and
transformer APIs (DOM, S
rc liblog4j1.2-java-gcj
1.2.15-4ubuntu1 Logging library for
java (native code)
rc libxerces2-java-gcj
2.9.1-4ubuntu1 Validating XML parser
for Java with DOM leve

If you can tell me which package exactly I should install to make this
work, that'd be awesome.

Ondrej

Screenshot.png

Ondrej Certik

unread,
Jul 24, 2010, 11:13:27 AM7/24/10
to sage-n...@googlegroups.com

Ok, I am installing sun-java6-jre, from multiverse, which means it's
not an opensource software, so I had to agree to some licence that I
don't agree with, for example I had to agree with:

"
you do not combine, configure or distribute
the Software to run in conjunction with any additional software
that implements the same or similar functionality or APIs as the
Software;
"

and bunch of things like this. Btw, I just violated the licence by
combining their software with other java software that I have on my
laptop....


But now it works! Wow, it's pretty impressive, it's fast.

But as I said, I am not going to violate their licence, so I just
removed the java package from my system.

Ondrej

Harald Schilly

unread,
Jul 24, 2010, 12:24:09 PM7/24/10
to sage-n...@googlegroups.com
On Sat, Jul 24, 2010 at 17:13, Ondrej Certik <ond...@certik.cz> wrote:
> Ok, I am installing sun-java6-jre ...

I wouldn't use that either and I'm using openjdk-6-jre / -jdk /-...
and the icedtea6-plugin ("web browser plugin based on OpenJDK and
IcedTea to execute Java applets") which is in my eyes the way that
should be recommended on ubuntu & similar.

H

Ondrej Certik

unread,
Jul 24, 2010, 1:47:51 PM7/24/10
to sage-n...@googlegroups.com

Yes, those are the packages that I already have installed:

ondrej@crow:~$ wajig list jdk
ii openjdk-6-jdk
6b18-1.8-4ubuntu3~9.10.2 OpenJDK Development
Kit (JDK)
ii openjdk-6-jre
6b18-1.8-4ubuntu3~9.10.2 OpenJDK Java runtime,
using Hotspot JIT
ii openjdk-6-jre-headless
6b18-1.8-4ubuntu3~9.10.2 OpenJDK Java runtime,
using Hotspot JIT (hea
ii openjdk-6-jre-lib
6b18-1.8-4ubuntu3~9.10.2 OpenJDK Java runtime
(architecture independe
ondrej@crow:~$ wajig list iced
ii icedtea-6-jre-cacao
6b18-1.8-4ubuntu3~9.10.2 Alternative JVM for
OpenJDK, using Cacao
ii icedtea6-plugin
6b18-1.8-4ubuntu3~9.10.2 web browser plugin


based on OpenJDK and Iced

And this produces that screenshot that I posted. It doesn't work.

It has never worked for me. I think I have actually reported this
problem to both jmol and Debian before and the conclusion was that
Debian/Ubuntu guys told me that jmol is broken and jmol guys told me
that the openjdk in Debian is broken and doesn't support something.

But anyway, I am giving up on java and I'll wait for opengl.

Ondrej

Jonathan

unread,
Jul 25, 2010, 3:05:59 PM7/25/10
to sage-notebook


On Jul 24, 10:13 am, Ondrej Certik <ond...@certik.cz> wrote:

> Ok, I am installing sun-java6-jre, from multiverse, which means it's
> not an opensource software, so I had to agree to some licence that I
> don't agree with, for example I had to agree with:
>
> "
> you do not combine, configure or distribute
>     the Software to run in conjunction with any additional software
>     that implements the same or similar functionality or APIs as the
>     Software;
> "
>
> and bunch of things like this. Btw, I just violated the licence by
> combining their software with other java software that I have on my
> laptop....
No, I don't think you have. What they mean by that is that you cannot
redistribute the sun java yourself as part of a package. Users must
get it from Sun/Oracle. The API functionality stuff is strange, but I
think would only cause problems if you are running it in conjunction
with other software that utilizes the Java to provide machine
independent APIs that do no more than duplicate the Java APIs.

>But as I said, I am not going to violate their licence, so I just
> removed the java package from my system.
If I were you, I would use the Sun/Oracle Java until the versions with
licenses you like better actually work for what you want. In the
meantime you should be reporting to the developers that they don't
work and how.

Jonathan
Reply all
Reply to author
Forward
0 new messages