2014-10-20 15:31:26 +00:00
|
|
|
#version 150
|
|
|
|
|
|
|
|
in vec3 vNormal;
|
|
|
|
in vec2 vTexCoord;
|
2014-11-03 23:47:35 +00:00
|
|
|
in vec4 fragPosition;
|
2014-10-20 15:31:26 +00:00
|
|
|
|
|
|
|
out vec4 oColor;
|
|
|
|
|
|
|
|
uniform sampler2D uTexture;
|
2014-11-03 22:54:35 +00:00
|
|
|
uniform vec3 ambientColor;
|
2014-10-31 09:38:57 +00:00
|
|
|
uniform float ambientFactor;
|
2014-11-07 10:37:26 +00:00
|
|
|
uniform float diffuseFactor;
|
|
|
|
uniform float specularFactor;
|
|
|
|
uniform vec3 camera;
|
|
|
|
uniform float shininess;
|
|
|
|
uniform int lightCount;
|
2014-11-17 16:51:15 +00:00
|
|
|
uniform vec3 directionalLightVector;
|
|
|
|
uniform vec3 directionalColor;
|
|
|
|
uniform float directionalIntensity;
|
2014-11-07 10:37:26 +00:00
|
|
|
uniform vec3 lightSources[128];
|
2014-11-03 22:54:35 +00:00
|
|
|
uniform vec3 lightColors[128];
|
2014-11-03 23:47:35 +00:00
|
|
|
uniform float lightIntensities[128];
|
2014-10-20 15:31:26 +00:00
|
|
|
|
|
|
|
void main()
|
2014-10-31 09:38:57 +00:00
|
|
|
{
|
2014-11-03 22:54:35 +00:00
|
|
|
vec3 ambientColor = ambientFactor * ambientColor;
|
2014-10-31 11:56:09 +00:00
|
|
|
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
|
2014-11-07 10:37:26 +00:00
|
|
|
vec3 specularColor = vec3(0.0, 0.0, 0.0);
|
2014-11-17 16:51:15 +00:00
|
|
|
|
|
|
|
if(length(directionalLightVector)>0.0f) {
|
|
|
|
vec3 directionalVector = normalize(directionalLightVector);
|
2014-11-18 23:46:51 +00:00
|
|
|
diffuseColor += clamp(dot(normalize(vNormal), directionalVector)
|
|
|
|
*diffuseFactor*directionalIntensity*directionalColor, 0.0, 1.0);
|
2014-11-17 16:51:15 +00:00
|
|
|
vec3 cameraVector = normalize(camera - vec3(fragPosition));
|
|
|
|
specularColor += clamp(pow((dot((cameraVector+directionalVector),normalize(vNormal))/(length(cameraVector+directionalVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
|
|
|
|
*specularFactor*directionalIntensity*directionalColor;
|
|
|
|
}
|
2014-10-31 11:56:09 +00:00
|
|
|
for(int i = 0; i<lightCount; i++) {
|
2014-11-03 23:47:35 +00:00
|
|
|
float distance = distance(lightSources[i], vec3(fragPosition));
|
2014-11-04 11:24:19 +00:00
|
|
|
// only take lights into account with meaningful contribution
|
|
|
|
if (distance > 0.001f) {
|
2014-11-07 10:37:26 +00:00
|
|
|
vec3 lightVector = normalize(lightSources[i]-vec3(fragPosition));
|
2014-11-19 00:58:25 +00:00
|
|
|
float intensity = clamp(exp(-(1/lightIntensities[i])*distance), 0.0, 1.0);
|
2014-11-18 23:46:51 +00:00
|
|
|
diffuseColor += clamp(dot(normalize(vNormal), lightVector)
|
|
|
|
*diffuseFactor*intensity*lightColors[i], 0.0, 1.0);
|
2014-11-07 10:37:26 +00:00
|
|
|
vec3 cameraVector = normalize(camera - vec3(fragPosition));
|
|
|
|
specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
|
|
|
|
*specularFactor*intensity*lightColors[i];
|
2014-11-04 11:24:19 +00:00
|
|
|
}
|
2014-10-31 11:56:09 +00:00
|
|
|
}
|
2014-11-07 10:37:26 +00:00
|
|
|
vec3 finalColor = specularColor + diffuseColor + ambientColor;
|
2014-10-20 15:31:26 +00:00
|
|
|
|
2014-11-17 15:15:42 +00:00
|
|
|
vec4 texture = texture(uTexture, vTexCoord).rgba;
|
|
|
|
oColor = vec4(finalColor, 1.0f)*texture;
|
2014-10-20 15:31:26 +00:00
|
|
|
}
|