This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
neofx-zoom-plusplus/shader/light.frag

40 lines
907 B
GLSL
Raw Permalink Normal View History

2009-12-15 02:25:40 +01:00
uniform sampler2D tex;
varying vec4 diffuse, ambient;
2009-12-15 02:25:40 +01:00
varying vec3 normal, pos;
void main() {
vec3 n, l, refl, eye;
float NdotL, RdotE;
2009-12-21 23:41:17 +01:00
vec4 specularColor;
float dist, distSq, att, specularFactor;
2009-12-15 02:25:40 +01:00
n = normalize(normal);
l = gl_LightSource[0].position.xyz - pos;
2009-12-21 23:41:17 +01:00
distSq = dot(l, l);
2009-12-15 02:25:40 +01:00
2009-12-21 23:41:17 +01:00
NdotL = dot(n, l);
2009-12-15 02:25:40 +01:00
if (NdotL > 0.0) {
2009-12-21 23:41:17 +01:00
dist = sqrt(distSq);
2009-12-15 02:25:40 +01:00
2009-12-21 23:41:17 +01:00
att = 1.0 / (gl_LightSource[0].quadraticAttenuation * distSq);
gl_FragColor = att * (diffuse * NdotL / dist + ambient) * texture2D(tex, gl_TexCoord[0].st);
2009-12-15 02:25:40 +01:00
2009-12-21 23:41:17 +01:00
refl = reflect(-l, n);
2009-12-21 23:41:17 +01:00
RdotE = -dot(refl, pos) / sqrt(dot(refl, refl) * dot(pos, pos));
if(RdotE > 0.0) {
specularFactor = att * pow(RdotE, gl_FrontMaterial.shininess);
gl_FragColor += specularFactor * gl_FrontMaterial.specular * gl_LightSource[0].specular;
}
2009-12-15 02:25:40 +01:00
}
else {
gl_FragColor = vec4(0, 0, 0, 1);
2009-12-15 02:25:40 +01:00
}
}