I Phong illumination model

I.0. (Do it if you haven’t done previous exercises connected to shaders)

Took at the files shader_4_1.vert i shader_4_1.frag. Note how normal vectors are sent from vertex shader to fragment shader with variable interpNormal. Files shader_4_2.vert i shader_4_2.frag won’t be used for now.

I.1. Calculate diffuse Phong lightning intensity in the fragment shader:

  1. Send a light source. For now we will use directional light source, thus the light will be described by a unit vector:
  1. Calculate diffusion intensity in fragment shader:
  1. Use calculated intensity to modify object color:

I.2. Why spaceship illumination is not changing with rotation?

(Normal vectors are in local model space and the light direction vector is in world space)

All vertex normal vectors have to be transformed into world space:

I.3. Add specular Phong lighting to the model.

  1. Define a vector describing the view direction (it depends on the surface and camera positions):
  1. Calculate specular light intensity in the fragment shader:
  1. The shaded pixel color is: objectColor * diffuse + vec3(1.0) * specular. This describes the simplest case when the reflected light color is white.

I.4. Create planetary system - one stationary sphere in the center and a few orbiting planets. At least one planet should have some moons.

I.5. A planetary system should be lit by a sun, therefore change directional lighting to point lightning :

I.6. Light source is inside of the sphere that represents the sun, thus it is black. To fix it create another shader, that will be responsible for rendering the sun.

Goal of this exercise is to create a shader (shader_4_sun.vert_ i shader_4_sun.frag), that will be responsible only for rendering the sun. Previous shaders (shader_4_1.vert_ i shader_4_1.frag) should still render other objects.

  1. initialize program (shaders):
  1. Im more complex projects different types of objects are drawn with different shaders, thus architecture, that will allow it, is required in the application. Set appropriate program for sun rendering

-function drawObject uses the global function program, to point drawing shaders. Add a function argument, which should contain a program address used in rendering.

-add appropriate program to drawObject calls.

I.7.* Change sun shader to more realistic.

On the picture bellow you can see a sun. It is darker on the corners, try to get a similar effect. Vectors from previous points will be useful, especially normal vector and the vector V.