Author: Tony Parisi
Reviewer: Mike James
Can you learn WebGL without getting involved in the very basic nuts and bolts like shaders and so on?
The big problem with WebGL is that it is very low level. If you are expecting to get involved with cameras and lights then think again. WebGL expects you to set up shaders, which are fairly complex programs in a C-like dialect to control how surfaces are rendered. This makes getting started with WebGL a slow and technical process.
Many programmers don't want or need to get into the powerful but difficult area of custom shaders - they just want to define and render 3D objects and create scenes that can be animated and used in games, simulations and so on. The problem is how to get them into WebGL?
This book takes the approach of augmenting WebGL with a 3D graphics engine - Three.js. What this means is that you work with 3D graphics in terms of meshes, cameras and lighting and so avoid the whole issue of shaders, which are provided for you by the engine. The only problem with this approach is if you actually want to master the low-level details of WebGL. Even if you do, starting off with a 3D graphics engine and finding out about shaders later on is still a good way into a complex subject.
However, it is important to realize that if you want an approach to WebGL that isn't based on Three.js you need a different book.
This said, the book does start off with an overview of WebGL and a simple program to draw a square. This is almost used as a motivation for adopting a 3D engine, as the next chapter introduces Three.js with a program that does the same thing in 30 lines as opposed to the original 150.
Next we move on to rendering a textured cube, something that usually takes a lot longer to reach taking the unaided route.
Chapter 3 uses a simple simulation example to introduce wider ideas on how to create meshes and textures. It also deals with particle systems and introduces custom shaders, but mostly concentrating on Three.js. From here we move on to animation in Chapter 4, again covering some basic principles, but quickly moving to Tween.js - a library that makes it all easy.
Next, Chapter 5 deals with hit detection and user interaction using Three.js. Chapter 6 is on integrating 2D and 3D graphics. Chapters 7 and 8 bring the book to a close, looking at WebGL in productions settings and creating a game.
As long as you are happy with using Three.js and can accept a fairly compact and advanced approach to 3D graphics, this is a good introduction to graphics based on WebGL and it should get you to the point where you can create your own game or simulation.