How to do it...

Using the same shader pair as in the recipe Using per-fragment shading for improved realism, replace the phongModel function in the fragment shader with the following:

vec3 blinnPhong( vec3 position, vec3 n ) { 
vec3 ambient = Light.La * Material.Ka;
vec3 s = normalize( Light.Position.xyz - position );
float sDotN = max( dot(s,n), 0.0 );
vec3 diffuse = Material.Kd * sDotN;
vec3 spec = vec3(0.0);
if( sDotN > 0.0 ) {
vec3 v = normalize(-position.xyz);
vec3 h = normalize( v + s );
spec = Material.Ks *
pow( max( dot(h,n), 0.0 ), Material.Shininess );
}
return ambient + Light.L * (diffuse + spec);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.114.125