2021-01-16 17:11:39 +01:00
|
|
|
#version 430 core
|
|
|
|
|
2021-01-17 01:26:29 +01:00
|
|
|
struct PointLight {
|
|
|
|
vec3 position;
|
|
|
|
vec3 color;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NR_POINT_LIGHTS 2
|
|
|
|
|
2021-01-16 17:11:39 +01:00
|
|
|
uniform vec3 objectColor;
|
|
|
|
uniform vec3 lightPos;
|
|
|
|
uniform vec3 cameraPos;
|
2021-01-16 20:33:47 +01:00
|
|
|
uniform sampler2D colorTexture;
|
2021-01-17 01:26:29 +01:00
|
|
|
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
2021-01-16 17:11:39 +01:00
|
|
|
|
|
|
|
in vec3 interpNormal;
|
|
|
|
in vec3 fragPos;
|
2021-01-16 20:33:47 +01:00
|
|
|
in vec2 vTexCoord;
|
2021-01-16 17:11:39 +01:00
|
|
|
|
2021-01-17 01:26:29 +01:00
|
|
|
|
|
|
|
|
2021-01-16 17:11:39 +01:00
|
|
|
void main()
|
|
|
|
{
|
2021-01-17 01:26:29 +01:00
|
|
|
vec3 fragColor = vec3(0,0,0);
|
2021-01-16 20:33:47 +01:00
|
|
|
vec4 textureColor = texture2D(colorTexture, -vTexCoord);
|
|
|
|
vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * textureColor;
|
2021-01-17 01:26:29 +01:00
|
|
|
vec3 normal = normalize(interpNormal);
|
|
|
|
for(int i = 0; i < NR_POINT_LIGHTS; i++)
|
|
|
|
{
|
|
|
|
vec3 lightDir = normalize(pointLights[i].position - fragPos);
|
|
|
|
|
|
|
|
vec3 V = normalize(cameraPos-fragPos);
|
2021-01-24 23:18:02 +01:00
|
|
|
vec3 R = reflect(-lightDir,normal);
|
|
|
|
|
|
|
|
float dist = 1 + distance(fragPos, pointLights[i].position) / 50;
|
|
|
|
float distance = (1/dist) * (1/dist);
|
2021-01-17 01:26:29 +01:00
|
|
|
|
2021-01-24 23:18:02 +01:00
|
|
|
float spec = pow(max(0,dot(R,V)),2);
|
|
|
|
float diff = max(0,dot(normal,normalize(lightDir)));
|
|
|
|
|
|
|
|
vec3 diffuse = pointLights[i].color * diff * distance;
|
|
|
|
vec3 specular = spec * pointLights[i].color * (1/dist);
|
|
|
|
|
2021-01-17 01:26:29 +01:00
|
|
|
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * pointLights[i].color;
|
|
|
|
fragColor += mix(texture,texture*diffuse+vec3(1)*specular,0.9);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_FragColor = vec4(fragColor, 1.0) + ambient;
|
2021-01-16 17:11:39 +01:00
|
|
|
}
|