filename:
assets/shaders/default.frag
branch:
main
back to repo
// default.frag
#version 330 core
#define MAX_LIGHTS 16
in vec3 vFragPos;
in vec3 vNormal;
in vec2 vUv;
out vec4 outColor;
uniform sampler2D uTexture;
uniform vec4 uColor;
uniform vec3 light_positions[MAX_LIGHTS];
uniform vec3 light_colors[MAX_LIGHTS];
uniform float light_intensities[MAX_LIGHTS];
uniform int num_lights;
void main() {
vec3 norm = normalize(vNormal);
vec3 lighting = vec3(0.1);
for (int i = 0; i < num_lights; ++i) {
vec3 toLight = light_positions[i] - vFragPos;
float dist = length(toLight);
vec3 lightDir = normalize(toLight);
float diff = max(dot(norm, lightDir), 0.0);
float attenuation = light_intensities[i] / (dist * dist + 1.0);
lighting += light_colors[i] * diff * attenuation;
}
vec4 tex = texture(uTexture, vUv);
//outColor = vec4(lighting, 1.0);
outColor = vec4((tex.rgb * uColor.rgb) * lighting, tex.a * uColor.a);
}