2012-01-28 21:55:52 -05:00
|
|
|
// Shader based on work by Fabien Sanglard
|
|
|
|
// Released under the terms of CC-BY 3.0
|
2014-01-04 19:08:00 -05:00
|
|
|
#version 130
|
2012-01-28 21:55:52 -05:00
|
|
|
uniform sampler2D BumpTex1; // Normal map 1
|
|
|
|
uniform sampler2D BumpTex2; // Normal map 2
|
|
|
|
uniform sampler2D DecalTex; //The texture
|
|
|
|
|
|
|
|
uniform vec2 delta1;
|
|
|
|
uniform vec2 delta2;
|
|
|
|
|
2014-01-08 19:17:28 -05:00
|
|
|
noperspective in vec3 lightVec;
|
|
|
|
noperspective in vec3 halfVec;
|
|
|
|
noperspective in vec3 eyeVec;
|
|
|
|
in vec2 uv;
|
2012-01-28 21:55:52 -05:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
|
2014-01-19 12:53:35 -05:00
|
|
|
vec3 normal = 2.0 * texture (BumpTex1, uv + delta1).rgb - 1.0;
|
|
|
|
vec3 normal2 = 2.0 * texture (BumpTex2, uv + delta2).rgb - 1.0;
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2013-11-30 16:33:06 -05:00
|
|
|
// scale normals
|
|
|
|
normal.y = 4.0*normal.y;
|
|
|
|
normal2.y = 4.0*normal2.y;
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2012-01-28 21:55:52 -05:00
|
|
|
normal = (normalize(normal) + normalize(normal2))/2.0;
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2012-01-28 21:55:52 -05:00
|
|
|
// compute diffuse lighting
|
|
|
|
float lamberFactor = max (dot (lightVec, normal), 0.0);
|
|
|
|
vec4 diffuseMaterial;
|
|
|
|
vec4 diffuseLight;
|
|
|
|
|
2014-01-19 12:53:35 -05:00
|
|
|
diffuseMaterial = texture (DecalTex, uv + vec2(delta1.x, 0.0));
|
2013-11-30 16:33:06 -05:00
|
|
|
diffuseLight = vec4(1.0, 1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
vec3 col = diffuseMaterial.xyz * (0.3 + lamberFactor*0.7);
|
|
|
|
|
|
|
|
// specular (phong)
|
|
|
|
vec3 R = normalize(reflect(lightVec, normal));
|
|
|
|
float specular = max(dot(R, eyeVec), 0.0);
|
|
|
|
|
|
|
|
// weak specular
|
|
|
|
specular = specular*specular;
|
|
|
|
specular = specular*specular;
|
|
|
|
float specular_weak = specular*0.05;
|
|
|
|
col += vec3(specular_weak, specular_weak, specular_weak);
|
|
|
|
|
|
|
|
// strong specular
|
|
|
|
specular = specular*specular;
|
|
|
|
float specular_strong = specular*0.3;
|
|
|
|
col += vec3(specular_strong, specular_strong, specular_strong);
|
|
|
|
|
|
|
|
float summed = dot(vec3(1.0), col) / 3.0;
|
|
|
|
float alpha = 0.9 + 0.1 * smoothstep(0.0, 1.0, summed);
|
|
|
|
|
|
|
|
gl_FragColor = vec4(col, alpha);
|
2012-01-28 21:55:52 -05:00
|
|
|
}
|