Files
starruler-linux/data/shaders/source/smooth_light_ps.txt
T
2018-07-17 14:15:37 +02:00

59 lines
1.8 KiB
Plaintext

const int nLightCount = 2;
uniform sampler2D diffuseRGBspecA;
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(diffuseRGBspecA, uv.xy);
vec3 matspec = gl_FrontMaterial.specular.rgb * texSamp.a;
float shininess = gl_FrontMaterial.shininess * (0.5 + texSamp.a);
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 * color * texSamp.rgb) + (specular * matspec);
gl_FragColor.a = 1.0;
}