Software Surfaces of Revolution

Surfaces of Revolution

A cylinder and a wavy vase, each generated from a curve spun around an axis and lit per pixel with Phong shading. Orbit them, change the material, move the light, and push the shininess from matte to mirror.

Your browser does not support the HTML5 canvas element.

Drag to orbit

How it works

Each surface starts as a 2D generating curve in the xy-plane. Sweeping that curve around the y-axis produces a grid of 3D points, and a triangle index list stitches the grid into a mesh.

  • Parametric geometry. The cylinder has a constant radius. The vase's radius is a sum of cosine and sine terms along its height. Both meshes are built from a 90 × 70 grid of samples by code in a separate geometry module.
  • Exact normals. Normals come from the cross product of the surface's partial derivatives rather than being averaged from neighboring faces. Turn on Show surface normals to see them drawn as short lines.
  • Indexed drawing. Positions and normals live in vertex buffers, and an index buffer drives drawElements.
  • Phong shading per pixel. The fragment shader evaluates ambient, diffuse, and specular terms for every pixel, using each material's colors and the shininess exponent.
  • Light and camera. The light either rides at the camera or circles the object. The camera orbits with yaw and pitch from mouse drags, and the near and far planes are derived from each mesh's bounding box. The field of view is adjustable from 10° to 100°.

Concepts

  • Parametric surfaces
  • Analytic normals
  • Indexed triangle meshes
  • Phong illumination
  • Per-fragment shading
  • Camera orbit

Built with

  • WebGL
  • GLSL
  • JavaScript

Background

Written for CSE 470, Introduction to Computer Graphics, at Arizona State University. Uses the course-supplied webgl-utils and MV.js helper libraries.