Advanced Computer Graphics: Laboratory Project

<< PREV | INDEX | NEXT >>

Task 2E: Add a Fresnel Term

Preparation

Locate $TASK 2E in the CgFX file 'carscene-2.fx' (two places in fragment shader).

Description

The reflection implemented in the previous tasks looks a bit odd. The cause of this is that the amount of reflected light to the viewer does not change with the angle between the viewer and the normal of the surface. The reflection can be enhanced by adding the so called fresnel term. The fresnel term describes the amount of light reflected to the viewer and the amount of light refracted when it strikes the surface of a material.

The maximum amount of light is reflected when the normal of the surface is perpendicular to the eye vector, and the minimum amount of light is reflected when the normal of the surface is parallell to the eye vector. For more information on fresnel reflection, its equation, and usable approximations refer to the technical report 'Fresnel Reflection' by Matthias Wloka.

In this task, we will use Schlick's approximation:

R(a) = R(0) + (1.0 - R(0)) * (1.0 - cos(a))5
R(0) = (n1 - n2)2 / (n1 + n2)2

Where a is the angle between the eye vector (the vector from the surface to the eye) and the surface normal. R(0) is the fresnel reflection for zero angle a, n1 is the index of refraction of the material from which light comes (commonly air or vacuum), and n2 is the refraction index of the surface material. For example, a vacuum has a refraction index of 1.0, air is 1.000293, water is 1.333333, and diamond is 2.417.

For high values of a, refraction will decrease as we approach total reflection. To achieve this effect in our shader we will have to modify the alpha value of the fragments so that we take into account the effects of fresnel reflection. A simple way to do this is to add the fresnel term to the alpha value of the fragment output color.

Hint

Calculate the fresnel value in the fragment shader. The fresnel term is used to modify the glossiness value. The variable R0 in the fragment shader is the R(0) value for a typical glass surface in air.

Build/run the application when you think you have completed this task. Note the effect of total reflection when looking at the windows of the car when they are parallell to the view vector.


<< PREV | INDEX | NEXT >>