1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#version 330
precision highp float;
uniform sampler2D em_DiffuseTexture;
in vec2 em_FragTexCoord0;
in vec4 em_FrontColor;
smooth in vec3 normal;
smooth in vec3 lightDir;
void main (void)
{
// FOG calculation
float density = 0.0001;
const float LOG2 = 1.442695;
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = exp2(-density * density * z * z * LOG2);
fogFactor = clamp(fogFactor, 0.0, 1.0);
// Dot product gives us diffuse intensity
float diff = max(0.0, dot(normalize(normal), normalize(lightDir)));
// Multiply intensity by diffuse color, force alpha to 1.0
vec4 finalColor = diff * mix(texture2D(em_DiffuseTexture, em_FragTexCoord0), em_FrontColor, 0.5);
// Add in ambient light
finalColor += vec4(0.1, 0.0, 0.0, 1.0);
// Specular Light
vec3 vReflection = normalize(reflect(-normalize(lightDir), normalize(normal)));
float spec = max(0.0, dot(normalize(normal), vReflection));
if ( diff != 0 )
{
float fSpec = pow(spec, 128.0);
finalColor.rgb += vec3(fSpec, fSpec, fSpec);
}
gl_FragColor = mix(vec4(0.1, 0.0, 0.0, 1.0), vec4(finalColor.rgb, 1.0), fogFactor);
} |
Partager