You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
639 B
27 lines
639 B
#version 330 core |
|
|
|
in vec3 fragmentColor; |
|
in vec3 fragNormal; |
|
in vec3 fragVertex; |
|
|
|
uniform mat4 model; |
|
uniform vec3 light_position; |
|
uniform mat3 normal_matrix; |
|
|
|
out vec3 color; |
|
|
|
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)); |
|
vec3 surfaceToLight = light_position - fragPosition; |
|
|
|
float brightness = dot(normal, surfaceToLight) / (length(surfaceToLight) * length(normal)); |
|
brightness = clamp(brightness, 0, 1); |
|
|
|
color = brightness * fragmentColor; |
|
//color = vec3(255, 255, 255); |
|
} |
|
|
|
|