#define MAX_LIGHTS 0 uniform vec3 z_sun_direction; uniform vec3 z_sun_color; uniform sampler2D z_tex_d; #if SPECULARMAP uniform sampler2D z_tex_s; #endif #if NORMALMAP varying vec3 v_tangent; varying vec3 v_bitangent; uniform sampler2D z_tex_n; #endif varying vec3 v_normal; varying vec3 v_fragpos; varying vec3 Lsun; void main() { float attenuation, spotlight; vec3 N, L, V, S; vec4 diffuse, ambient, color, specular; vec4 tex_color; V = normalize(-v_fragpos); #if NORMALMAP // Transform normal from normalmap from tangent space, to eye-space. mat3 tangent_to_eye = mat3(v_tangent, v_bitangent, v_normal); vec3 texnormal = texture2D(z_tex_n, gl_TexCoord[0].st).rgb * 2.0 - 1.0; texnormal.rg = -texnormal.rg; N = normalize(tangent_to_eye * texnormal); #else N = normalize(v_normal); #endif // Initialize color to emission+global ambient. color = gl_FrontMaterial.emission + gl_FrontLightModelProduct.sceneColor; // Add diffuse for sun, and initialize specular. S = normalize(Lsun+V); color.rgb += max(0.0, dot(Lsun, N)) * z_sun_color; specular = vec4(pow(max(dot(S,N),0.0), gl_FrontMaterial.shininess) * z_sun_color, 0.0); // Add contribution of each light to color and specular. for (int i = 0; i < MAX_LIGHTS; i++) { L = normalize(gl_LightSource[i].position.xyz - (v_fragpos * gl_LightSource[i].position.w)); S = normalize(L+V); attenuation = 1.0; // FIXME spotlight = 1.0; // FIXME ambient = gl_FrontLightProduct[i].ambient; diffuse = max(0.0, dot(L, N)) * gl_FrontLightProduct[i].diffuse; color += attenuation * spotlight * (ambient + diffuse); specular += pow(max(dot(S, N), 0.0), gl_FrontMaterial.shininess) * gl_FrontLightProduct[i].specular; } tex_color = texture2D(z_tex_d, gl_TexCoord[0].st); gl_FragColor.rgb = color.rgb * tex_color.rgb; gl_FragColor.a = tex_color.a * gl_FrontMaterial.diffuse.a; #if SPECULARMAP gl_FragColor.rgb += specular.rgb * texture2D(z_tex_s, gl_TexCoord[0].st).rgb; #else gl_FragColor.rgb += specular.rgb; #endif }