hemilight.vs
Code:
// $Id$
//
// Vertex shader for hemispherical lighting
//
// Author: Randi Rost
//
// Copyright (C) 2005 3Dlabs, Inc.
//
// See 3Dlabs-License.txt for license information
//
// modified by rattle 2014-06-22
const int LIGHT_COUNT = 2;
attribute vec4 wings_tangent;
varying vec3 normal;
varying vec3 lightVec[LIGHT_COUNT];
varying vec3 eyeVec;
varying vec4 color;
varying vec4 tangent;
void main(void)
{
vec3 viewPos = vec3(gl_ModelViewMatrix * gl_Vertex);
eyeVec = normalize(-viewPos);
for (int i = 0; i < LIGHT_COUNT; ++i) {
lightVec[i] = normalize(gl_LightSource[i].position.xyz - viewPos);
}
color = gl_FrontMaterial.diffuse * gl_Color;
normal = gl_NormalMatrix * gl_Normal;
tangent.xyz = gl_NormalMatrix * wings_tangent.xyz;
tangent.w = wings_tangent.w;
gl_TexCoord[0] = gl_MultiTexCoord0;
#ifdef __GLSL_CG_DATA_TYPES // Fix clipping for Nvidia and ATI
gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;
#endif
gl_Position = ftransform();
}
hemilight.fs
Code:
// $Id$
//
// Fragment shader for hemispherical lighting
//
// Author: Dan Gudmundsson
//
// modified by rattle 2014-06-22
const int LIGHT_COUNT = 2;
uniform int UseDiffuseMap;
uniform int UseNormalMap;
uniform sampler2D DiffuseMap;
uniform sampler2D NormalMap;
varying vec3 normal;
varying vec3 lightVec[LIGHT_COUNT];
varying vec3 eyeVec;
varying vec4 color;
varying vec4 tangent;
vec3 get_normal(vec3 T, vec3 N, float W, sampler2D M, vec2 C) {
N = normalize(N);
T = normalize(T);
T = normalize(T - dot(T, N) * N);
vec3 B = cross(T, N) * W;
mat3 TBN = mat3(T, B, N);
return normalize(TBN * (2.0 * texture2D(M, C).xyz - 1.0));
}
void main(void)
{
vec3 N = UseNormalMap>0?get_normal(tangent.xyz, normal, tangent.w, NormalMap, gl_TexCoord[0].xy):normalize(normal);
vec4 diffuseColor = UseDiffuseMap>0?texture2D(DiffuseMap, gl_TexCoord[0].xy):color;
vec4 diffuse, specular;
for (int i = 0; i < LIGHT_COUNT; ++i) {
gl_LightSource[i].diffuse = vec4(1.0);
gl_LightSource[i].ambient = vec4(1.0);
gl_LightSource[i].specular = vec4(1.0);
vec3 E = eyeVec;
vec3 L = lightVec[i];
float NdotL = dot(N, L);
if (NdotL > 0.0) {
vec3 R = normalize(reflect(-L, N));
diffuse += gl_FrontLightProduct[i].diffuse * NdotL;
specular += gl_FrontLightProduct[i].specular * pow(max(dot(R, E), 0.0), clamp(gl_FrontMaterial.shininess, 1.0, 128.0));
}
}
gl_FragColor = gl_FrontLightModelProduct.sceneColor + diffuseColor * diffuse + specular;
}
Okay, I've changed your shader so it takes specularity into account, which can be controlled by the shininess material property and spec color.
In the fragment shader change LIGHT_COUNT to 1 or 2, it uses either one or two hardcoded lights. Somehow gl_FrontLightProduct[].ambient always appears as black... gl_FrontLightModelProduct.sceneColor has the ambient/emissive color in it though, so it should be fine as viewport shader.