Graphics Reference
In-Depth Information
vec3 ambient = vColor.rgb;
float dl = dot( That, Lhat );
vec3 diffuse = sqrt( 1. - dl*dl ) * vColor.rgb;
float de = dot( That, Ehat );
vec3 spec = uLightColor * pow(dl * de +
sqrt(1. - dl*dl) * sqrt(1. - de*de), uShininess);
fFragColor = vec4( uKa*ambient + uKd*diffuse + uKs*spe, 1. );
Exercises
1. Compare the tradeoffs between granularity and shading quality, spe-
cifically between smooth and Phong shading. Create a model with a
granularity you can adjust, and see if you can identify the granularity of
smooth shading that is indistinguishable from Phong shading.
2. In the text, we say that the specular light computation using the reflec-
tion vector gives you a smaller specular highlight than the computation
using the half-angle vector when the same specularity exponent is used.
Modify the ADS lighting function in the text to use the half-angle formu-
lation, and verify this statement. Add a slider for the shininess exponent
to the GLIB file for the Phong shader, and see if you can quantify the rela-
tion between the exponents for the two formulations that give the same
look.
3. Modify the ADS light function to use homogeneous vector computations
throughout. Is this enough to make it work with directional as well as
positional lights? If not, modify it further to support directional lights.
4. In the spotlight example in the text, we simply used ambient and dif-
fuse light. Modify this shader to use the ADS light function and compute
specular light as well.
5. Suppose that you had a material that reflected light from a sphere differ-
ently from the anisotropic example above: the light is reflected in a direc-
tion tangent to the sphere toward the poles. Write a shader to implement
this kind of lighting.
Search WWH ::




Custom Search