157
votes

I'm new and starting to learn about 3D computer graphics in web browsers. I'm interested in making 3D games in a browser. For anyone who has learned both WebGL and three.js...

  1. Is knowledge of WebGL required to use three.js?

  2. What are the advantages of using three.js vs. WebGL?

8
Use Three.js. Period. It is exactly what West says below, while simple in theory, writing WebGL from scratch is a pain. There are so many things that almost every WebGL application will need / want to do. These things can be abstracted away from you. Also, Three.js has matured into an amazing library. If you check Google Trends or the number of SO Questions here you will see that it has pulled far ahead of the competition.theblang
@GeorgeStocker Actually, the answers to this question have not been based primarily on opinion, but on facts, references, and specific expertise. This has been a valuable post for the there.js community, and part (2) of the question is certainly acceptable. How would you recommend rewording it so it is acceptable to you -- that is, without changing the meaning/intent of the question?WestLangley
@WestLangley I haven't heard anything but opinions in the answers given; not to mention "Pros and cons to using either [library]" is a bit too broad for Stack Overflow.George Stocker
@GeorgeStocker Your reply is itself an opinion, and I strongly disagree with it. How would you recommend rewording the post so it is acceptable to you?WestLangley
Perhaps the questions could be rephrased to ask how learning WebGL is beneficial to using Three.js. The answer to that would be supported by facts, references, and expertise.zz85

8 Answers

224
votes

Since you have big ambitions, you have to invest the time to learn the fundamentals. It is not a matter of what you learn first -- you can learn them simultaneously if you want to. (That's what I did.)

This means that you need to understand:

  1. WebGL concepts
  2. Three.js
  3. The underlying mathematical concepts

Three.js. Three.js does an excellent job of abstracting away many of the details of WebGL, so personally, I'd suggest using Three.js for your project. But remember, Three.js is in alpha, and it is changing frequently, so you have to be prepared for that. Most people learn Three.js by studying the examples. Avoid outdated books and tutorials, and avoid examples from the net that link to old versions of the library.

WebGL. If you use Three.js, you don't need to know how to program in WebGL, you just need to understand the WebGL concepts. That means, that you just need to be able to read someone else's WebGL code and understand what you read. That is a lot easier than being expected to write a WebGL program yourself from scratch. You can learn the WebGL concepts sufficiently well using any of the tutorials on the net, such as the beginner's tutorial at WebGLFundamentals.org and Learning WebGL.

Math. Again, you at least need to understand the concepts. Three good books are:

  1. 3D Math Primer for Graphics and Game Development by Fletcher Dunn and Ian Parberry

  2. Essential Mathematics for Games and Interactive Applications: A Programmer’s Guide by James M. Van Verth and Lars M. Bishop

  3. Mathematics for 3D Game Programming and Computer Graphics by Eric Lengyel

I hope this is helpful to you. Good luck.

25
votes

There is a very good online course - Interactive 3D Graphics at https://www.udacity.com/course/cs291 on THREE.js. This course includes assignments also to get hands-on experience. It covers all the basic concepts of Three.js and Computer Graphics

16
votes

My personal thoughts are the following:

  • If you have plenty time, you could learn both, but note that WebGL is much lower level than Three.js.
  • For a first 3d project, experts suggest using a library like Three.js in order to get used to the terms and the general 3d model.
12
votes

Whichever direction you choose to go, I suggest you learn/polish up on your linear algebra skills. Then go ahead and learn or polish up your understanding about MVP dimensions (Model View Projection). Three.JS can abstract much of that away, but I think it's key that one understands those concepts well before getting serious about any 3D development.

I wrote an introductory article about MVP when I was first learning 3D programming with OpenGL. I realized that until I was able to explain what those transformation matrices are, and how they relate to the various dimensions/spaces, I really didn't know any 3D programming at all, though I could render objects to the screen.

Since your goal is to create games, I think you'll benefit much from learning some raw WebGL first, even if you end up using a framework like Three.js to help you write your code later.

10
votes

"WebGL is a 2D API and not a 3D API"

http://webglfundamentals.org/webgl/lessons/webgl-2d-vs-3d-library.html

This article describes the fundamental differences between WebGL & 3d libraries like three.js.
Which made my choice between WebGL or Three.js a no-brainer.

6
votes

I came from a Unity3D background as well as Papervision3D back in the day, so I had a good understanding of how to deal with 3D space. Three.js is the way to go for your initial jump into learning how to deal with WebGL projects. The api is very good, it's very powerful and if you're coming from another 3D technology, you'll be up and running with very little time.

I spent a lot of time with Threejs.org's examples - there's a ton of them and they're very good at getting you off and running in the right direction. The docs are decent enough, especially if you're comparing them to other webGL 3D api's out there.

You might also consider getting the free version of Unity3D and the free collada (was free when I got it) exporter from their app store (Window>App store). I found it easy enough to setup my scene in Unity and export it to Collada for use with Three.js.

Also, I posted this class that I use with Three.js called neo ( http://rockonflash.com/webGL/three/neo.js ). Just add it to your project, then call Neo.JackIntoThree() and it will add the methods/properties to Object3D for use in your project. Things like DrawAllAxis() are invaluable when debugging your scene etc.

Hands down though, Three.js is a great way to go - it's flexible enough to let you write your own shaders/objects etc, and powerful enough right out of the box to help you accomplish your goals.

4
votes

I picked up three.js, but also jumped into GLSL and experimented a lot with three.js shaderMaterial. One way of going about it - three.js still abstracts much of the stuff for you, but it also gives you a very clean, low level access to all the rendering (projection, animation) capabilities.

This way, you can follow even something like this awesome open-gl tutorial. You don't have to set up the matrices, typed arrays, because three already sets it up for you, updating them when needed. The shader though, you can write from scratch - a simple color rendering would be two lines of GLSL. There is also a post processing plug-in for three.js that sets up all the buffers, full screen quads and stuff you need to do the effects, but the shader can be very simple to begin with.

Since programmable shaders are the essence of modern 3d graphics, i hope my answer is not missing the point :) Sooner or later, anyone who does this needs to at least understand what goes on under the hood, it's the nature of the beast. Also, understanding the 4th dimension in homogeneous space is probably important as well.

This book is good for WebGL.

2
votes

I just learnt a little of both and I feel that understand the basics of webgl, I think an introduction on webgl is sufficient and then jump into three js. It will be pretty easy once you understand the underlying concepts of WebGL. Useful links:

  1. Best Intro I have read: http://dev.opera.com/articles/view/an-introduction-to-webgl/
  2. Comprehensive tutorials: http://www.johannes-raida.de/tutorials.htm