Getting ready

We'll set up our shader by starting with the shader pair from the Blinn-Phong recipe, but we'll change the fragment shader. Let's set up some uniforms for the light and material information.

For the light sources, we just need a position and an intensity:

uniform struct LightInfo {  vec4 Position; // Light position in cam. coords.  vec3 L;        // Intensity} Light[3];

For materials, we need the three values mentioned previously:

uniform struct MaterialInfo {  float Rough;  // Roughness  bool Metal;   // Metallic (true) or dielectric (false)  vec3 Color;   // Diffuse color for dielectrics, f0 for metallic} Material;

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.