HTML and CSS Reference
Figure 11-2. 3D rotating cube (CH11EX1.html)
Shaders are pieces of code that run directly on a graphics card. They describe how a
scene —how you refer to a 3D canvas when working with WebGL—should be rendered.
Many of these little programs perform mathematical transformations that would oth-
of code will be read in like text files and passed to the graphics hardware. Full discus-
sions of topics like shaders are far out of scope for this little section of the topic, but
we will tell you a bit about each one of them to help set the tone for what comes next.
The first shader below is a fragment shader , which tells the graphics card that we will
be using floating-point numbers and blended colors. The second shader is the vertex
shader . It works with the vertices (defined points in 3D space used to create 3D objects)
and will be used for every vertex we draw onto the Canvas 3D context: