29 lines
758 B
GLSL
29 lines
758 B
GLSL
#version 330
|
|
|
|
in vec2 fragTexCoord;
|
|
in vec4 fragColor;
|
|
|
|
uniform sampler2D texture0;
|
|
uniform sampler2D textureNormal;
|
|
|
|
uniform vec3 lightDir;
|
|
uniform vec4 lightColor;
|
|
uniform vec4 ambientColor;
|
|
uniform vec3 falloff = vec3(0.01, 2.4, 20);
|
|
|
|
out vec4 finalColor;
|
|
|
|
void main() {
|
|
float d = length(lightDir);
|
|
vec3 n = normalize(texture(textureNormal, fragTexCoord).xyz);
|
|
vec3 l = normalize(lightDir);
|
|
|
|
vec3 diffuse = lightColor.rgb * lightColor.a * max(dot(n, l), 0.0);
|
|
vec3 ambient = ambientColor.rgb * ambientColor.a;
|
|
float attenuation = 1.0 / (falloff.x + falloff.y * d + falloff.z * d * d);
|
|
vec3 intensity = ambient + diffuse * attenuation;
|
|
|
|
vec3 final = diffuse.rgb * intensity;
|
|
|
|
finalColor = vec4(final, texture(texture0, fragTexCoord).a * 0.93);
|
|
}
|