|WebGL Beginner's Guide|
Author: Diego Cantor and Brandon Jones
WebGL is growing in importance as a way of getting 3D graphics into web pages. The problem is that 3D is a tough subject, but this book is a beginner's guide - does it make things simple?
Learning to use 3D graphics was never easy because it involves all sorts of mathematical ideas - matrices, perspective transformations, quaternions, texture mapping and so on. The bad news is that 3D got a lot more complicated when the new graphics hardware introduced programmable pipelines. After this you not only had to master the basics of 3 geometry but the fine details of rendering. Put simply you had to write vertex and pixel shaders using a special shader language. This is fine if your aim is to create something unique, but if you just want to render a scene with a few lighting sources and a pretend you have a camera to specify the view, then it's a disaster. It raises the cost of getting started to a very high level.
A getting started book has two options to get around this problem. It can provide the reader with a standard shader that performs one of the well-known rendering algorithms. This effectively converts the situation back to a fixed pipeline - apart, of course, from the need to setup and load the shader code. The alternative is to explain in detail how shaders work and make managing them central to using 3D graphics.
The first method has the advantage of being easier, but there will come a day when you do have to master shader code.
This book tackles the whole problem head on and enables you to learn about shaders. It stars off with a gentle look at WebGL and its overall operating principles. If you download the code then you get to see an play with a 3D scene, even though at this point you have no idea how it all works.
From here we move on to look at the way geometry is specified and the use of buffer objects - a key idea in WebGL. However, we can't avoid considering the problem of the shader and how it makes use of vertex data. At the end there are some more examples that take you beyond the basics introduced in the chapter.
Chapter 3 is titled "Lights!" and it goes over the different types of lighting models that you can use: Gouraud, Phong, Lambertian and so on. This can be difficult reading if your math isn't up to it. At the end of the chapter we express these standard lighting models as shaders. Given that many will never want to use anything more than the Goraud or Phong models, the shaders introduced here are as far as you really need to go.
After "Lights!" you would expect "Camera" but Chapter 4 begins with the section "WebGL does not have cameras". The fact of the matter is that WebGl expects you to work with the fundamental transformation matrices to set up world and view positions. By the end of this chapter you will know how to setup the equivalent of a camera to render the scene using the matrices.
And of course Chapter 5 is called action and, yes, it is on animation. By the end of the chapter you have mastered the bouncing ball and interpolation.
Chapter 6 returns to more direct 3D concerns with a look at color, depth testing and alpha blending. This is really advanced lighting and rendering and Chapter 7 is on textures which is about as far as the subject goes. It explains the idea of texture mapping, i.e. u,v co-ordinates, in a very clear way and gets into the more advanced ideas such as Mipmapping.
Chapter 8 is about picking, i.e. letting the user interact with the 3D scene, which is more problematic than in 2D because the "pointer" may be over more than one visible object. Finally, we have a chapter on putting it all together and a chapter on advanced techniques.
Overall this is a really good book, but not for the 100% complete beginner. The topic is a tough one and, while the book does its best to make things as simple as possible, it is still not an easy read. I can imagine an approach that does simplify things by providing standard shaders that aren't explained until much later and by providing lots of boiler plate code that does standard tasks. However, the reader would have to come to terms with the details at some point.
This particular book makes you come to terms with the details at the earliest possible moment. If you can cope with this then it is a very good introduction to WebGL and at the end you will understand how it all works. If you are just looking for a book to get you started with 3D web-based games without learning how things work then you need a different book, and probably one on a game or physics engine.
As long as you are prepared for the technicalities this is an excellent introduction to WebGL.
|Last Updated ( Saturday, 08 September 2012 )|