2023-01-21 13:00:02 +01:00
|
|
|
#version 330 core
|
2023-12-05 10:49:51 +01:00
|
|
|
|
|
|
|
in VertexData {
|
|
|
|
vec3 normal;
|
|
|
|
vec4 fragColor;
|
|
|
|
vec2 texCoord;
|
|
|
|
vec3 lightPosition;
|
|
|
|
vec3 fragPosition;
|
|
|
|
vec4 lightBrightness;
|
|
|
|
vec3 lightColor;
|
|
|
|
} vertexData;
|
|
|
|
|
|
|
|
out vec4 outColor;
|
|
|
|
|
|
|
|
uniform sampler2D modelTexture;
|
2023-01-21 13:00:02 +01:00
|
|
|
|
|
|
|
void main() {
|
2023-12-05 10:49:51 +01:00
|
|
|
vec3 ambientLightColor = vec3(1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
// Ambient lighting
|
|
|
|
vec3 ambient = vertexData.lightBrightness.x * ambientLightColor;
|
|
|
|
|
|
|
|
// Diffuse lighting
|
|
|
|
vec3 normalVector = normalize(vertexData.normal);
|
|
|
|
|
|
|
|
vec3 lightDirection = normalize(vertexData.lightPosition - vertexData.fragPosition);
|
|
|
|
float diffuse = vertexData.lightBrightness.y * max(dot(normalVector, lightDirection), 0.0);
|
|
|
|
|
|
|
|
// Specular lighting
|
|
|
|
vec3 viewDirection = normalize(-vertexData.fragPosition);
|
|
|
|
vec3 reflectDirection = normalize(-reflect(lightDirection, normalVector));
|
|
|
|
float reflectionIntensity = pow(max(dot(viewDirection, reflectDirection), 0.0), vertexData.lightBrightness.w);
|
|
|
|
float specular = vertexData.lightBrightness.z * reflectionIntensity;
|
|
|
|
|
|
|
|
float dst = distance(vertexData.lightPosition, vertexData.fragPosition);
|
2024-02-24 23:34:29 +01:00
|
|
|
float attn = 1./(1.0F + 0.1F*dst + 0.01f*dst*dst) ;
|
2023-12-05 10:49:51 +01:00
|
|
|
vec3 color = ((diffuse + specular)*attn + ambient) * vertexData.lightColor;
|
|
|
|
outColor = (texture(modelTexture, vertexData.texCoord) + vertexData.fragColor) * vec4(color, 1.0);
|
|
|
|
}
|
2023-01-21 13:00:02 +01:00
|
|
|
|