3D on the Web
Shaders, meshes, and a solar system you can click.
This course has five pages that draw 3D graphics. Every one of them runs in a browser with nothing installed. The first two use no library at all. You write the two small programs that the graphics card runs, and you put a triangle on the screen yourself.
Then the course changes gear. The last three lessons use three.js, which is the library most 3D websites are built with. It writes those small programs for you. The point of doing it the hard way first is that you can tell what the library took off your hands, and you can work out what is wrong when a screen goes black.
Do the lessons in order. Each one gives you a copy of the page beside the guide. Change your copy and watch what happens.
The last three lessons fetch three.js from the internet the first time they run. If your school network blocks it, the first two lessons still work, because they depend on nothing.
- Who it's for
- Students who have finished JavaScript. The platformer course helps too, because it uses the same canvas and the same animation loop, but it is not required. You need to be comfortable with arrays, loops, and functions.
Lessons
Your First Triangle
One green triangle, drawn by the graphics card. You write the two programs that put it there.
<canvas> for WebGLgetContext("webgl")vertex shaderfragment shaderA Program Per Pixel
Two triangles covering the canvas, and one small program that paints every pixel of them.
varyingsuniforms over timeTRIANGLE_STRIPlength() and sin()Your First Scene
A lit cube turning in space, in about fifteen lines. Same graphics card, none of the shaders written by hand.
import mapsScenePerspectiveCameraWebGLRendererLight and Material
Four knots, the same shape and the same colour, with four different materials. A button turns the lamp off.
MeshBasicMaterialMeshStandardMaterialroughnesswireframeA World From An Array
Six planets orbiting a sun, none of them written by hand. Drag to look around. Click a planet to name it.
building objects in a loopGroupparentinguserData