1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
varying vec3 normal , eyeVec;
void main()
{
vec4 diffuse = vec4 (0.0);
vec4 specular = vec4 (0.0);
float att = 0.0;
vec3 norm = normalize ( normal );
vec3 light = vec3( gl_LightSource[0].position.xyz + eyeVec );
light = normalize(light);
vec4 ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
float NdotL = abs(dot ( norm , light ));
if (NdotL > 0.0)
{
diffuse = (gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * NdotL) + gl_FrontMaterial.emission;
diffuse = (diffuse + diffuse*gl_FrontMaterial.emission)/2.0;
vec3 eye = normalize (eyeVec);
vec3 refl = reflect ( -light, norm);
float spec = max( dot ( refl , eye ), 0.0 );
spec = pow( spec , gl_FrontMaterial.shininess );
specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * spec;
float dist = length ( light );
att = 1.0 / (gl_LightSource[0].constantAttenuation + (gl_LightSource[0].linearAttenuation*dist) + (gl_LightSource[0].quadraticAttenuation*dist*dist) );
}
gl_FragColor = ambient + ( diffuse + specular) * att;
} |
Partager