Files
2018-07-17 14:15:37 +02:00

59 lines
1.8 KiB
Plaintext

const int nLightCount = 2;
uniform sampler2D diffuseRGBglowA;
varying vec3 normal;
varying vec3 npos;
varying vec2 uv;
vec3 light[nLightCount];
float dist[nLightCount];
void main() {
vec3 color = gl_FrontMaterial.diffuse.rgb;
vec4 texSamp = texture2D(diffuseRGBglowA, uv.xy);
vec3 matspec = gl_FrontMaterial.specular.rgb;
float shininess = gl_FrontMaterial.shininess;
vec3 n = normalize(normal);
vec3 v = normalize(npos);
if(nLightCount > 0) {
const int i = 0;
light[i] = gl_LightSource[i].position.xyz + npos;
dist[i] = length(light[i]);
light[i] = light[i] / dist[i];
}
if(nLightCount > 1) {
const int i = 1;
light[i] = gl_LightSource[i].position.xyz + npos;
dist[i] = length(light[i]);
light[i] = light[i] / dist[i];
}
vec3 diffuse = gl_LightModel.ambient.rgb * gl_FrontMaterial.ambient.rgb;
vec3 specular = vec3(0.0);
if(nLightCount > 0) {
const int i = 0;
float falloff = 1.0 / (1.0 + (gl_LightSource[i].quadraticAttenuation * dist[i] * dist[i]));
float intensity = max(0.0, dot(n, light[i])) * falloff;
diffuse += gl_LightSource[i].diffuse.rgb * intensity;
vec3 r = -reflect(light[i], n);
specular += gl_LightSource[i].specular.rgb * (pow(max(0.0, dot(r, v)), shininess) * intensity);
}
if(nLightCount > 1) {
const int i = 1;
float falloff = 1.0 / (1.0 + (gl_LightSource[i].quadraticAttenuation * dist[i] * dist[i]));
float intensity = max(0.0, dot(n, light[i])) * falloff;
diffuse += gl_LightSource[i].diffuse.rgb * intensity;
vec3 r = -reflect(light[i], n);
specular += gl_LightSource[i].specular.rgb * (pow(max(0.0, dot(r, v)), shininess) * intensity);
}
gl_FragColor.rgb = ((diffuse + vec3(texSamp.a)) * color * texSamp.rgb) + (specular * matspec);
gl_FragColor.a = 1.0;
}