varying vec3 v;
varying vec2 t0;
void main()
{
gl_Position = ftransform();
v = vec3(gl_ModelViewMatrix * gl_Vertex);
t0 = gl_MultiTexCoord0.xy;
}
varying vec3 v;
varying vec2 t0;
uniform sampler2D textureMap;
uniform sampler2D normalMap;
void main()
{
vec3 lightVec = normalize(gl_LightSource[0].position.xyz - v);
vec3 normal =
gl_NormalMatrix *
(vec3(-1, 1, -1) *
normalize(texture2D(normalMap, t0).rgb * 2 - 1));
vec4 base = texture2D(textureMap, t0);
vec4 ambiantTerm =
gl_LightSource[0].ambient *
gl_FrontMaterial.ambient;
float diffuse = max(dot(normal, lightVec), 0.0);
vec4 diffuseTerm =
diffuse *
gl_LightSource[0].diffuse *
gl_FrontMaterial.diffuse;
float specular = pow(max(dot(reflect(lightVec, normal * 0.8), v), 0.0),
gl_FrontMaterial.shininess);
vec4 specularTerm =
specular *
gl_FrontMaterial.specular *
gl_LightSource[0].specular;
gl_FragColor =
ambiantTerm * base +
diffuseTerm * base +
specularTerm;
}
Aucun commentaire:
Enregistrer un commentaire