Graphics Reference
In-Depth Information
Figure 16.8. A diagram of a concave lens.
For a concave lens, shown in Figure 16.8, the normals point towards
the centerline - z , and so rays of light from the eye are directed farther from
the centerline rather than toward it. This has the effect of making things seen
through the lens seem smaller.
In the next few figures, we will show how these lens behaviors are trans-
lated into actual images by GLSL shaders. In Figure 16.9, we see a scene in
which the object we are looking at is in front of the lens's convergence point.
The objects we see through the lens are upright and are magnified.
In contrast to Figure 16.9, we see in Figure 16.10 that if an object lies
behind the convergence point, it is inverted when viewed through the lens.
The magnification effect is not as strong here, and you begin to see some fish-
eye magnification lens effect within the area of the lens.
For a concave lens, as shown in Figure 16.11, we see an upright image,
but the area within the image is seen as smaller than its actual size. We also see
a fish-eye lens effect in this lens that reduces objects' size as rays toward the
edge of the lens are bent more than rays toward its center.
The actual shader code for vertex and fragment shaders is shown below.
First we include the vertex shader code, because it must compute the refraction
vector for the lens as well as the familiar gl_Position value. In this example,
you could let uR1 and uR2 be glman slider variables so you could experiment
with the effect of lenses with different shapes.
Search WWH ::




Custom Search