07 Surfaces and light
From points to solid, then light the surface
Turn the switches on in order, or on their own to compare each step. The model turns slowly so front, back, light and shade are easy to see.
Exercise
Drag numbers, or edit the code
position → surfacevec3 p = vec3(aUv * 2.0 - 1.0, 0.0);gl_Position = P * V * M * vec4(p, 1.0);
M / V / P: model → camera → projection.
normal → base colourvec3 N = normalize(vNormal);vec3 base = vec3(0.48, 0.83, 0.69);
N is the surface’s facing; mapped to RGB you can see the direction.
light → shadingfloat diffuse = 1.0;float shine = 0.0;
L points at the light; H is halfway between light and view.
colour → outputvec3 color = base * diffuse + vec3(shine);gl_FragColor = vec4(color, 1.0);
Alpha, with blending, makes it transparent.
Vertex dots · light goes into the colour; JS decides which points form faces.
JS side
gl.uniformMatrix4fv(uModel, …) // rotation -0.35 / 0.10Review: position → triangles → normals → diffuse → specular → transparency; each step is one line of code.
Try it
- Turn the switches on from top to bottom