A new approach to shape from shading is described based on a connection with a calculus of variations/optimal control problem. The approach leads naturally to an algorithm for shape reconstruction that is simple, fast, provably convergent, and, in many cases, provably convergent to the correct solution. In particular, if the surface is known to be locally concave (or convex) at a singular point in the image, then the algorithm provably reconstructs the correct surface in a region around the singular point. The algorithm is robust against noise and, in contrast with standard variational algorithms, does not require regularization. An explicit representation is given for the surface: its height is expressed as the minimal cost for an optimally controlled trajectory. This representation makes the convergence analysis for the algorithm transparent, and allows it to be easily adapted to different situations in practice. Uniqueness of the reconstruction (under suitable conditions) is an immediate consequence. We focus primarily on the case of illumination from the camera direction. For this case, if the singular points at which the surface is locally concave have been identified, and their heights are known, then the algorithm provably reconstructs the original imaged surface. For general direction of illumination, there is a representation of the surface in terms of a differential game, and a slightly modified surface reconstruction algorithm. Finally, given a continuous image, the algorithm can be proven to converge to the continuous surface solution as the image sampling frequency is taken to infinity.