2012-01-15 11:37:15 -05:00
|
|
|
// Shader based on work by Fabien Sanglard
|
|
|
|
// Released under the terms of CC-BY 3.0
|
2011-10-31 21:52:10 -04:00
|
|
|
|
|
|
|
uniform sampler2D BumpTex; //The bump-map
|
2012-01-15 11:37:15 -05:00
|
|
|
uniform sampler2D DecalTex; //The texture
|
2012-07-22 17:30:47 -04:00
|
|
|
uniform sampler2D LightMapTex;
|
|
|
|
int HasLightMap;
|
2012-01-15 11:37:15 -05:00
|
|
|
|
|
|
|
// New bumpmapping
|
|
|
|
varying vec3 lightVec;
|
|
|
|
varying vec3 halfVec;
|
|
|
|
varying vec3 eyeVec;
|
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
|
|
|
|
vec3 normal = 2.0 * texture2D (BumpTex, gl_TexCoord[0].st).rgb - 1.0;
|
|
|
|
normal = normalize (normal);
|
|
|
|
|
|
|
|
// compute diffuse lighting
|
2012-01-28 20:10:57 -05:00
|
|
|
float lamberFactor = max (dot (lightVec, normal), 0.0) ;
|
2012-01-15 11:37:15 -05:00
|
|
|
vec4 diffuseMaterial;
|
|
|
|
|
2012-01-28 20:10:57 -05:00
|
|
|
diffuseMaterial = texture2D (DecalTex, gl_TexCoord[0].st);
|
2012-01-15 11:37:15 -05:00
|
|
|
|
2012-07-22 17:30:47 -04:00
|
|
|
if (HasLightMap < 1)
|
|
|
|
{
|
|
|
|
// 0.5 is the ambient light
|
|
|
|
gl_FragColor = diffuseMaterial * (0.5 + lamberFactor*0.5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_FragColor = diffuseMaterial * (0.5 + lamberFactor*0.5) * texture2D(LightMapTex, gl_TexCoord[0].st);
|
|
|
|
}
|
2012-01-15 11:37:15 -05:00
|
|
|
}
|