programs in folder learnOpenGL2_p2B

This project has the translation of a number of C++ programs found in Part 2 (chapters 12 - 18) of the offline book that can be down loaded from www.learnOpenGL.com.

In the programs we will use the KeyInput, the Mouse and the Shader class that were also used at the end of Part 1. Our programs start with a number of includes of these classes. Also at the end of the programs we have akways similar code, used for the KeyInput and Mouse.

Chapter 14

Materials.ts

The translation poses no problems. We added two functions at the end for the setting of uniforms, one for setting 3d-vectors and the other for setting matrices.

We use Materials and Lights for the calculation of the color output. In the fragment shader fs_materials we find:

struct Material {
    vec3 ambient;
    vec3 diffuse;
    vec3 specular;    
    float shininess;
}; 

struct Light {
    vec3 position;

    vec3 ambient;
    vec3 diffuse;
    vec3 specular;
};

So, we use structs in our shader. In the program we set elements of the struct element by element e.g. lightingShader.setFloat3(gl, "light.ambient", 0.2, 0.2, 0.2);

After calculating diff = max((N.L), 0.0) and spec = (max((V.R), 0.0)^material.shininess; the resulting FragColor is found using:

ambient = light.ambient * material.ambient;
diffuse = light.diffuse * (diff * material.diffuse);
specular = light.specular * (spec * material.specular);
FragColor = ambient + diffuse + specular;

This is Phong shading. In Part 5, chapter 33 the Blinn-Phong shading is treated. It uses a different formula for the specular component.

Chapter 15

Lighting_maps_specular.ts

The translation poses no problems. The two used textures are normal PNG RGBA files.


date: 22 sept 2020. version: 1.00.
code found at: github.com/d3q3/LearnOpenGl
©Drikus Kleefsman