opengl-playground/shaders/mesh-fragment.glsl

47 lines
1.2 KiB
GLSL

#version 330 core
struct Material {
sampler2D diffuse0;
sampler2D diffuse1;
sampler2D diffuse2;
sampler2D diffuse3;
sampler2D specular0;
sampler2D specular1;
sampler2D specular2;
sampler2D specular3;
};
out vec4 fragmentColor;
in vec3 Normal;
in vec3 FragPos;
in vec2 TexCoord;
in vec3 ViewPos;
uniform Material material;
void main()
{
const vec3 light_direction = vec3(-1.0, -1.0, -1.0);
const vec3 light_color = vec3(1.0, 1.0, 1.0);
const float light_amb = 0.1;
const float light_spec = 0.4;
const float light_diff = 0.7;
vec3 diffuseTexCol = vec3(texture(material.diffuse0, TexCoord));
vec3 specularTexCol = vec3(texture(material.specular0, TexCoord));
vec3 normal_n = normalize(Normal);
vec3 light_dir_n = normalize(light_direction);
vec3 view_dir = normalize(ViewPos - FragPos);
vec3 reflect_dir = reflect(light_dir_n, normal_n);
float shine = pow(max(dot(view_dir, reflect_dir), 0.0), 35);
vec3 ambient_light = light_amb * diffuseTexCol * light_color;
vec3 diffuse_light = max(dot(normal_n, -light_dir_n), 0.0) *light_diff * diffuseTexCol * light_color;
vec3 specular_light = shine * light_spec * specularTexCol * light_color;
vec3 color = ambient_light + diffuse_light + specular_light;
fragmentColor = vec4(color, 1.0);
}