Back

Specular Control

Learn core lighting terms (diffuse/specular/rim) on a simple sphere.

Controlling the size and sharpness of a specular highlight comes down to this line:

Let's break it down.


What shininess does

shininess is the exponent passed to pow — it controls how tight and sharp the highlight appears:

  • shininess = 4 → large, soft highlight (matte rubber)
  • shininess = 16 → medium, like plastic
  • shininess = 64 → small, sharp (metallic paint)
  • shininess = 256 → tiny pinpoint (mirror or glass)

A larger exponent means only pixels very close to the perfect reflection angle keep any brightness — the bright spot shrinks and concentrates.


What the half-vector hV is

This tutorial uses the Blinn-Phong approach instead of computing a full reflection vector. The half-vector sits midway between the light direction l and the view direction v:

Add the two directions together and normalize. Then check how well the surface normal n aligns with hV — better alignment means a brighter highlight.

Blinn-Phong is cheaper to compute than classic Phong and behaves more stably when the viewer is at a grazing angle.


Try changing it

ChangeEffect
shininess = 16.0 to 4.0Large, soft highlight — rubber-like surface
shininess = 16.0 to 64.0Small, tight highlight — smooth surface
Change 0.6 in * spec * 0.6 to 1.5Brighter specular, may clip to white

Exercise

The exercise has spec = 0.0 and no visible highlight. Fill in the TODO to compute the specular value using hV and shininess.

Answer Breakdown

Starting state: spec = 0.0 — the sphere shows only diffuse shading.

The fix: compute dot(n, hV) to measure how well the normal aligns with the half-vector, then raise it to shininess to concentrate the result into a tight highlight. shininess = 16.0 gives a medium-smooth plastic appearance.

Try changing shininess to 2.0 and see how far the highlight spreads across the sphere.

Functions used in this lesson

Before this lesson

GLSL Code Editor

Correct Code Preview

Current Code Preview