|
|
|
|
@ -15,7 +15,7 @@ struct point_light {
|
|
|
|
|
}; |
|
|
|
|
#define MAX_LIGHTS 10 |
|
|
|
|
uniform point_light lights[MAX_LIGHTS]; |
|
|
|
|
uniform int num_lights = 0; |
|
|
|
|
uniform uint num_lights = 0u; |
|
|
|
|
|
|
|
|
|
out vec3 color; |
|
|
|
|
|
|
|
|
|
@ -23,19 +23,15 @@ void main()
|
|
|
|
|
{ |
|
|
|
|
// https://www.tomdalling.com/blog/modern-opengl/06-diffuse-point-lighting |
|
|
|
|
vec3 normal = normalize(normal_matrix * fragNormal); |
|
|
|
|
|
|
|
|
|
vec3 fragPosition = vec3(model * vec4(fragVertex, 1)); |
|
|
|
|
float totalBrightness = 0; |
|
|
|
|
|
|
|
|
|
///// |
|
|
|
|
|
|
|
|
|
//vec3 surfaceToLight = light_position - fragPosition; |
|
|
|
|
vec3 surfaceToLight = lights[0].position - fragPosition; |
|
|
|
|
|
|
|
|
|
///// |
|
|
|
|
|
|
|
|
|
float brightness = dot(normal, surfaceToLight) / (length(surfaceToLight) * length(normal)); |
|
|
|
|
brightness = clamp(brightness, 0, 1); |
|
|
|
|
for (uint i = 0u; i < num_lights; i++) { |
|
|
|
|
vec3 surfaceToLight = lights[i].position - fragPosition; |
|
|
|
|
float brightness = dot(normal, surfaceToLight) / (length(surfaceToLight) * length(normal)); |
|
|
|
|
totalBrightness += brightness; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
color = brightness * fragmentColor; |
|
|
|
|
color = clamp(totalBrightness, 0, 1) * fragmentColor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|