Saxum/Shader/phong.fsh

29 lines
699 B
Plaintext
Raw Normal View History

2014-10-20 15:31:26 +00:00
#version 150
in vec3 vNormal;
in vec2 vTexCoord;
out vec4 oColor;
uniform sampler2D uTexture;
2014-10-31 11:56:09 +00:00
uniform int lightCount;
uniform vec3 lightSources[128];
2014-11-03 22:54:35 +00:00
uniform vec3 ambientColor;
uniform float ambientFactor;
2014-11-03 22:54:35 +00:00
uniform vec3 lightColors[128];
uniform float diffuseFactor;
2014-10-20 15:31:26 +00:00
void main()
{
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);
for(int i = 0; i<lightCount; i++) {
2014-11-03 22:54:35 +00:00
diffuseColor += dot(normalize(vNormal), normalize(lightSources[i]))
*diffuseFactor*lightColors[i];
2014-10-31 11:56:09 +00:00
}
vec3 finalColor = diffuseColor + ambientColor;
2014-10-20 15:31:26 +00:00
vec3 texture = texture(uTexture, vTexCoord).rgb;
oColor = vec4(finalColor*texture, 1.0 );
2014-10-20 15:31:26 +00:00
}